简体   繁体   中英

Datatables locate row through all pages

I want to find a row that has a certain value in one of the cells and apply class. I managed to do that, but problem is that it works only when I get to the page where that value exists.

drawCallback: function( settings ) {
    var data = table.rows({ page: 'all' }).data();
    $(data).each( function (idx) {
        var row = table.row( idx );

        if ( row.data().username === 'miko55' ) {
            row.nodes().to$().addClass( 'table-success' );
            alert(idx);
        }
    } );
}  

I tried with page:'all' but it doesn't change anything.

You need to use Datatables jumpToData() plugin to achieve this. Try this

//jump to particular row in a table
YOUR_TABLE.page.jumpToData('VALUE YOU ARE LOOKING FOR', 0);

//add you CSS class to the row
YOUR_TABLE.rows(function (idx, data, node) {
  if(data.YOUR_VALUE === 'VALUE YOU ARE LOOKING FOR') {
    return true;
  }
}).nodes().to$().addClass('YOUR CSS CLASS');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM