can't make serverSide works
can't make serverSide works
Hello,
I'd like to make my datatable runs with Ajax, but I'm facing a problem.
here is the javascript :
[code]$('.datatable').dataTable({
"bJQueryUI": true,
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "ajax_list_candidats.php",
});[/code]
and my ajax file :
[code]<?php
$str = '{
"aaData":[
[
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8"
],
[
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8"
]
],
"sEcho":"1"
}';
echo $str;
?>[/code]
My table just displays a "Processing popup", but anything more happens.
Where am I mistaken ?
I'd like to make my datatable runs with Ajax, but I'm facing a problem.
here is the javascript :
[code]$('.datatable').dataTable({
"bJQueryUI": true,
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "ajax_list_candidats.php",
});[/code]
and my ajax file :
[code]<?php
$str = '{
"aaData":[
[
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8"
],
[
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8"
]
],
"sEcho":"1"
}';
echo $str;
?>[/code]
My table just displays a "Processing popup", but anything more happens.
Where am I mistaken ?
This discussion has been closed.
Replies
If you want to use server-side processing, then you'll need a slightly more complicated script than that :-). http://datatables.net/usage/server-side
Allan
[code]<?php
$str = '{"aaData":[["1","2","3","4","5","6","7","8"],["1","2","3","4","5","6","7","8"]],"sEcho":"1","iTotalRecords": 2,"iTotalDisplayRecords": 2}';
echo $str;
?>[/code]
same thing, i'm getting stuck to a "Processing" popup, my 2 lines are not pushed into my table. I can't even see the file call in firebug..
I can't figure what's wrong in my javascript.
Allan
My Ajax file is ok, as it loads properly on page load.
Here is my DataTable instanciation :
[code]$('.datatable').dataTable({
"bJQueryUI": true,
"iDisplayLength": 25,
"aLengthMenu": [25, 50, 100, 500],
"sPaginationType": "full_numbers",
"oLanguage": {
"sLengthMenu": "Afficher _MENU_ enregistrements",
"sSearch": "Recherche :",
"sZeroRecords": "Aucune donnée correspondante",
"sInfo": "Affichage de _START_ à _END_ sur _TOTAL_ enregistrements",
"sInfoEmpty": "0 résultats",
"sInfoFiltered": "( total de _MAX_ enregistrements)",
"oPaginate": {
"sFirst": "Début",
"sLast": "Fin",
"sNext": "Suivant",
"sPrevious": "Précédent",
}
},
"aoColumnDefs": [
{ "sType": "string", "aTargets": [ -2 ] }
],
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "ajax_list_candidats.php",
"fnServerData": function ( sSource, aoData, fnCallback ) {
$.ajax( {
"dataType": 'json',
"type": "POST",
"url": sSource,
"data": aoData,
"success": fnCallback
} );
}
});[/code]
It is okay for the first load - but not the second! Have a look at the documentation for server-side processing that I linked to before: http://datatables.net/usage/server-side . sEcho must be echoed back as it is sent (ideally parsed as an integer for security) - not just echoed as '1' - which would cause the problem you are seeing.
Allan