SSP::complex using mysql date function can't render the rows in pages correctly
SSP::complex using mysql date function can't render the rows in pages correctly
EnzoCheng
Posts: 15Questions: 3Answers: 0
Description of problem: SSP is working but when I use date() mysql function, the results returned are all shown on the first page
JavaScript:
let table = $('#salesTable').DataTable({
//responsive: true,
// "sDom": 'Blftip',
// buttons: [
// 'print'
// ],
"deferRender": true,
"aLengthMenu": [
[5, 10, 15, -1],
[5, 10, 15, "All"]
],
"iDisplayLength": 10,
"language": {
search: "Search"
},
"processing": true,
"serverSide": true,
"ajax": {
url:requestSalesTablePath,
type:"POST",
data:{
startDate:"123",
endDate:"123"
},
error:(xhr, error, code)=>{
console.log(JSON.stringify(xhr));
console.log(error);
},
},
});
PHP:
<?php
use App\DataTable\SSP;
include realpath("../../vendor/autoload.php");
use const App\Mysql\DB_HOST;
use const App\Mysql\DB_NAME;
use const App\Mysql\DB_PASSWORD;
use const App\Mysql\DB_USER;
require("C:/xampp/.config.php");
$dbDetails = array (
"host" => DB_HOST,
"user" => DB_USER,
"pass" => DB_PASSWORD,
"db" => DB_NAME
);
if(isset($_POST["startDate"]) && isset($_POST["endDate"])){
$table = "sales";
$primaryKey = "SALES_TRANSNO";
$columns = array(
array("db"=>"SALES_TRANSNO",
"dt"=>"DT_RowId",
'formatter'=>function($d,$row){
return "row_".$d;
}),
array("db"=>"SALES_TRANSNO","dt"=>0),
array("db"=>"SALES_STORE","dt"=>1),
array("db"=>"SALES_STATUS","dt"=>2),
array("db"=>"SALES_DATETIME","dt"=>3,
'formatter' => function($d,$row){
return date('Y-m-d',strtotime($d));
}),
array("db"=>"SALES_NETSALES","dt"=>4),
);
$where = "DATE(SALES_DATETIME) > '2020-09-10';";
echo json_encode(
SSP::complex($_POST,$dbDetails,$table,$primaryKey,$columns,$where)
);
}
53 rows returned are all shown on the first page:
The rows are the same on the fourth page:
This discussion has been closed.
Answers
Are you saying that when you request the data for any page, it's only showing the data from the first page?
Can you link to your page so we can take a look?
Colin
Sorry the website is still under development, it is accessed locally.
I found out that it has nothing to do with mysql date() function. With WHERE clause, if results are more than iDisplayLength, all the results will be rendered on the first page of the table
This table says Showing 1 to 10 of 14 entries (filtered from 17 total entries)
but all 14 records are shown, not just 10.
Searching is functioning well.
Can you post the JSON returned from the server when that happens, please.
Colin
JSON returned:
Yep - there's 14 rows in there! The server should be returning the number of records requested, which in your case would be 10.
Colin
Why is this happening? I copied the SSP class from github. Any idea?
Can you use the debugger to give me a trace please - click the Upload button and then let me know what the debug code is.
Or even better would be a link to a test case showing the issue.
Thanks,
Allan
Hi Allan, the code is ulifam, https://debug.datatables.net/ulifam
Thanks!
In your PHP above you have:
but those two parameters are not being send to the server. So I'm guessing it is dropping into an
else
which is not shown in the code above? Can you show the full PHP file please?Allan
I did send the parameters via the JavaScript I posted here
Now I put an esle condition in this PHP:
The datatable is functioning well without WHERE clause.
Is it because of there are multiple primary keys in this database table?
That doesn't match what your debug trace shows though:
There are no
startDate
andendDate
parameters being sent in the request in the trace you sent me above.Allan
Hi allan, the correct debug code for this table is ijihol, https://debug.datatables.net/ijihol
Thank you. That looks like it should be working to me - I don't immediately see anything that would be causing the issue you are seeing.
Can you update to DataTables 1.10.22 (from 1.10.16) please? I don't think that will make a difference though. Could you also link to a page showing the issue so I can trace it through?
Thanks,
Allan
Hi Allan, this is the link testing.qubeorder.com.my/demo/demo.php
Thank you. Can you also show me
queryTesting.php
? I see you are passinganything: '123'
as the data. I don't see anything in the above PHP that is handling that.Allan
Hi Allan, this is queryTesting.php:
the front-end part:
Are you using this version of the script?
I've just tried my basic example with:
and it appears to work just fine.
I'd suggest that if it isn't an out of date script, then you need to echo out the SQL that is constructed in
complex
and see what is wrong with that.Allan
Hi Allan,
the SQL I get looks like this:
SSP:
The result looks like this:
Can you echo out the SQL that is generated here please?
Allan
Hi Allan,
query:
The query is logged to console and can be seen here testing.qubeorder.com.my/demo/demo.php
You've got the DataTable commented out and a plain jQuery Ajax request being made to the server without any of the parameters that DataTables would be sending - such as the page length:
Can you remove the
$.ajax
call and uncomment the DataTable initialisation please?Allan
Hi Allan,
I have removed the ajax call and uncommented the DataTable initialization.