gpt4 book ai didi

javascript - 单击时在 jquery 数据表中切换具有特定属性的行

转载 作者:行者123 更新时间:2023-11-27 22:54:15 27 4
gpt4 key购买 nike

我是 jquery 数据表的新手。

我想要实现的是,在单击按钮时切换(隐藏/显示)具有名为 status_id 属性且值为 9 到 13 的数据表行。

我只针对数字 9 尝试过此操作,但不起作用。

var dTable = $('#tbl_taskList').DataTable();

$(document).on('click', '.hide-tasks', function (e) {

e.preventDefault();

var row = dTable.row($(this).attr('status_id'));
if(row === '9') {
dTable.row().hide();
}
});

最佳答案

没有hide()行的特征。基本上就是您想要做的专门过滤器,因此您可以创建一个 custom filter实现你想要的。这是隐藏或显示 <tr> 的可切换过滤器的示例与status_id 9 或 13:

$('#hide-tasks').on('click', function (e) {
//is the checkbox checked?
if ($(this).is(':checked')) {
//add filter
$.fn.dataTable.ext.search.push(function( settings, data, dataIndex ) {
//always go through the API when working with dataTables!
var status_id = parseInt(table.row(dataIndex).nodes().to$().attr('status_id'))
return !~[9,13].indexOf(status_id)
})
} else {
//reset filter
$.fn.dataTable.ext.search.pop()
}
//update table
table.draw()
})

演示 -> http://jsfiddle.net/k1cz6rma/

关于javascript - 单击时在 jquery 数据表中切换具有特定属性的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37761751/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com