Server-side processing and parameters
Server-side processing and parameters
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
Use
ajax.data
in DataTables 1.10+.Allan
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.
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
I don't understand what I have to add.
This is the code of "my_page.php" (code obtained from "Server-Side-Processing example") :
What do I have to add ?
Thanks in advance.
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
ssp.class.php - which contains the query - is only an example. You need to customise to suit your own requirements.
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.
No idea ?
That's not how it works. You need to spend more time with the docs, and look at customising your server-side php.
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
For the sake of clarity, my mentioning the docs was in reference to my quoting of Jeff06's mistaken understanding.