开发者

jquery tablesorter access internal config parameter

i'm working since hours on this issue without any success, hope to get some help here! I use the tablesorter plugin to sort table on client side. First of all, I 开发者_开发百科set an default sort order and initalize the sorter-plugin:

var defaultSort=[[4,1]];
$("#myTable").tablesorter({sortList:defaultSort});

Which does not work (does not sort) while this works:

 $("#myTable").tablesorter({sortList: [[4,1]]});

Can't see a reason for this behavior.

Later, I add columns dynamically by using getJSON. After adding a line, I have to update the tablesorter and order again (because of the new rows). For that: read the current "sortList" and try to apply this list:

$("#myTable").trigger("update");
sortOrder=$("#myTable")[0].config.sortList;
setTimeout('$("#myTable").trigger("sorton",['+sortOrder+']);',1);

But this does not work. There is no ordering. An console.info(sortOrder) returns 4 instead of [[4,1]]. Why?

But all this code works, if the sortList is hardcoded, like:

$("#myTable").trigger("update");
setTimeout('$("#myTable").trigger("sorton",[[[4,1]]]);',1);

Thank you


try this:

var myTable = $("#myTable");
var sortOrder=myTable.trigger("update")[0].config.sortList;
setTimeout(function(){
    myTable.trigger("sorton",[sortOrder]);
},1);

in your 3rd example you wrote

setTimeout('$("#myTable").trigger("sorton",['+sortOrder+']);',1);

sortOrder is having toString() called on it when you stick it in that string. That's at least one of the reasons it's not working.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜