Sorting columns, server side processing

Sorting columns, server side processing

BFlokstraBFlokstra Posts: 2Questions: 1Answers: 0

I'm really new to DataTables. I implemented it in a test project (to see how useful the plugin would be to me). Here is the problem I'm faced with:

I have 6 columns. All are text columns except for one, which should be a date column. My SQL query sorts the data by date (ASC). When I add the data to the table, it's all sorted alphabetically, on the first column. I added " data-order='[[ 3, "asc" ]]'" to my code, but this seems to handle the column as text instead of date's, making the sorting:
01-08-2021,
02-09-2021,
08-08-2021,
etc

What I want is this:
01-08-2021,
08-08-2021,
02-09-2021

I read somewhere that, if server side processing is used, the data is handled as it comes in? Yet, the array I loop through is sortered by date (I checked to see if the problem was there), but the resulting table is not.

As I said, I'm complely new to this plugin. Any and all help would be greatly appreciated.

Here is my JS code:

$('#evenementenTable').DataTable({
      language: {
           processing:     "Verwerken...",
            search:         "Zoeken:",
            lengthMenu:    "Toon _MENU_ items",
            info:           "Toon  _START_ tot _END_ van _TOTAL_ items",
            infoEmpty:      "Toon 0 tot 0 van 0 items",
            infoFiltered:   "(Gefilterd uit totaal _MAX_ items)",
            infoPostFix:    "",
            loadingRecords: "Records laden...",
            zeroRecords:    "Geen items om weer te geven",
            emptyTable:     "Geen data in de tabel",
            paginate: {
                first:      "Eerste",
                previous:   "Vorige",
                next:       "Volgende",
                last:       "Laatste"
            },
            aria: {
                sortAscending:  ": Oplopend sorteren",
                sortDescending: ": Aflopend sorteren"
            }
        }
    });

And the first line of my table html:

<table class="table display" id="evenementenTable" data-order='[[ 3, "asc"]]'>

Answers

  • kthorngrenkthorngren Posts: 21,351Questions: 26Answers: 4,955
    edited July 2021

    I read somewhere that, if server side processing is used, the data is handled as it comes in?

    Server side processing is a feature enabled with the serverSide option that allows for sorting, searching and paging to be done by the server script for large sets of data. It doesn't look like you have the serverSide option enabled so you are using client side processing - your data might be loaded from a server but the table processing is done at the client.

    The server side processing documentation is here.

    This blog discusses the recommended way to handle date/time sorting with Datatables. Let us know if it helps.

    Kevin

  • BFlokstraBFlokstra Posts: 2Questions: 1Answers: 0

    i know it's been quite a long time since I asked this question. But I had this project just laying around untouched for months now. Came back to it today and read the blog link you gave. All I had to do was do the steps in that blogpost and now the sorting works as I was (sort on the date column). Thanks!

Sign In or Register to comment.