data-order attr in Server side Processing
data-order attr in Server side Processing
samraj
Posts: 9Questions: 1Answers: 1
Without using serverside we can use data-order attribute for custom sort. I want to use it in serverside too, as I have a column where it contains mixed data sets like int, float, string. The sorting is happening by take the column as a string. So I'm getting 75 at first then getting 100.
Example : [0, 100, 75, 100, NA] is sorted desc as [75, 100, 100, 0, NA]. Sorry I cannot link a test case please don't ask for it.
Replies
data-order
is an HTML attribute, so it isn't relevant for server-side processing.However, more importantly than that, the sorting is done at the server-side when server-side processing. So whatever script it is you are using would need to be updated to send the data in the order you want to the client-side.
Allan
Hi @allan, is there any other way for custom sorting for serverside in the js or should we do it only in the php where it returns the data?
I'm using ssp.class.php and datatables version 2.0.1
If you are using server-side processing, then the sorting has to be done at the server-side. The client-side doesn't have the full data set, so it can't sort the data.
The demo SSP class doesn't have the ability to do anything smart like what you are looking for - it simply tells the database to sort by a specific column, and it is up to the DB how that sort happens. If you want to modify that, this is the function where the custom SQL would need to be added (probably a
case
statement, but it isn't something I've done in SQL before).Allan
Already did that in the demo SSP and it's working fine now. I have just handled for columns which will have mixed datatypes. In my case that was the issue, but also with this now only I got an idea of using like data-order in the server side. I'm gonna try that too. Below is the code for handling mixed datatypes sorting
Nice one