Problem with server-side processing
Problem with server-side processing
Kenshin83
Posts: 9Questions: 0Answers: 0
Hello,
I've got a problem when I'm trying to make my datatable with a JSON File...
See my HTML code below :
[code]
Extraction des users avec liste des droits
$(document).ready(function() {
$('#tab_droits').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "recup_Users.php"
} );
} );
LOGON
NOM
DATE MODIFICATION
LIRECL
Loading data from server
LOGON
NOM
DATE MODIFICATION
LIRECL
[/code]
There is nothing that change in the page... There is diplayed "Processing..." at the top of it, but no data to appears...
My Json file given by "recup_Users.php", seems correct to me also :
[code]
{"sEcho":0,"iTotalRecords":20,"iTotalDisplayRecords":20,"aaData":[["00460","LANG","050628","0"],["0587","CURELLI","051027","0"],["0968","VISCO","051027","0"],["1499","DERVAULT","051027","0"],["1698","KAMRAOUI","060209","0"],["1750","POULAIN","060411","0"],["2085","ANDRIEUX","051027","0"],["2237","BONNEHON","051027","0"],["2851","SUDRE","050812","0"],["3035","DAVID","050525","0"],["3045","SOULA","060308","0"],["3081","MAILLOCHON","050525","0"],["3167","ROBERT","051027","0"],["3489","COSTES","050628","0"],["4461","MARCON","050923","0"],["4462","BEAU","060209","0"],["4849","AUZEMARIE","051019","0"],["5242","CROUAU","060209","0"],["58F","GALEY","110420","0"],["6083","LAVIOLETTE","060120","0"]]}
[/code]
I have no Javascript Error (I tried with a inexistant php file, and I've got an error, so the HTML see the php file)
I'm pretty sure I'm missing an obvious thing... But what ?
Thank you by advance for your help ! I'm looking for few hours...
And sorry for my english (I'm a french developper).
I've got a problem when I'm trying to make my datatable with a JSON File...
See my HTML code below :
[code]
Extraction des users avec liste des droits
$(document).ready(function() {
$('#tab_droits').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "recup_Users.php"
} );
} );
LOGON
NOM
DATE MODIFICATION
LIRECL
Loading data from server
LOGON
NOM
DATE MODIFICATION
LIRECL
[/code]
There is nothing that change in the page... There is diplayed "Processing..." at the top of it, but no data to appears...
My Json file given by "recup_Users.php", seems correct to me also :
[code]
{"sEcho":0,"iTotalRecords":20,"iTotalDisplayRecords":20,"aaData":[["00460","LANG","050628","0"],["0587","CURELLI","051027","0"],["0968","VISCO","051027","0"],["1499","DERVAULT","051027","0"],["1698","KAMRAOUI","060209","0"],["1750","POULAIN","060411","0"],["2085","ANDRIEUX","051027","0"],["2237","BONNEHON","051027","0"],["2851","SUDRE","050812","0"],["3035","DAVID","050525","0"],["3045","SOULA","060308","0"],["3081","MAILLOCHON","050525","0"],["3167","ROBERT","051027","0"],["3489","COSTES","050628","0"],["4461","MARCON","050923","0"],["4462","BEAU","060209","0"],["4849","AUZEMARIE","051019","0"],["5242","CROUAU","060209","0"],["58F","GALEY","110420","0"],["6083","LAVIOLETTE","060120","0"]]}
[/code]
I have no Javascript Error (I tried with a inexistant php file, and I've got an error, so the HTML see the php file)
I'm pretty sure I'm missing an obvious thing... But what ?
Thank you by advance for your help ! I'm looking for few hours...
And sorry for my english (I'm a french developper).
This discussion has been closed.
Replies
sEcho should never be 0!
From the documentation ( http://datatables.net/usage/server-side ):
> An unaltered copy of sEcho sent from the client side. This parameter will change with each draw (it is basically a draw count) - so it is important that this is implemented. Note that it strongly recommended for security reasons that you 'cast' this parameter to an integer in order to prevent Cross Site Scripting (XSS) attacks.
Allan
In this topic : http://datatables.net/forums/discussion/2087/secho-the-mystery-variable-/p1
there isn't mentionned that sEcho should never be 0 :(
So if it not could be 0, what I am supposed to put in this parameter ?
I don't send any value in the client side, so intval($_GET['sEcho']) return 0... Am I wrong, and I must specify a value somewhere ?
Or I put a random value, except 0 in my JSON ?
Thanks for the answer ! And thanks by advance for the next one !
And I didn't say in my firt post, but DataTables is a very great job ! Very helpfull.
As the documentation says, simply return the value sent by the client.
> I don't send any value in the client side, so intval($_GET['sEcho']) return 0... Am I wrong, and I must specify a value somewhere ?
Do you actually have server-side processing enabled?
Can you please link to a test page showing the problem, as required in the forum rules.
Allan
Unfortunatly, no... I have not web space, and it is for a job's project, so everything is in a local network :(
As already said, in my client side, I just have what I put above, so for the javascript :
[quote]
$(document).ready(function() {
$('#tab_droits').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "recup_Users.php"
} );
} );
[/quote]
If I well understood, I am supposed to send the sEcho value ? But in all examples that I saw, I didn't see that. Preciselly in this page : http://datatables.net/examples/data_sources/server_side.html
So, I'm doing the same thing, with a correct JSON I think. (see above again)
And nothing happen on the page... Still "processing..."
Thank you again for your help.
And now, my datas appears on the client side.
But I have all datas, for example, with 20 rows you can see here what happen : http://imagik.fr/view-rl/72117
Normally I should have the 10 first rows, and when I click on a column, the sort doesn't work, when I click on "Next", I have "Processing..." that appears at the top of the page, but nothing happen then !
Once again, my JSON :
[code]
{"sEcho":1,"iTotalRecords":20,"iTotalDisplayRecords":20,"aaData":[["00460","LANG","050628","0"],["0587","CURELLI","051027","0"],["0968","VISCO","051027","0"],["1499","DERVAULT","051027","0"],["1698","KAMRAOUI","060209","0"],["1750","POULAIN","060411","0"],["2085","ANDRIEUX","051027","0"],["2237","BONNEHON","051027","0"],["2851","SUDRE","050812","0"],["3035","DAVID","050525","0"],["3045","SOULA","060308","0"],["3081","MAILLOCHON","050525","0"],["3167","ROBERT","051027","0"],["3489","COSTES","050628","0"],["4461","MARCON","050923","0"],["4462","BEAU","060209","0"],["4849","AUZEMARIE","051019","0"],["5242","CROUAU","060209","0"],["58F","GALEY","110420","0"],["6083","LAVIOLETTE","060120","0"]]}[/code]
Please do you have an idea ?
If you use server-side processing then yes. The example you link to does use it, although it is easier to see in this example: http://datatables.net/release-datatables/examples/server_side/server_side.html .
> Ok, this morning I tried to put a value to sEcho in the server side ("sEcho" -> 1)
It is only 1 on the first draw. I linked to the documentation and quoted it. I'm not sure how I can make this clearer.
From the documentation (again) - http://datatables.net/usage/server-side ) :
> An unaltered copy of sEcho sent from the client side. This parameter will change with each draw
Allan
And this time it's working better (but it's not completely working yet)... I supposed I made a mistake when I typed the name of variable...
But I'v still have a problem !
The datatable display always all rows, but I looked again your example, and I'm thinking I doesn't use the server-side processing as excepted... I don't verify values that the client sent to server !
In my case I don't treat datas from a database, but from a big txt file ! Do you have an example of this kind of treatment ?
Thank you for your patience, things begin to be clearer !
[code]"iDisplayLength": n // where n is the number of rows you wish to display.... [/code]
I put the content of my txt file in a multi-dimensionnal array and I will try to implement sort... I think it will be a little more difficult, preciselly for date field...
Datatables is well documented :P
http://datatables.net/release-datatables/examples/basic_init/table_sorting.html
But normally, I should succed !
We had no idea you were doing that. This is why it is so important to post test cases - otherwise we are just guessing and taking up everyone's time.
Unless you are using 50'000+ rows, I would very much recommend using client-side processing. If you are using more than 50k rows, then doing it without a database is going to be a performance nightmare.
Allan
I have a little more than 7k rows, and 8 columns. At the beginning I was trying to use client-side processing, but it took a half-minute on chrome, and on IE8 it doesn't load... I must kill the process after several minutes...
But one chrome, once loaded it is great !
If you have the solution to improve performance, and to make work on IE8, I'm taking ! I made some researches and I found the server-side processing was the best solution for me, but with what you say, I suppose I'm wrong, once again...
I put my code of client-side processing, if you want (I'm sorry but for the moment, I didn't put comments... But I think it is simple) :
[code]
Extraction des users avec liste des droits
jQuery.extend( jQuery.fn.dataTableExt.oSort, {
"date-uk-pre": function ( a ) {
var ukDatea = a.split('-');
return (ukDatea[2] + ukDatea[1] + ukDatea[0]) * 1;
},
"date-uk-asc": function ( a, b ) {
return ((a < b) ? -1 : ((a > b) ? 1 : 0));
},
"date-uk-desc": function ( a, b ) {
return ((a < b) ? 1 : ((a > b) ? -1 : 0));
}
} );
jQuery.extend( jQuery.fn.dataTableExt.oSort, {
"num-html-pre": function ( a ) {
var x = String(a).replace( /<[\s\S]*?>/g, "" );
return parseFloat( x );
},
"num-html-asc": function ( a, b ) {
return ((a < b) ? -1 : ((a > b) ? 1 : 0));
},
"num-html-desc": function ( a, b ) {
return ((a < b) ? 1 : ((a > b) ? -1 : 0));
}
} );
$(document).ready(function() {
$('#tab_droits').dataTable({
"sPaginationType": "full_numbers",
"aLengthMenu": [[25, 50, 75, -1], [25, 50, 75, "All"]],
"iDisplayLength": 25,
"aoColumns" : [
null,
null,
null,
{ "sType": 'num-html' },
{ "sType": 'num-html' },
{ "sType": 'num-html' },
{ "sType": 'num-html' },
{ "sType": 'date-uk' }
]
});
});
<?php
# Enable Error Reporting and Display:
error_reporting(E_ERROR | E_WARNING);
ini_set('display_errors', 1);
include ("/include/fonctions.php");
date_default_timezone_set('Europe/Paris');
$fic_droits="\\\\fr-vfiler022\\pc_idob_monitoring\\accessibility\\liste_droits_users.txt";
$fic=fopen($fic_droits,"r");
if ($fic)
{
?>
LOGON
NOM
PRENOM
LIRECL
ECRIRECL
INTEGRCL
AUTRE
DATE MODIFICATION
LOGON
NOM
PRENOM
LIRECL
ECRIRECL
INTEGRCL
AUTRE
DATE MODIFICATION
<?php
$i=0;
while(!feof($fic))
{
$ligne=explode(':',fgets($fic));
if (!empty($ligne[0]))
{
$lirecl = $ligne[4]+$ligne[8]+$ligne[12];
$ecrirecl = $ligne[5]+$ligne[9]+$ligne[13];
$integrcl = $ligne[6]+$ligne[10]+$ligne[14];
$autre = $ligne[7]+$ligne[11]+$ligne[15];
$date_int = DateTime::createFromFormat('ymd', $ligne[3]);
$date = $date_int->format('d-m-Y');
echo "".$ligne[0]."".$ligne[1]."".$ligne[2]."
".$lirecl."Phenix01 : ".$ligne[4]."
Phenix05 : ".$ligne[8]."
Phenix06 : ".$ligne[12]."
".$ecrirecl."Phenix01 : ".$ligne[5]."
Phenix05 : ".$ligne[9]."
Phenix06 : ".$ligne[13]."
".$integrcl."Phenix01 : ".$ligne[6]."
Phenix05 : ".$ligne[10]."
Phenix06 : ".$ligne[14]."
".$autre."Phenix01 : ".$ligne[7]."
Phenix05 : ".$ligne[11]."
Phenix06 : ".$ligne[15]."
".$date."";
$i++;
}
}
echo"";
}
else
{
echo "Impossible d'ouvrir le fichier ".$fic_droits;
}
?>
[/code]
edit : I don't know what is the problem with the code balise... I'm sorry...
Try to generate it just with php and html ! and tell us if it works
I understood why do you mean by "client-side processing" Allan ! I make it, and it is working !!!
It is ok on IE8 also ! Just a last question (normally) what is the css class used to have the "Processing..." in the middle of the table ! It is pretty in your examples !
Thank you LordMouss also of course !
The processing display is controlled by this in the CSS: https://github.com/DataTables/DataTables/blob/1_9/media/css/jquery.dataTables.css#L174
Allan