DataTables - 在第二页隐藏按钮

DataTables - hide buttons on second page

当某些值不是 "error" 时,我尝试在 table 中隐藏按钮。

它在第一页上工作得很好,但由于分页,按钮在第二页上没有隐藏。

JSFiddle

$(function() {
$('#table1').each(function() {
var Cell = $(this).find('td:eq(2)');
debugger;
if (Cell.text() !== 'error' ) {
$(this).find('button').hide();
       }
    });
});

页面变化时必须调用该函数。如果您检查 table,您可以看到所有未加载的行。

就像您对 initComplete 回调所做的一样,您可以通过 DataTable 选项传递 drawCallback 函数。每次绘制 table 时都会 运行。只需将以下内容添加到选项中即可。

JSFiddle

参见:https://datatables.net/reference/option/drawCallback

drawCallback: function (settings) {
    $('#table1').each(function () {
        var Cell = $(this).find('td:eq(2)');
        debugger;
        if (Cell.text() !== 'error') {
            $(this).find('button').hide();
        }
    });
}