同一模板上的两个表中的jQuery tablesorter?
我在同一个模板中有两个表,数据是在这两个表上动态生成的。这两个表都可以有数据,它们中没有一个可以有数据,或者只有一个可以有数据。我想用数据对表进行排序,即使另一个表上没有数据,所以我在jQuery中使用了这样的if条件:同一模板上的两个表中的jQuery tablesorter?,jquery,tablesorter,Jquery,Tablesorter,我在同一个模板中有两个表,数据是在这两个表上动态生成的。这两个表都可以有数据,它们中没有一个可以有数据,或者只有一个可以有数据。我想用数据对表进行排序,即使另一个表上没有数据,所以我在jQuery中使用了这样的if条件: $(document).ready(function() { // call the tablesorter plugin if ($("#product-table tbody td").length > 0){ $("table").tab
$(document).ready(function() {
// call the tablesorter plugin
if ($("#product-table tbody td").length > 0){
$("table").tablesorter({
// sort on the first column and third column, order asc
sortList: [[0,0],[2,0]]
});
}
});
当我使用它时,控制台中不会出现任何错误,但是如果一个表为空,排序在另一个表上就不起作用。如果两个表都有数据,则排序工作正常 只检查一个表的数据长度。这样试试看
$(document).ready(function() {
// call the tablesorter plugin
if ($("#product-table tbody td").length > 0){
$("#product-table").tablesorter({
// sort on the first column and third column, order asc
sortList: [[0,0],[2,0]]
});
}
if ($("#product-table2 tbody td").length > 0){
$("#product-table2").tablesorter({
// sort on the first column and third column, order asc
sortList: [[0,0],[2,0]]
});
}
});