Select all rows in active page only jquery Datatab

2020-07-12 02:32发布

I'm using jquery datatable on a gidview and there is a checkbox on the datatable header. The purpose of that checkbox is to check all checkboxes in the current page of the gridview rows.

So am using the function

var table = $('#Tab_ApplicantList').DataTable();
    var rows = $('#Tab_ApplicantList').dataTable().fnGetNodes();
    $(rows).each(function () {
        $(this).find("input.grey").iCheck('check');
    });

But the problem is it is selecting all rows in the datatable, not just the rows in the active page. So how can I achieve that to check rows in the current page alone?

3条回答
Evening l夕情丶
2楼-- · 2020-07-12 03:09

I've got an answer to my question and sharing for those with similar issue..

var table = $('#tbl_questions').DataTable();
var p = table.rows({ page: 'current' }).nodes();

will return all the rows in the current page only..

查看更多
手持菜刀,她持情操
3楼-- · 2020-07-12 03:15

fnGetNodes() returns all the generated rows. Use this to get the current displayed table rows:

$('#Tab_ApplicantList> tbody > tr').each(function() 
{
    $(this).find("input.grey").iCheck('check');
});
查看更多
Root(大扎)
4楼-- · 2020-07-12 03:35

Use dataTables.checkboxes.min.js , Use option "selectAllPages" : false . It should be work and it's easy

查看更多
登录 后发表回答