Server side sorting

Server side sorting

MarekAdamMarekAdam Posts: 30Questions: 9Answers: 1

Link to test case: https://editor.datatables.net/examples/standalone/collection.html
Description of problem:
I use standalone like in link but i have verticaly div. Many divs in many tabs. All works ok but i need to sort data by date. How to do it?
Give any parametr to ajax or somenthing like ->order (not working) in php file?

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,327Questions: 26Answers: 4,949

    Server side sorting

    Does that mean you are using server side processing, ie serverSide: true? If so the server script is responsible for querying the data with the appropriate sorting. Are you using a Datatables supplied server side processing script?

    Give any parametr to ajax or somenthing like ->order (not working) in php file?

    See the Server side processing protocol docs for details of the parameters sent. You will see there is an order[i][column] and order[i][dir] parameter for each column. Your server script will need to use this to build the appropriate query.

    If you still need help then please provide more details about your solution especially the server side.

    Kevin

  • MarekAdamMarekAdam Posts: 30Questions: 9Answers: 1

    My code is almost the same as in the example. The main difference is that there is leftJoin in php and appropriate changes in js.

     $.ajax({
                url: '/php/table.zapisy.php',
                dataType: 'json',
                success: function (json) {
    
                    for (var i = 0, ien = json.data.length; i < ien; i++) {
                        createPanel(json.data[i],json.options["zapisy.pac"]);
                    }
                }
            });
    

    php file is standard.

    The problem is that there is no classic "new DataTable" call here and I don't know how to do it in js or php. I would also like to refresh the table with a button (normally I can do it) but I have no idea how to do it here

  • kthorngrenkthorngren Posts: 21,327Questions: 26Answers: 4,949

    Sorry I misunderstood the question - you aren't using Datatables nor server side processing.

    The panels are being loaded on the page in the order of the JSON response. I see two options:

    1. Update the server side query to order the data by the date. If using SQL like query you can use ORDER BY to sort the date field.
    2. In Javascript you can sort the JSON response by the date property to be used in the for loop. Here is one example.

    Kevin

  • MarekAdamMarekAdam Posts: 30Questions: 9Answers: 1
    1. I use server side Editor instance from example. How i can add it? There is no
      ->order_by instance
  • MarekAdamMarekAdam Posts: 30Questions: 9Answers: 1

    I found an interesting workaround on the forum, but I don't know why it doesn't work. I add:

    ->where( 'data', $data ." ORDER BY `gz`.`g` DESC" , '>')
    

    In debuging console i see good sql query. When i paste it to phpmyadmin its working but on my page still is order by ID. Why? I have no sorting in JS.

  • MarekAdamMarekAdam Posts: 30Questions: 9Answers: 1
    Answer ✓

    Correct query. You can close the topic. Great script, thanks guys for the good job!

        ->where( function ( $q ) use ( $data ){
            $q->where('data', $data . " ORDER BY `gz`.`g` ASC", '>', false);
        })
    
    
Sign In or Register to comment.