gpt4 book ai didi

javascript - 如何隐藏数据表中的某些行

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

我有使用ajax作为数据源的数据表,而且我有一个包含多个 row_id 的数组,我想显示 row_id 不在该数组中的行。

我该怎么做?

我搜索了数据表文档,并尝试了很多函数/回调,但都不起作用。

最佳答案

您可以非常轻松地设置custom filter在您想要的任何条件之后永久排除(或隐藏)某些行:

var excluded_row_ids = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43]

$.fn.dataTable.ext.search.push(function(settings, data, dataIndex) {
//assuming the row_id is located in first column
return (!~excluded_row_ids.indexOf(parseInt(data[0])))

//or for example compare to dataIndex, i.e. original insert order
//return (!~excluded_row_ids.indexOf(dataIndex))
})

如果您出于某种原因想要包含排除的行,只需删除过滤器即可:

$.fn.dataTable.ext.search.pop()

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

关于javascript - 如何隐藏数据表中的某些行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35824721/

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