fnSortNeutral not working as expected

fnSortNeutral not working as expected

neuDev33neuDev33 Posts: 11Questions: 0Answers: 0
edited June 2012 in DataTables 1.9
I'm trying to implement the fnSortNeutral functionality by using it as follows -

$(document).ready(function () {

$.fn.dataTableExt.oApi.fnSortNeutral = function (oSettings) {
/* Remove any current sorting */
oSettings.aaSorting = [];

/* Sort display arrays so we get them in numerical order */
oSettings.aiDisplay.sort(function (x, y) {
return x - y;
});
oSettings.aiDisplayMaster.sort(function (x, y) {
return x - y;
});

/* Redraw */
oSettings.oApi._fnReDraw(oSettings);
};
/* Init the table */
oTable = $('#headTable').dataTable({
"bPaginate": false,
bJQueryUI: true,
"bSortClasses": false,
"sDom": 'T<"clear">lfrtip',
........
..........
});
});

function clearSort()
{
oTable.fnSortNeutral();
}

However, when the clearSort functon is called, the table is sorted by the first column instead of clearing the sort and getting the table to display as it did when it loaded for the 1st time. Is this expected behavior? Or am i not using this correctly?

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    The neutral sort plug-in should restore the sort to the order the data was originally read in as. Can you link to an example that doesn't work please?

    Allan
This discussion has been closed.