Custom sort problem

Custom sort problem

tomas209tomas209 Posts: 1Questions: 0Answers: 0
edited June 2011 in Bug reports
Hi,
I'm experiencing a problem when using custom sort definition. I define custom sorting for one table column:
[code]
"aoColumns": [
{ sWidth: "20%", "sType": 'detail_date' },
{ sWidth: "10%" },
{ sWidth: "45%" },
{ sWidth: "25%" }
]
[/code]

and callback sorting function as follows:
[code]
jQuery.fn.dataTableExt.oSort['detail_date-asc'] = function(x, y) ...
jQuery.fn.dataTableExt.oSort['detail_date-desc'] = function(x, y) ...
[/code]

I switched state saving on. So part of options defunitions is as fllows:
[code]
...
"bSort": true,
"bInfo": false,
"bAutoWidth": false,
"bStateSave": true,
"sPaginationType": "four_button",
"aaSorting": [],
...
[/code]

When I first load the page, sorting works fine on every column. But when I have first column sorted and refresh page via F5, sorting on all columns stops working. In IE javascript error is shown: "Object doesn't support this property or method", referencing to jQuery.datatables.js, to code
[code]
iTest = oSort[ iDataType+"-"+aaSort[i][1] ](
aoData[a]._aData[iDataSort],
aoData[b]._aData[iDataSort]
);
[/code]

Also, I'd like to have default sorting on the first column (ie the one with custom sorting), but when I use
[code]
"aaSorting": [[0, "asc"]],
[/code]

the js error is thrown right at the page load.

Any help greatly appreciated.
And thanks for this great plugin and your effort, anyway.

Replies

  • tomas209tomas209 Posts: 1Questions: 0Answers: 0
    Solved. All I had to do was to define custom sorting BEFORE calling datatable() function. Didn't got that from description here.
  • allanallan Posts: 63,389Questions: 1Answers: 10,449 Site admin
    Good to hear you got this working. The code does need to be available before it can be used - which is noted in the documentation on this page: http://datatables.net/plug-ins/sorting

    > include the plug-in's code in the Javascript available for your page, after you load the DataTables library, but before you initialise the DataTable

    I'll look at ways of making this clearer in future.

    Regards,
    Allan
This discussion has been closed.