Javascript 添加新行后的表排序

Javascript 添加新行后的表排序,javascript,html,Javascript,Html,有人能告诉我在页面加载时动态地将行添加到表中后,如何触发初始排序吗 $('.tablesorter2').trigger('update'); var sorting = [[1,0]]; $('.tablesorter2').trigger('sorton',sorting); sorton函数无法触发“Age”上的初始排序 以下是完整的脚本: var options = { theme: 'default', widgets: ['editable']

有人能告诉我在页面加载时动态地将行添加到表中后,如何触发初始排序吗

$('.tablesorter2').trigger('update');

var sorting = [[1,0]]; 

$('.tablesorter2').trigger('sorton',sorting);
sorton函数无法触发“Age”上的初始排序

以下是完整的脚本:

var options = {
        theme: 'default',
        widgets: ['editable'],
        widgetOptions : {
          editable_columns       : [0,1,2],      
          editable_enterToAccept : true,          
          editable_autoAccept    : true,          
          editable_autoResort    : false,         
          editable_validate      : null,         
          editable_noEdit        : 'no-edit',     
          editable_editComplete  : 'editComplete'
       }
}
$('.tablesorter2').tablesorter(options).children('tbody').on('editComplete','td', function(event, config){
    var $this = $(this),
        tr = $this.parent('tr'),
        $allRows = config.$tbodies.children('tr'), 
        tid = tr.data('tid'),
        input="",
        name = $(this).data('name'),
        newContent = $(this).text();
        input = '<input value="'+newContent+'" name="'+name+'[]" type="hidden">';

        $this.find('.j_input').html(input);
    });

$('button').click(function(){
    var item_html = "";
    item_html += '<tr><td>Mary</td><td>5</td><td>Good</td><td>...</td><td><input type="checkbox"/></td></tr>';
   $('tbody').append(item_html);
    $('.tablesorter2').trigger('update');
    var sorting = [[1,0]]; 
    $('.tablesorter2').trigger('sorton',sorting);
});
var选项={
主题:'默认',
小部件:[“可编辑”],
widgetOptions:{
可编辑的_列:[0,1,2],
可编辑输入接受:真,
可编辑的自动接受:true,
可编辑_autoResort:false,
可编辑的验证:空,
可编辑\u noEdit:“无编辑”,
editable_editComplete:“editComplete”
}
}
$('.tablesorter2').tablesorter(选项).children('tbody').on('editComplete','td',函数(事件,配置){
变量$this=$(this),
tr=$this.parent('tr'),
$allRows=config.$tbodies.children('tr'),
tid=tr.data('tid'),
输入=”,
名称=$(this).data('name'),
newContent=$(this.text();
输入='';
$this.find('.j_input').html(input);
});
$(“按钮”)。单击(函数(){
var item_html=“”;
item_html+=“Mary5Good…”;
$('tbody').append(item_html);
$('.tablesorter2')。触发器('update');
变量排序=[[1,0]];
$('.tablesorter2').trigger('sorton',排序);
});
HTML:

添加
名称
年龄
条件
笔记
德尔
彼得
18
好
...
汤姆
12
好
药物治疗
您是否尝试过:

$('.tablesorter2').trigger('sorton',[sorting]);
$('.tablesorter2').trigger('sorton',[sorting]);