Clear sorting instead of fnSort([]);

Clear sorting instead of fnSort([]);

miodraglmiodragl Posts: 2Questions: 0Answers: 0
edited February 2012 in General
Hi.
I lost one day trying to find other solution for clear all sorting.
At first I used
[code]
oTable.fnSort([]);
[/code]
But i have to find other solution for clearing
I found solution for search reset with this function
[code]
$.fn.dataTableExt.oApi.fnResetAllFilters = function (oSettings) {
for(iCol = 0; iCol < oSettings.aoPreSearchCols.length; iCol++) {
oSettings.aoPreSearchCols[ iCol ].sSearch = '';
}
oSettings.oPreviousSearch.sSearch = '';
}
[/code]
I also tried with this
[code]
$.fn.dataTableExt.oApi.fnResetAllSorting = function (oSettings) {
oSettings.aaSorting = [];
}
[/code]
but it doesn't work.

Replies

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    This is the plug-in that you want to get the original data input order: http://datatables.net/plug-ins/api#fnSortNeutral . Or if you want the original sorting you should apply the default sort ( fnSort([[0,'asc']]); )

    Allan
  • miodraglmiodragl Posts: 2Questions: 0Answers: 0
    Does exist any way to disable table redrowing in oTable.fnSort([]); ?
  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    Stop the table from redrawing? No, fnSort will automatically call fnDraw. What's the use case for not redrawing?

    Allan
  • tpctpc Posts: 12Questions: 0Answers: 0
    edited October 2012
    Allan, here's a use case.

    I'd like to give my user the ability to sort selected rows to the top of the table. To do so I set a value in a hidden column on the tr click event then attempt to call fnSort on that column. The fnDraw blows away the hidden values that I set and thus I lose the ability to sort on the selected items.

    Is there another way to do this without relying on a hidden column?
  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    First thing to say is that DataTables 1.10 will not do an automatic redraw on sorting when using the new API.

    Having said that, I don't understand why fnDraw would blow away values you set in a column, unless you are using server-side processing. Please link to an example :-)

    Allan
  • jlunajluna Posts: 2Questions: 0Answers: 0
    Hello,

    Here's a use case I've been dealing with that would benefit from not redrawing when sorting (I'm using 1.9.3 btw:

    When initializing the datatable I need to give a value to a column based on the "order number" that is stored. I would get something like this:

    [{"id": "92, "order": "3"}, {"id": "94", "order": "", {"id": 95, "order": "1"} ... ]

    By default the table is ordered by "id" and there's a checkbox that displays the order column and some controls in case the user wants to set her own order (and change the "order" value).

    The thing here is that there are some rows that do not have an "order" and I would like to set it to the row they are displayed when sorted using "numWithNull" sorting (http://datatables.net/forums/discussion/9784/sort-columns-with-numbers-and-empty-cells/p1)

    What I would like to do is to sort it as numWith-null on the initCallback so I can set the correct row and then sort it back again by the default sort. The problem is that this makes the table "move" for the user when loading.

    Pretty sure there's a better way that I'm unaware of, though :P

    p.s. As always, great job you've done Allan! Thank you so much!
This discussion has been closed.