n1crack / datatables

Simplify your Datatables server-side processing effortlessly using our lightning-fast PHP library, streamlining your workflow seamlessly.
https://datatables.ozdemir.be/
MIT License
267 stars 90 forks source link

weird error with the sorting of multiple columns #98

Open xJuvi opened 6 months ago

xJuvi commented 6 months ago

Hey there,,

I have a problem where I don't know exactly how best to describe or show it.

I have a very complex query over several different tables with joins. The columns in the select command are arbitrarily ordered, because the sorting in JavaScript is done by data attribute. The sorting is defined in JavaScript and has two columns.

Now I have included the column id (is the auto increment column of the main table) and placed it at the beginning of the select query. Now only the second part of the sorting is applied, then the sorting is done by id in ascending order. After I put the id in the select query at the end and the two columns to be sorted by at the beginning, everything works.

before change (already working)

$dt->query("select g.firstname, g.lastname, g.email, g.birthdate, g.lastbooking, g.lastimpartattempt, g.registerdate  from guest g join event e [....]");

after change (only second filter is working)

$dt->query("select g.id, g.firstname, g.lastname, g.email, g.birthdate, g.lastbooking, g.lastimpartattempt, g.registerdate  from guest g join event e [....]");

now (everything is working again)

$dt->query("select  g.lastbooking, g.lastimpartattempt, g.firstname, g.lastname, g.email, g.birthdate, g.registerdate, g.id  from guest g join event e [....]");

My JavaScript defines the following order:

order: [
            ['3', 'asc'],
            ['4', 'asc']
            ],
        "columns": [
            {"data": "lastname"},
            {"data": "firstname"},
            {"data": "birthdate"},
            {"data": "lastimpartattempt"},
            {"data": "lastbooking"},
            ]

But after adding the id, only the column 4 was working, column 3 was ignored and the guests are sorted by id.

Do you have any problem? How can i help you to troubleshoot this issue?

Kind regards

n1crack commented 5 months ago

this is interesting.. I need to look into it. btw, I've updated broken docs .

It can be unrelated, I don't know but:

// ❌  i think, the first parameter should be integer

order: [
    ['3', 'asc'],
    ['4', 'asc']
  ],

// ✅   like this: 

order: [
    [3, 'asc'],
    [4, 'asc']
  ],