使用jQuery Tablesorter使用Select字段对多个字段进行排序
我用的是莫蒂的桌叉运输机: 我想做的是使用实际表之外的多个select字段对表进行筛选或排序。所以我不想使用出现在表标题下的过滤器 我已经找到了一些可行的方法。例如,将这两个添加到我的tablesorter脚本中:使用jQuery Tablesorter使用Select字段对多个字段进行排序,jquery,tablesorter,Jquery,Tablesorter,我用的是莫蒂的桌叉运输机: 我想做的是使用实际表之外的多个select字段对表进行筛选或排序。所以我不想使用出现在表标题下的过滤器 我已经找到了一些可行的方法。例如,将这两个添加到我的tablesorter脚本中: jQuery(".selectParty").bind('change', function (e) { var cols=[] cols[2] = $(this).val() jQuery('table').trigger('search', [col
jQuery(".selectParty").bind('change', function (e) {
var cols=[]
cols[2] = $(this).val()
jQuery('table').trigger('search', [cols]);
})
jQuery(".selectState").bind('change', function (e) {
var cols=[]
cols[0] = $(this).val()
jQuery('table').trigger('search', [cols]);
})
下面是表格上方的HTML选择字段:
<select class="selectState tablesorter-filter" data-column="0">
<option class="reset" value="">No Filter</option>
<option>Illinois</option>
<option>Indiana</option>
</select>
<select class="selectParty tablesorter-filter" data-column="2">
<option class="reset" value="">No Filter</option>
<option>Democratic</option>
<option>Republican</option>
</select>
<table class="tablesorter"><thead><tr><th data-placeholder="Search" class="filter-match">State</th><th data-placeholder="Search" class="filter-match">Name</th><th data-placeholder="Search" class="filter-match">Party</th></tr></thead><tbody>
这些单独工作很好,但假设我先选择Sort by Illinois,它会按Illinois对表格进行排序。然后我继续按Democractic排序,它会重置状态过滤器,以显示所有带有Democractic的行
目前是否可以让tablesorter允许您通过表本身之外的多个字段进行过滤?我见过一些例子,你可以通过按住Shift键按多列排序,但这在平板电脑上不起作用……非常感谢你的帮助 不必清除col变量,只需修改特定列的筛选器,如下所示:
var cols = [];
jQuery(".selectParty").bind('change', function (e) {
cols[2] = $(this).val();
jQuery('table').trigger('search', [cols]);
});
jQuery(".selectState").bind('change', function (e) {
cols[0] = $(this).val();
jQuery('table').trigger('search', [cols]);
});
谢谢你,莫蒂!我对所有这些都是新手,我自学jQuery和PHP时使用了编程界非常有用的人!