Need to display a large amount of data in a DataTable in a Drupal page. I use server side processing. The php file returns json array. It works (but very slow) on up to 2500 records. On more than that the response fails. Also when I add some icons instead of the text links to json array (see php code below) so they are displayed in the table next to the customer's data, the amount of records on which the DataTable works decreases to about 800.
Can it be because of the json array size?
How to display about 5000 records in the DataTable and make sure it still works as data grows? How to optimize the whole thing to speed it up?
JavaScript:
var oTable = $('#mytable').DataTable({
ajax: "ajax/myphp.php?i="+i+"&a=",
scrollY: 600,
scroller: {
loadingIndicator: true
},
paging: false
});
Here is what happens in myphp.php file:
<?php
include '../includes/functions/config.php';
include '../includes/functions/functions.php';
if(isset($_GET)){
$i=$_GET['i'];
$a=$_GET['a'];
}
$output= array();
$sql= "Select * from customers where a= $a and i=$i"; //returns about 2600-5500 records depends on the filtering, takes about 0.0010 seconds. If I limit the query to 2500 everything works fine.
/*
get query results
loop thought the result
for each record
- get first, last name, address, phone, email.
- add few links like View, Edit, Payments, Files
- run 2 small functions with a quick db query in each to get things like
balance
*/
$num= mysql_num_rows($data);
while($row= mysql_fetch_assoc($data)){
//do what I mentioned above
$links.= "<a href='edit_customer.php?id=".$row['id']."'>Edit</a> "; //I add about 5 similar links to each record
$output[]= [$row['Last'], $row['First'], $row['Date'],$row['Phone'], $row['Email'], $links];
}
$json_data = array(
"draw" =>1,
"recordsTotal" => $num,
"recordsFiltered" =>$num,
"data" => $output
);
echo json_encode($json_data);
Thanks!