Datatable sort with image data not working (server-side).
Datatable sort with image data not working (server-side).
YOM
Posts: 53Questions: 22Answers: 1
Description of problem:
The data has a image and a number associated with it. I want the column to be able to sort but its not happening. I tried some examples from the documentation it is not working. The data in the cell is in the form of "<img src=' '> number"
Screenshot of output:
This question has an accepted answers - jump to answer
Answers
Based on your title you have server side processing enabled. With SSP enabled sorting, searching and paging processes are handled by the server script. You will need to build your data queries to perform the sorting the way you want.
Kevin
@kthorngren can you provide an example to understand it better?
There is a complete server-side script in the example here:
https://datatables.net/examples/server_side/simple.html
Plus you can look at the ssp.class.php script used in the examples linked by Tangerine.
Kevin
We're using the node library 'datatables.net-editor-server' and have our data query built using the Editor class. It's not very clear from the docs how to override or extend the sorting functionality for the query
The frontend is sending an options object to the Editor instance in our server. This object contains an option for sorting:
This is how the Editor knows which way to sort the data. We need to override this functionality somehow.
Does anybody know how?
The way the Editor server-side scripts work for ordering server-side processing data is to look up the field based on the
columns.data
for the column index being sorted. It will then generate an ORDER BY statement for that column.So for example if you use
order: [[1, 'asc']]
and column index 1 uses the data frommyName
, then the SQL generated will beORDER BY myName ASC
.There is no way to override that in the server-side libraries for Editor I'm afraid.
Allan
That's alright, we will likely just redesign the column to be only a numeric value then to avoid the needless complexity. Thanks for the clear answer Allan!