0

I have the following code in "listings.js" in my rails app. Im using the gem datatables to show some data. I would like to have my columns and rows highlighted as shown in this example. But the highlight feature is not working in my app.

//Initialize the datatable
$(document).ready(function()
{
  var listingsTable = $('#listings').dataTable(
  {
    "sPaginationType":  "full_numbers",
    "bJQueryUI": true,
    "bSortClasses": false,
    "sScrollX": "90%",
    "bScrollCollapse": true,
    "sDom":  '<"top"iflp<"clear">>rt<"bottom"iflp<"clear">>',
    "bProcessing": true,
    "bServerSide": true,
    "sAjaxSource": $('#listings').data('source')
  });

  $('td', listingsTable.fnGetNodes()).hover(function() 
    {
        var iCol = $('td').index(this) % 5;
        var nTrs = listingsTable.fnGetNodes();
        $('td:nth-child('+(iCol+1)+')', nTrs).addClass( 'datatablerowhighlight' );
    }, 
    function() 
    {
        $('td.datatablerowhighlight',     listingsTable.fnGetNodes()).removeClass('datatablerowhighlight');
    } );

});

Here is my listings.css.scss file

.datatablerowhighlight 
{
    background-color: #ECFFB3 !important;
}

So what am I doing wrong ?

1 Answer 1

0

From http://railscasts.com/episodes/340-datatables, try adding:

group :assets do
  gem 'jquery-datatables-rails', github: 'rweng/jquery-datatables-rails'
  gem 'jquery-ui-rails'
end

to your Gemfile and

//= require dataTables/jquery.dataTables

to app/assets/javascripts/application.js.

Sign up to request clarification or add additional context in comments.

3 Comments

Hi thanks for your response but,I already have added the gem and updated everything according to the railscasts episode. I have my datatable nicely formatted with pagination and search just like in the episode. But, I cannot get the row and column highlight to work as illustrated in the example which has a link above in my post.
I am seeing that the function oCol is undefined. Are you getting the same error? If so, there seem to be other posts about this issue like stackoverflow.com/questions/6405429/… .
It's in datatable's javascript. I notice the error coming up when I inspect the loaded javascript in my browser with firebug console.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.