jQuery Datatables对多个表进行排序 [英] jQuery Datatables sort multiple tables
问题描述
当我点击一个表的列标题时,可以对所有的表进行排序。
行为应该是,如果我点击列标题'名称'(例如)所有表将被排列在同一列。
我我试图执行以下操作:
$(document).on(click,.myTable thead th function(){
var index = $(this).closest(thead)。children(tr)。find(th)。index($(this));
var allTables = $ .fn.dataTable.fnTables();
for(var i = 0; i< allTables.length; i ++){
$(allTables [i ])。dataTable()。fnSort([index,asc]);
}
})
但是当我这样做时,我得到以下异常:
未捕获TypeError:无法读取属性'sSortDataType'未定义
fnSort()的参数必须是 2维数组,因为它需要一个数组,其中包含要排序的所有列的排序列出列的排序选项。像这样: $(allTables [i])。dataTable()。fnSort([[index,asc]])
We have a page with multiple tables on it. All tables are identical (except for the data of course). Is it possible to sort all the tables when I click on a column header of one table. The behaviour should be that if I click on the column header 'Name' (for example) that all tables will be sorted on the same column.
I've tried to do the following:
$(document).on("click", ".myTable thead th", function () {
var index = $(this).closest("thead").children("tr").find("th").index($(this));
var allTables = $.fn.dataTable.fnTables();
for (var i = 0; i < allTables.length; i++) {
$(allTables[i]).dataTable().fnSort([index, "asc"]);
}
})
But when I do this I get the following exception:
Uncaught TypeError: Cannot read property 'sSortDataType' of undefined
The parameter for fnSort() had to be a 2 dimensional array because it expects an array which contains the sorting for all columns you would like to sort including the sort option for the column. Like this: $(allTables[i]).dataTable().fnSort([[index, "asc"]]);
这篇关于jQuery Datatables对多个表进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!