How to Highlight a row manually

How to Highlight a row manually

ravikiranketheravikirankethe Posts: 11Questions: 5Answers: 0

I want to go through list of datatable items and if my criteria is matching then I want to select the row manually. What if the row is in the other page? How to handle that?

Answers

  • ravikiranketheravikirankethe Posts: 11Questions: 5Answers: 0
    edited December 2014
       var oTable = $('#tbl_env_list').dataTable();
       var nRows = oTable.fnGetNodes();
    
       var rowFound = 0;
       for (var i in nRows) {
          var aData = oTable.fnGetData(nRows[i]);
          if (aData[0] == env_id) {
             rowFound = 1;
             console.log ("row is found");
             // WANT TO HIGHLIGHT THE ROW HERE
          }
       }
    
  • allanallan Posts: 63,532Questions: 1Answers: 10,475 Site admin
    $(i).addClass( 'highlight' );
    

    perhaps? Then just have a bit of CSS that matches that class and adds whatever highlighting style you want.

    Allan

  • ravikiranketheravikirankethe Posts: 11Questions: 5Answers: 0
    edited December 2014

    Allan,

    Thanks for the reply. I would like to have default stylesheet of selecting the row. I added the code but that did not helped.

  • ravikiranketheravikirankethe Posts: 11Questions: 5Answers: 0
       var oTable = $('#tbl_env_list').dataTable();
       var nRows = oTable.fnGetNodes();
    
       var rowFound = 0;
       for (var row in nRows) {
          var aData = oTable.fnGetData(nRows[row]);
          console.log (aData[0]); 
          if (aData[0] == env_id) {
             rowFound = 1;
             console.log ("row is found");
             $(row).addClass('selected');
             $(row).addClass('highlight');
             break;
          }
       }
    
  • allanallan Posts: 63,532Questions: 1Answers: 10,475 Site admin

    selected is the class that the DataTables default stylesheet uses for highlighting a row.

    If that doesn't work for you, please link to a test case showing the issue.

    Allan

This discussion has been closed.