Tablesorter Filter小部件在所有浏览器上更新后停止工作,没有错误消息

我试图看看我如何解决我在jQuery Tablesoter小部件中遇到的问题’filter’,它在更新表后没有任何错误消息就停止工作,它在所有Web浏览器上执行此操作,其他小部件像zebra和saveort这样的工作只有filter停止工作。

这是代码:

        var comper; function checkSession() { return $.get("ajaxcontrol.php", function (DblIn) { console.log('checking for session'); if (DblIn == 1) { window.location = 'loggedout.php'; } }).then(updateTable); } function checkComper() { var SvInfo; var onResponse = function (comperNow) { if (comper === undefined) { comper = comperNow; } else if (comper !== comperNow) { var Vinfoo; comper = comperNow; // returning this $.get will make delay done until this is done. return $.get("getlastupdate2.php", function (primaryAddType) { Vinfoo = primaryAddType; $().toastmessage('showNoticeToast', Vinfoo); }).then(checkSession); } }; $.get('getlastupdate.php').then(onResponse).done(function () { tid = setTimeout(checkComper, 2000); }); } function updateTable() { return $.get('updatetableNEW.php', function (data) { console.log('update table'); var $table = $("table.tablesorter"); var $tableContents = $table.find('tbody') ////// var $html = $('').html(data); $tableContents.replaceWith('' + data + '') //$tableContents.replaceWith($html) $table.trigger("update", [true]); var currentUrl = document.getElementById("frmcontent").contentWindow.location.href; var urls = ['indexTOM.php', 'index1.php'], frame = document.getElementById('frmcontent').contentDocument; for (var i = 0; i < urls.length; i++) { var url = urls[i]; if (frame.location.href.indexOf(url) !== -1) { frame.location.reload() } } $('[title!=""]').qtip({}); }); }; $(function(){ var tid = setTimeout(checkComper, 2000); $("#append").click(function (e) { // We will assume this is a user action e.preventDefault(); updateTable(); }); // define pager options var pagerOptions = { // target the pager markup - see the HTML block below container: $(".pager"), // output string - default is '{page}/{totalPages}'; possible variables: {page}, {totalPages}, {startRow}, {endRow} and {totalRows} output: '{startRow} - {endRow} / {filteredRows} ({totalRows})', // if true, the table will remain the same height no matter how many records are displayed. The space is made up by an empty // table row set to a height to compensate; default is false fixedHeight: true, // remove rows from the table to speed up the sort of large tables. // setting this to false, only hides the non-visible rows; needed if you plan to add/remove rows with the pager enabled. removeRows: false, // go to page selector - select dropdown that sets the current page cssGoto: '.gotoPage' }; // Initialize tablesorter // *********************** $("table") .tablesorter({ theme: 'blue', headerTemplate : '{content} {icon}', // new in v2.7. Needed to add the bootstrap icon! widthFixed: true, widgets: ['savesort', 'zebra', 'filter'], headers: { 8: { sorter: false, filter: false } } }) // initialize the pager plugin // **************************** .tablesorterPager(pagerOptions); // Delete a row // ************* $('table').delegate('button.remove', 'click' ,function(){ var t = $('table'); // disabling the pager will restore all table rows t.trigger('disable.pager'); // remove chosen row $(this).closest('tr').remove(); // restore pager t.trigger('enable.pager'); }); // Destroy pager / Restore pager // ************** $('button:contains(Destroy)').click(function(){ // Exterminate, annhilate, destroy! http://www.youtube.com/watch?v=LOqn8FxuyFs var $t = $(this); if (/Destroy/.test( $t.text() )){ $('table').trigger('destroy.pager'); $t.text('Restore Pager'); } else { $('table').tablesorterPager(pagerOptions); $t.text('Destroy Pager'); } return false; }); // Disable / Enable // ************** $('.toggle').click(function(){ var mode = /Disable/.test( $(this).text() ); $('table').trigger( (mode ? 'disable' : 'enable') + '.pager'); $(this).text( (mode ? 'Enable' : 'Disable') + 'Pager'); return false; }); $('table').bind('pagerChange', function(){ // pager automatically enables when table is sorted. $('.toggle').text('Disable'); }); });   

也许在表更新后需要重新加载filter小部件?

我首先想到更新的表没有正确的格式,所以我将视图源保存为html文件,当我在本地打开页面时,’filter’(搜索)工作正常,所以它不能是表( )格式或所以我认为,但它能做什么,任何人都可以帮助我,我一直试图让这个工作两个星期,我想出了我的知识,因为我的知识是有限的:(谢谢。

看起来插件需要知道我们进行了更新,我只需要触发updateAll命令。

像这样:

 var resort = true, // re-apply the current sort callback = function(){ // do something after the updateAll method has completed }; $("table").trigger("updateAll", [ resort, callback ]); 

需要花费很多代码,但您可能想尝试更新表格内容,如下所示:

 var $table = $("table.tablesorter"); $table.find('tbody').html(data); $table.trigger("update", [true]); 

我只是猜测replaceWith()函数没有按预期工作。

同样的问题在这里

简短的解决方案:将filter-select设置为filter匹配类,然后该表将再次运行。

长解决方案:有没有人有一个表格分类器与ajax寻呼机和filter插件相结合的工作示例?