[英]jQuery Datatables sort multiple tables
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 未捕获的TypeError:无法读取未定义的属性'sSortDataType'
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. fnSort()的参数必须是一个二维数组,因为它需要一个数组,其中包含您要排序的所有列的排序,包括列的排序选项。 Like this: $(allTables[i]).dataTable().fnSort([[index, "asc"]]) ; 像这样: $(allTables [i])。dataTable()。fnSort([[index,“asc”]]) ;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.