Sending Alternative Sort Column to Server-Side
Sending Alternative Sort Column to Server-Side
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
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
This discussion has been closed.
Replies
The default sort is controlled using the aaSorting option.
Allan
All working now.
Thanks for your prompt help.
Richard