在jquery插入时,tablesorter外部搜索输入栏失败

时间:2016-11-01 04:34:18

标签: javascript jquery tablesorter

我正在尝试编写一个js函数,它将触发在我的表顶部插入一个搜索栏,因为我有很多需要它的页面而且我讨厌重复代码。但是,这个带有类搜索的搜索栏是在我的主.tablesorter js之后执行的。

我所有触发更新的努力都失败了。我甚至尝试在控制台中执行.tablesorter脚本,就像我插入输入栏之前一样。如果我将它留在html中,外部搜索栏的效果会很惊人,但是只要涉及到jquery,我就无法触发任何排序。

我想知道我是否可以发信号通知js立即执行,因为我的tablesorter等到页面加载...

filter_functions : {
                    filter_placeholder: { search : 'Search...' },
                    filter_saveFilters : true
                },
                //FOR SEARCH BAR
                filter_external : '.search',

...

jQuery(".buttons-on-right").prepend

1 个答案:

答案 0 :(得分:0)

有一个内部过滤功能(bindSearch),允许在tablesorter初始化后绑定外部搜索输入。使用方法如下:

var table = $('#mytable'),
  input = $('.search');
// the third parameter (set as false) forces a new search
// on the current value of the newly added input; do not
// include the third parameter to silently add the new input
$.tablesorter.filter.bindSearch(table, input, false);

注意:外部输入必须具有data-column="#"属性才能生效。 #设置为从零开始的列索引,或设置为all以搜索所有列。