Default Sort Order Using Null Column in SSP
Default Sort Order Using Null Column in SSP
I discovered an issue related to server-side processing and default sort order that triggers an error Unknown field: (index 0).
To replicate, alter DataTables/example/simple/simple.html $('#example').DataTable( { declaration by adding:
dom: "Bfrtip",
ajax: { url: "<url_to_use>", "type": "POST" },
serverSide = true,
...
In this example, the sort sent to the server is defaulted to sort: [[0, "asc"]] but since the first column is derived with data = null, the server side code in .NET library fails with Unknown field: (index 0) error. I did not test any other server side libraries.
One way to resolve this, is to add an explicit order declaration like order: [[1, 'asc']],
Maybe the core library should do an inspection of the data property of each column and default the sort to be the first column with a non-null data property.
On a side note, the .NET library requires the ajax POST as it ignores the query string. Not sure if this is an oversight but it was a code trap for me that was not trivial to debug.
Hope this helps others.
Replies
Another, better work around for sorting issue is to do add the
first_nameandlast_namecolumns to the table as hidden columns and then defineorderDataproperty for the derivedNamecolumn to use the the two new hidden columns.Do you mean this example? If so, then yes, I would expect server-side processing to fail on the first column since it has
data: nullin the column declaration. The renderer is a client-side construct, so the server can have no way to know what column in the database you want to have it sort on.One solution is to set
data: 'first_name'which will instruct the server to sort on that column. It falls apart if you have multiple people with the same name - for that you could use thecolumns.orderDataoption along with hidden columns as you have done.Regards,
Allan