custom http variables - 1.10

custom http variables - 1.10

mihomesmihomes Posts: 165Questions: 23Answers: 0
edited May 2014 in DataTables 1.10

Trying to understand how this is used - http://datatables.net/examples/server_side/custom_vars.html and the example isn't doing much for me. Is d.myKey available in scripts/server_processing.php then for that example or...?

Here is what I am looking to do. Majority of my data tables include a timestamp column. I want to include a date range filter on my page (there would be a start and end value) and pass onto my server-side processing so I can filter the data. Is that the type of thing this is intended for? Normally I would just use jquery to pass those variables onto my script then do what I need on that end, but I came across this and am a little confused how and what it is used for.

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin

    Is d.myKey available in scripts/server_processing.php then for that example or...?

    Yes - in that case you will be able to use $_GET['myKey'] to get the parameter.

    Is that the type of thing this is intended for?

    Bang on! You might use something like:

    $(document).ready(function() {
        $('#example').dataTable( {
            "processing": true,
            "serverSide": true,
            "ajax": {
                "url": "scripts/server_processing.php",
                "type": "POST",
                "data": function ( d ) {
                    d.range_start = ...;
                    d.range_end = ...;
                }
            }
        } );
    } );
    

    filling in the ... with how you get your values of course! Then you will have $_POST['range_start'] and $_POST['range_end'] at the server-side (I've used POST in this example, while the linked example uses GET).

    Does that make sense?

    Regards,
    Allan

This discussion has been closed.