在aspx页面上过滤表

时间:2012-10-26 19:16:13

标签: asp.net html-table

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

我想要的是,当我点击任何列标题时,它应该显示该列中的行列表,每个列都有复选框,当我选择特定行时,表格应该相应地进行过滤。

1 个答案:

答案 0 :(得分:0)

这是一次一列的工作示例。我正在努力让这个列适用于多个列: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

还有一个filtering插件可用于jQuery DataTables plugin,虽然排序显然是该插件的主要焦点。