Datatable sort with image data not working (server-side).

Datatable sort with image data not working (server-side).

YOMYOM 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

  • kthorngrenkthorngren Posts: 20,425Questions: 26Answers: 4,794

    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

  • YOMYOM Posts: 53Questions: 22Answers: 1

    @kthorngren can you provide an example to understand it better?

  • tangerinetangerine Posts: 3,350Questions: 37Answers: 394

    There is a complete server-side script in the example here:
    https://datatables.net/examples/server_side/simple.html

  • kthorngrenkthorngren Posts: 20,425Questions: 26Answers: 4,794

    Plus you can look at the ssp.class.php script used in the examples linked by Tangerine.

    Kevin

  • YOMYOM Posts: 53Questions: 22Answers: 1
    edited July 2022

    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:

    order: [[1, "asc"]] // sorts in ascending order by 1st index
    

    This is how the Editor knows which way to sort the data. We need to override this functionality somehow.

    Does anybody know how?

  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin
    Answer ✓

    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 from myName, then the SQL generated will be ORDER BY myName ASC.

    There is no way to override that in the server-side libraries for Editor I'm afraid.

    Allan

  • YOMYOM Posts: 53Questions: 22Answers: 1

    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!

Sign In or Register to comment.