Friday 15 August 2014

datatables - Dynamic multicolumn sorting using fnPreDrawCallback -


I have a table with 3 columns and when I sort the columns 1 or 2, I descend to column 3 I want to sort.

I am using fnPreDrawCallback (I also tried to use fnDrawCallback ).

Here is my code:

  "fnPreDrawCallback": function (oSettings) {var column = oSettings.aaSorting [0] [0]; If (column! == 3) {oSettings.aaSorting.push ([3, "desc"]); }}  

This code looks fine, but, for example, when I solve column 1, then column 3 is not sorted, and is more weird, When I try to sort the second time on column 1, the results of the sort always keep climbing.

How can I get it?

The data has already been "sorted", unless the preDrawCallback is removed, Changing type isetching will not change the results of the table.

You can verify by checking oSettings. AID display and AIDSpeel are master properties. AIDISplay is a sort of orange array of similar elements that changes because they are sorted by click on one th. Adisplaymaster is the original order that the data came back from the server or was present on the page.

I will call fnSort manually due to the occurrence of clicks of your elements. To do this, you have to pair the data event, which installs DataTable.

Create a function like this and call it fnInitComplete, so it runs only after the datatable setup. UnbindDTSorting () // // Unbind the sorted event when the header is clicked, click $ j ('[id $ = table] th')

  function. Unbind ('click.DT'); // Create your own click handler for header $ J ('[ID $ = table] th'). Click (function (e) {var oTable = $ j ('[id $ = table]'). DataTable (); // Here is where you make all your if / other arguments to create the desired multi-disciplinary classification If this (if.cellIndex == 3) {oTable.fnSort ([[2, 'asc'], [3, 'desc']]);}}); }  

No comments:

Post a Comment