[英]Better solution than 'callback like behaviour'
I use jquery picnet table filter - http://www.picnet.com.au/picnet-table-filter.html 我使用jquery picnet表滤波器- http://www.picnet.com.au/picnet-table-filter.html
I need to display count of rows currently visible, so I need to react to each filtering event. 我需要显示当前可见的行数,因此我需要对每个过滤事件做出反应。
There are two options which should serve as callback - filteringRows and filteredRows. 有两个应该用作回调的选项-filteringRows和filteredRows。
However, I tried both of them and it didn't work out. 但是,我尝试了两个,但都没有解决。 I got the callback function triggered only sometimes.
我只在某些时候触发了回调函数。 Finally I have a working solution -
终于我有了一个可行的解决方案-
$('#myTable .filters').change(function(){ setTimeout( 'load_num_rows()', 500 ) })
.keyup(function(){ setTimeout( 'load_num_rows()', 500 ) });
What bothers me is that this solution is obviously not callback. 让我困扰的是,这种解决方案显然不是回调。 This is waiting 500ms for the filtering to finish, but if there would be a lot of rows and the filtering would take a little more than 500ms, then I wouldn't get the result right.
这需要等待500毫秒才能完成过滤,但是如果行很多并且过滤需要500毫秒多一点,那么我将无法获得正确的结果。
What I tried is 我试过的是
$('#tb_list_reports').tableFilter({filteredRows: function(){ 'load_num_rows()' }});
and 和
$('#tb_list_reports').tableFilter({filteredRows: function(){setTimeout( 'load_num_rows()', 500 )}});
and the same with option filteringRows. 与选项filterRows相同。 None of them works, the number of rows is not updated.
它们都不起作用,行数未更新。 I have tried console.log() and it seems they are not even triggered when I filter rows, and also when I have these options set, I get some strange behaviour - sometimes I reload the page, there is no filtering set and yet I don't get anything displayed until the third reload.
我尝试过console.log(),当我过滤行时似乎也没有触发它们,而且当我设置了这些选项时,我得到一些奇怪的行为-有时我重新加载页面,没有过滤设置,但是我在第三次重新加载之前,不会显示任何内容。
Have you any suggestions on what should I try? 您对我应该尝试什么有什么建议?
This works for me: 这对我有用:
filteredRows: function(filterStates) {
running_total = $("#assets tbody tr").filter(":visible").length;
$("#total_rows_returned").html(running_total);
}
这可能是您要查找的回调: $('#myTable').tableFilterRefresh();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.