Sending Alternative Sort Column to Server-Side

Sending Alternative Sort Column to Server-Side

dickbobdickbob Posts: 10Questions: 0Answers: 0
edited April 2012 in General
Hi,

DataTables is working fine for me with server-side processing until I try to change the default sort column and direction.

This is my client-side code which is working fine...

[code]
$.extend($.fn.dataTable.defaults, {
"bLengthChange": false
,"bFilter": false
,"iSortCol_0": 0
,"sSortDir_0": "asc"
});

$('#courseUserListing').dataTable({
"bProcessing": true
,"iDisplayLength": 13
,"bServerSide": true
,"sAjaxSource": "process.cfm"

,"aoColumns": [
{"mDataProp": "username", "sTitle": "Username", "sClass": "edit", "bSortable": true}
,{"mDataProp": "firstname", "sTitle": "First Name", "sClass": "edit", "bSortable": true}
,{"mDataProp": "surname", "sTitle": "Surname", "sClass": "edit", "bSortable": true, "bSort": true}
,{"mDataProp": "emailAddress", "sTitle": "Email Address", "sClass": "edit", "bSortable": true}
,{"mDataProp": "delete", "sTitle": " ", "sWidth": "78px", "bSortable": false}
]

,"fnServerData": function (sSource, aoData, fnCallback) {
$.ajax(
{"dataType": "json"
,"type": "POST"
,"url": sSource
,"data": aoData
,"success": fnCallback}
);
}
});
[/code]

...but if I want to initially sort want to sort by the "surname" which is column 2 in descending order by doing...

[code]
$.extend($.fn.dataTable.defaults, {
"bLengthChange": false
,"bFilter": false
,"iSortCol_2": 2
,"sSortDir_2": "desc"
});
[/code]

...I still get...

[code]
iSortCol_0 1
sSortDir_0 asc
[/code]

...posted to my server-side.

I guess I'm doing something wrong but can't figure out what!

All suggestions welcome :-)

Regards,

Richard

Replies

  • allanallan Posts: 63,810Questions: 1Answers: 10,516 Site admin
    iSortCol_{i} is not an initialisation option - hence why trying to set it has no effect!

    The default sort is controlled using the aaSorting option.

    Allan
  • dickbobdickbob Posts: 10Questions: 0Answers: 0
    Ah right, I misunderstood the purpose of iSortCol_{i}.

    All working now.

    Thanks for your prompt help.

    Richard
This discussion has been closed.