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

Javascript 如何隐藏数据表中的某些行,javascript,datatables,Javascript,Datatables,我有使用ajax作为数据源的数据表,还有一个数组包含多个row\u id,我想显示这个数组中没有row\u id的行 我怎么做 我已经搜索了datatables文档,并尝试了许多函数/回调,但它们都不起作用。您可以非常轻松地设置一个永久排除(或隐藏)任何条件后的特定行: var excluded_row_ids = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43] $.fn.dataTable.ext.search.push(functi

我有使用ajax作为数据源的数据表,还有一个数组包含多个row\u id,我想显示这个数组中没有row\u id的行

我怎么做


我已经搜索了datatables文档,并尝试了许多函数/回调,但它们都不起作用。

您可以非常轻松地设置一个永久排除(或隐藏)任何条件后的特定行:

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()
演示->