【问题标题】:Filtering on table on aspx page过滤aspx页面上的表格
【发布时间】:2018-01-20 18:23:55
【问题描述】:

我需要在 aspx 页面上的表格上实现 Excel 类型的过滤。

我想要的是,当我单击任何列标题时,它应该向我显示该列中的行列表以及每个行的复选框,当我选择特定行时,表应该相应地过滤。

【问题讨论】:

  • 您需要多高的水平,您准备自己编写多少代码?
  • 我希望它与 jquery 相关......但我找不到任何东西

标签: asp.net html-table


【解决方案1】:

这里是一个每次一列的工作示例。我也在努力让这个功能适用于多个专栏:http://jsfiddle.net/mwB37/20/

由于您要求一个完整的插件,其中包含 UI 和所有内容,包括 SO 上的相关代码,这有点困难。但以下是定义我的想法和概念的关键摘录:

// fetching the column index
var columnIndex = th.index();

// then fetching the corresponding TDs (use for-loop when thousands of elements)
var tds = th.closest('table')
            .find('tbody td:nth-child(' + (columnIndex+1) + ')');

// distinctively selecting the unique text values in those columns
var checks = $.unique(tds.map(function() {
    return $(this).text();
}).get());

// the most basic way possible of filtering
// (should be extended into an OR query of all current column filters)
if (index != -1 || arr.length == 0)
    td.parent('tr').show();
else
    td.parent('tr').hide();

如果你想要一些已经完成的东西,这就是这样一个插件:PicNet Table Filter

还有一个可用于 jQuery DataTables pluginfiltering 插件,尽管排序显然是该插件的主要重点。

【讨论】:

  • 这是排序。我实际上是在寻找过滤。就像我有一个名为“类别”的列,它有汽车、律师、宠物等数据......所以现在如果我点击列标题,它应该会显示当前列中所有类别的列表并带有一个检查-box,现在如果我只选择 Car 和 Pet 它应该只显示类别中有 Car 和 Pet 的那些行。
  • 可以使用上述技术构建。 jQuery DataTables 插件的插件是过滤,而不是排序。你的意思是你需要完全禁用排序功能,只使用过滤功能?
  • 是的,现在我只想过滤
猜你喜欢
  • 2023-03-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-02
  • 1970-01-01
相关资源
最近更新 更多