Server-side processing and parameters

Server-side processing and parameters

Jeff06Jeff06 Posts: 5Questions: 0Answers: 0

Hello,

I'm using DataTable 1.10.3.
I've created a datatable (Server-side processing) and it works.
I use :

$(document).ready(function() {
$('#example').dataTable(
{
"processing": true,
"serverSide": true,
"ajax": "my_page.php",
} );
} );

Now, I want to sent a query with a condition in order to build my datatable.
I have : "select a, b, c from myTable"
I want : "select a, b, c from myTable where a='myValue'"

I read that I had to use "fnServerParams".
I tried :

$(document).ready(function() {
$('#example').dataTable(
{
"processing": true,
"serverSide": true,
"ajax": "my_page.php",
"fnServerParams": function ( aoData )
{
aoData.push( { "name":"country", "value": "EN"} );
}
} );
} );

However it doesn't work.
"Processing..." appears and that's all.
Moreover, in the log of my browser, I read :
"TypeError: aoData.push is not a function "

What can I to do ?
Thanks in advance.

Replies

  • allanallan Posts: 63,290Questions: 1Answers: 10,428 Site admin

    Use ajax.data in DataTables 1.10+.

    Allan

  • Jeff06Jeff06 Posts: 5Questions: 0Answers: 0

    Thank you for your answer.

    I tried it :

    $('#example').dataTable( {
    "processing": true,
    "serverSide": true,
    "ajax": {
    "url": "my_page.php",
    "data": {
    "country": "EN"
    }
    }
    } );

    It's ok, there is no error and my datatable appears.
    However my dataTable isn't filtered, every lines are displayed.
    How can I filter my request ?
    Thanks in advance.

  • allanallan Posts: 63,290Questions: 1Answers: 10,428 Site admin

    You'd need to modify the code in my_page.php whatever that is to do the filter. In server-side processing the server does all the processing :-).

    Allan

  • Jeff06Jeff06 Posts: 5Questions: 0Answers: 0
    edited October 2014

    I don't understand what I have to add.
    This is the code of "my_page.php" (code obtained from "Server-Side-Processing example") :

    //************************************************************************************
    $table = 'myTable';
     
    $primaryKey = 'id_customer';
     
    $columns = array(
        array( 'db' => 'title',                     'dt' => 0 ),
        array( 'db' => 'message',               'dt' => 1 ),
        array( 'db' => 'dateMessage',       'dt' => 2 ),
        array( 'db' => 'age',                       'dt' => 3 ),
        array( 'db' => 'country',               'dt' => 4 )
     
    );
     
    $sql_details = array(
        'user' => 'root',
        'pass' => '',
        'db'   => 'myDB',
        'host' => 'localhost'
    );
      
    require( 'ssp.class.php' );
    echo json_encode(
        SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns )
    );
    //************************************************************************************
    

    What do I have to add ?
    Thanks in advance.

  • allanallan Posts: 63,290Questions: 1Answers: 10,428 Site admin

    Looks okay to me - but it doesn't appear to be working. A link to the page or a debugger trace might show when is going wrong, although possibly the server-side script might need to be debugged.

    Allan

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    ssp.class.php - which contains the query - is only an example. You need to customise to suit your own requirements.

  • Jeff06Jeff06 Posts: 5Questions: 0Answers: 0

    This is my test site : http://be4gd.net63.net/test_datatables.html

    In this example, given that I write

    "data": {
    "codePays": "FR"
    }

    I expect to have in my datatable only lines with Pays=FR.
    For the moment, all my table is displayed.

    In test_datatables.html, you can see my code for the other pages (in comment).

    Perhaps I have to modify "ssp.class.php" but I don't know what I must change :-(

    Thanks in advance.

  • Jeff06Jeff06 Posts: 5Questions: 0Answers: 0

    No idea ?

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395
    edited October 2014

    In this example, given that I write
    "data": { "codePays": "FR" }
    I expect to have in my datatable only lines with Pays=FR.

    That's not how it works. You need to spend more time with the docs, and look at customising your server-side php.

  • allanallan Posts: 63,290Questions: 1Answers: 10,428 Site admin

    In fairness that isn't documented, as the server-side processing script given is really just an example showing how it could be done using the protocol in the manual.

    It is expected that if you want to do anything beyond the simple behaviour of the default script you would modify it to suit your needs.

    In this case, you would probably modify it around about this point.

    Allan

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    For the sake of clarity, my mentioning the docs was in reference to my quoting of Jeff06's mistaken understanding.

This discussion has been closed.