Column sorting false, but still i want to have results displayed desc

Column sorting false, but still i want to have results displayed desc

doghidoghi Posts: 22Questions: 1Answers: 0
edited June 2023 in Free community support

This is the demo im working with : https://phppot.com/php/column-search-in-datatables-using-server-side-processing/

This part of the code is the problem:

order: [[0, 'desc']],
columnDefs: [{
targets: "_all",
orderable: false

The problem is that my results are ASC ordered, even in my code is DESC, this is because orderable is false, and if i switch orderable to true, my desc sorting is working, but also makes every column to sort every time when im clicking on them to enter my search values.

I added a short video here, im not sure if im explaining very well, so the video can help.
https://we.tl/t-V8o9KJaaPf
**:

Answers

  • kthorngrenkthorngren Posts: 21,337Questions: 26Answers: 4,954

    Your code snippet works in the SSP test case:
    https://live.datatables.net/nisokizi/4/edit

    The problem will be in the server side processing code you are using. I believe the SSP examples and SSP JS Bin examples use ssp.class.php like the tutorial you linked to. The server code will need to be debugged to determine why it is sorting incorrectly with the above config.

    Kevin

  • doghidoghi Posts: 22Questions: 1Answers: 0
    edited June 2023

    The sorting works good if orderable is on true, but the problem is when i want to use column search, when i click on column search input to enter my keywords, that click is activating the sorting.

    Is there a way to keep orderable on true, and disable sorting when clicking on column ?

    Did you manage to check the video ?

  • doghidoghi Posts: 22Questions: 1Answers: 0

    with orderable on false clicking on each column not activating the filter, and is exactly what i want. But the sorting by id (desc) not working anymore.

    https://we.tl/t-1qwBxfunNC

    If i go on true for orderable sorting is working but each time when i click on column to search...is activating the search, and is very hard to use it, watch the first video for this example.

  • doghidoghi Posts: 22Questions: 1Answers: 0

    Lolz, i manage to solve it.

    In my server-side script (ssp.class.php) i changed the original code from:

    if ( $requestColumn['orderable'] == 'true' ) {
    $dir = $request['order'][$i]['dir'] === 'asc' ?
    'ASC' :
    'DESC';

    changed to:

    if ( $requestColumn['orderable'] == 'false' ) {
                    $dir = $request['order'][$i]['dir'] === 'desc' ?
                        'DESC' :
                        'ASC';
    

    Now with orderable on false the default sorting is DESC and clicking on column sorting is disabled. Perfect!

    Thx mate, your hint helped me.

  • kthorngrenkthorngren Posts: 21,337Questions: 26Answers: 4,954

    Glad you got it fixed.

    Have you tried using two header rows, one for the search inputs? See this example:
    https://live.datatables.net/giharaka/1/edit

    This will allow you to have both sorting and searching in the header.

    Kevin

  • doghidoghi Posts: 22Questions: 1Answers: 0

    nop :)) first time when i see this version. I will try it.

    Is there a way to limit the default database query, for example i want to display in table only results from the last 3 days by default.

  • kthorngrenkthorngren Posts: 21,337Questions: 26Answers: 4,954

    You can use deferLoading if you don't want the first request sent when initializing Datatables. This example shows how to send input parameters using ajax.data as a function. If this doesn't help then please provide more details of what you want.

    Kevin

Sign In or Register to comment.