所以基本上我有一个有编号的行来计算结果。(类似于excel中的行号),目前,它会在你对表格排序后对它们重新编号,但在你过滤表格后,我似乎不能让它工作。因此,如果它只拉取记录6-9,数字6-9仍然存在,而不是将其重新编号为1、2、3和4。
目前,这是我所拥有的:
var table = $("#myTable");
table.bind("sortEnd",function() {
var i = 1;
table.find("tr:gt(1)").each(function(){
$(this).find("td:eq(0)").text(i);
i++;
});
});
table.bind("filterEnd",function() {
var i = 1;
table.find("tr:gt(1)").each(function(){
$(this).find("td:eq(0)").text(i);
i++;
});
}); 使用表格:
+===+=======+========+
| # | Name | Amount |
+===+=======+========+
| 1 | Item1 | 8934 |
+===+=======+========+
| 2 | Item2 | 8971 |
+===+=======+========+
| 3 | Item3 | 4891 |
+===+=======+========+如果我筛选出数量< 5000,则结果为:
+===+=======+========+
| # | Name | Amount |
+===+=======+========+
| 3 | Item3 | 4891 |
+===+=======+========+我希望3变为1(因为它现在是列表中的第一项)。有什么建议吗?我一直在尝试使用filterEnd,但似乎无法让它正常工作。
发布于 2014-07-28 19:51:16
使用jquery each:
$("table").bind("filterEnd",function() {
$("#myTable tbody tr:visible").each(function(index){
$("td:first-child", $(this)).html(index+1);
});
});https://stackoverflow.com/questions/22561147
复制相似问题