0

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

2
  • Looks like it should work. Can you link to a test case please. Commented Apr 30, 2013 at 10:00
  • 1
    SOLVED: 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"]]); Commented Apr 30, 2013 at 13:19

1 Answer 1

2

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"]]);

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.