Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用tablesorter.js对表中的ajax数据进行排序_Javascript_Jquery_Tablesorter - Fatal编程技术网

Javascript 使用tablesorter.js对表中的ajax数据进行排序

Javascript 使用tablesorter.js对表中的ajax数据进行排序,javascript,jquery,tablesorter,Javascript,Jquery,Tablesorter,我试图使用tablesorter.js,但在使用ajax更新表时遇到了问题。我照做了,但它似乎工作不正常。我还注意到,即使在示例网站上,代码也不能正常工作。单击“附加新表数据”时,会将数据添加到表中,但排序不正确。如果我复制javascript代码并将其粘贴到控制台中,它将正常工作并正确排序表。im使用的代码如下所示: var updateTableSort = function(){ var table = $('#transaction-table') //tells tab

我试图使用tablesorter.js,但在使用ajax更新表时遇到了问题。我照做了,但它似乎工作不正常。我还注意到,即使在示例网站上,代码也不能正常工作。单击“附加新表数据”时,会将数据添加到表中,但排序不正确。如果我复制javascript代码并将其粘贴到控制台中,它将正常工作并正确排序表。im使用的代码如下所示:

var updateTableSort = function(){
    var table = $('#transaction-table')
    //tells table sorter that table has been updated
    table.trigger("update");
    //re sorts after table has been updated based on 
   //current sort patern
    var sorting=table.get(0).config.sortList;
    table.trigger('sorton', [sorting]);
}    
同样,如果我将它复制并通过控制台,它工作得很好,但是当我的success ajax函数中有它时,它不会正确地对表排序。如果您能帮我找出问题所在,我们将不胜感激

试试我的。更新后,它会自动调用表:

// pass anything BUT false and the table will resort
// using the current sort
$("table").trigger("update", [false]);
以下是:


真是太棒了,这个补丁成功了!!我不确定我使用的方法有什么问题,但是谢谢你的新解决方案!
$(function() {

  $("table").tablesorter({ theme : 'blue' });

  $("#ajax-append").click(function() {

    $.get("assets/ajax-content.html", function(html) {

      // append the "ajax'd" data to the table body
      $("table tbody").append(html);

      // let the plugin know that we made a update
      // the resort flag set to anything BUT false (no quotes) will
      // trigger an automatic
      // table resort using the current sort
      var resort = true;
      $("table").trigger("update", [resort]);

      // triggering the "update" function will resort the table using the
      // current sort; since version 2.0.14
      // use the following code to change the sort; set sorting column and
      // direction, this will sort on the first and third column
      // var sorting = [[2,1],[0,0]];
      // $("table").trigger("sorton", [sorting]);
    });

    return false;
  });

});