当使用javascript更改其他页面中复选框的选中状态时,DataTable会不断返回第一页



>我有以下代码

$('.chk_realtor:checked').each(function () {
emailarr.push($(this).val());
action = "Selected";
});

每当我单击除 1st 以外的任何页面中的"全选"按钮时,数据表都会不断恢复到第一页。

您需要使用DataTable配置的渲染属性。

var table = $('#example').DataTable({
'ajax': 'https://api.myjson.com/bins/1us28',  
'columnDefs': [{
'targets': 0,
'searchable':false,
'orderable':false,
'className': 'dt-body-center',
'render': function (data, type, full, meta){
return '<input type="checkbox" name="id[]" value="' 
+ $('<div/>').text(data).html() + '">';
}
}],
'order': [1, 'asc']
});

这是一个工作示例

最新更新