Datables with server-side: true, sorting became faulty

Datables with server-side: true, sorting became faulty

TheNerdy97TheNerdy97 Posts: 25Questions: 6Answers: 1

**https://codepen.io/TheNerdy97/pen/gOvNeeo?html-preprocessor=pug**:
**https://debug.datatables.net/ugucuh**:

**Everything is perfect but when I enable server-side and sort by any column the child-row disappears, and the sorting doesn't really show the highest or lowest values available **:

This question has an accepted answers - jump to answer

Answers

  • rf1234rf1234 Posts: 2,801Questions: 85Answers: 406
    edited June 2022

    With server-side turned on everything is done on the server. If your displayed values are rendered the sorting will be incorrect in many cases. You need to do everything based on server values which in most cases are database values without any rendering. Search for orthogonal data to find a solution: e.g. return database values to the server and only render the "display" values to be able to still achieve proper client side sorting.

    https://datatables.net/manual/data/orthogonal-data

  • TheNerdy97TheNerdy97 Posts: 25Questions: 6Answers: 1

    Even if I pass only the DB values I still can't sort correctly as you saw in the example.

  • rf1234rf1234 Posts: 2,801Questions: 85Answers: 406

    Both of your examples produce errors. I actually saw nothing.

  • TheNerdy97TheNerdy97 Posts: 25Questions: 6Answers: 1
    edited June 2022

    Fixed the errors, never mind the images not loading.
    https://codepen.io/TheNerdy97/pen/gOvNeeo?html-preprocessor=pug**:

  • TheNerdy97TheNerdy97 Posts: 25Questions: 6Answers: 1
  • TheNerdy97TheNerdy97 Posts: 25Questions: 6Answers: 1

    @allan @rf1234 As I said the problem didn't disappear even if I show server values only without rendering

  • kthorngrenkthorngren Posts: 20,141Questions: 26Answers: 4,736

    As rf1234 mentioned the sorting is handled by your server script with server side processing. Server side processing uses this protocol. You can look at the ssp.class.php script used in the server side processing examples to see the basic functionality needed.

    Does your server script support the server side processing protocol and column sorting, etc?

    Kevin

  • allanallan Posts: 61,438Questions: 1Answers: 10,052 Site admin
    ajax: 'https://raw.githubusercontent.com/TheNerdy97/BraveGacha.io/main/data.json'
    

    That's static data. That can't work with server-side processing. I wonder if you might be mixing up what server-side processing is and Ajax loading data. You can Ajax load data from a server and use client-side processing for sorting and filtering etc. See this part of the manual for a proper description.

    Allan

  • TheNerdy97TheNerdy97 Posts: 25Questions: 6Answers: 1

    That's for the sake of the example, as Codepen took too long to load the the original data

  • TheNerdy97TheNerdy97 Posts: 25Questions: 6Answers: 1

    @allan In reality, I don't think that I need serverside processing, but when I use client-side my 1000 rows became only 50 rows.

  • kthorngrenkthorngren Posts: 20,141Questions: 26Answers: 4,736

    when I use client-side my 1000 rows became only 50 rows.

    Start by looking at the browser's network inspector tool to see the XHR response. How many rows are in the response?

    Do you have a search plugin that might be filtering rows?

    In the info element, Showing 1 to 10 of 57 entries for example, how many entires does it show?

    Kevin

  • TheNerdy97TheNerdy97 Posts: 25Questions: 6Answers: 1

    Showing 1 to 10 of 50 entries

  • TheNerdy97TheNerdy97 Posts: 25Questions: 6Answers: 1

    I want server-side also because every row of my table has child row with 100-200 image

  • kthorngrenkthorngren Posts: 20,141Questions: 26Answers: 4,736
    edited June 2022 Answer ✓

    Showing 1 to 10 of 50 entries

    That suggests the server is returning only 50 rows. Look at the XHR response in the browser's console.

    I want server-side also

    As explained earlier you will need a server side processing script that supports the SSP protocol.

    Kevin

  • TheNerdy97TheNerdy97 Posts: 25Questions: 6Answers: 1

    The Module rest_framework_datatables was handling everything for serverSide, the problem was with one of the columns being integer but saved as text on the DB, so Sorting became faulty.

Sign In or Register to comment.