DataTables stopped working after populating it with alot of data
DataTables stopped working after populating it with alot of data
ChrisF
Posts: 15Questions: 7Answers: 0
I have been using DataTables on my CodeIgniter page and it has been working great with a few data. I used an SQL Query to generate 12 000 Rows and my DataTables stopped working with DataTables warning: table id=usertable - Ajax error. For more information about this error, please see http://datatables.net/tn/7
Ajax is from:
public function vykresy_page() {
$draw = intval($this->input->get("draw"));
$start = intval($this->input->get("start"));
$length = intval($this->input->get("length"));
$vykres = $this->Vykresy_model->get_vykresy2();
$data = array();
foreach ($vykres->result() as $row) {
$sub_array = array();
$zakazkaid = "";
$vykresid = "";
if(strlen($row->ID_zakazka)==1) {
$zakazkaid="000".$row->ID_zakazka;
}
if(strlen($row->ID_zakazka)==2) {
$zakazkaid="00".$row->ID_zakazka;
}
if(strlen($row->ID_zakazka)==3) {
$zakazkaid="0".$row->ID_zakazka;
}
if(strlen($row->Poradie)==1) {
$vykresid="00".$row->Poradie;
}
if(strlen($row->Poradie)==2) {
$vykresid="0".$row->Poradie;
}
if(strlen($row->Poradie)==3) {
$vykresid=$row->Poradie;
}
$sub_array[] = $zakazkaid.'.'.$vykresid;
$sub_array[] = $row->Nazov_vykresu;
$sub_array[] = $row->Pocet_dielov;
$sub_array[] = $row->Nazvy_dielov;
$sub_array[] = $row->Dodavatel;
$sub_array[] = $row->Cena;
$sub_array[] = $row->Mail;
$sub_array[] = $row->Mobil;
$sub_array[] = $row->WWW;
$sub_array[] = $row->Stav_objednavky;
$sub_array[] = $row->Nazov_stavu;
$casy = $this->Vykresy_model->get_casy($row->ID_vykres);
foreach ($casy->result() as $row2) {
$hodiny = intval($row2->Cas / 60);
$minuty = intval($row2->Cas %60);
$sub_array[] = $hodiny;
$sub_array[] = $minuty;
if(!empty($row2->Sekundy)) {
$sub_array[] = $row2->Sekundy;
} else {
$sub_array[] = 0;
}
}
$sub_array[] = '<a type="button" name="attachments" id="'.$row->ID_vykres.'" class="editbutton" href="VHU/index/'.$row->ID_vykres.'">Časy</a>';
$sub_array[] = '<a type="button" name="attachments" id="'.$row->ID_vykres.'" class="editbutton" href="vykresy/upload/'.$row->ID_vykres.'">Prílohy</a>';
$sub_array[] = '<a type="button" name="view" id="'.$row->ID_vykres.'" class="editbutton" href="vykresy/view/'.$row->ID_vykres.'">QR</a>';
$sub_array[] = '<a type="button" name="update" id="'.$row->ID_vykres.'" class="editbutton" href="vykresy/edit/'.$row->ID_vykres.'">Editovať</a>';
$sub_array[] = '<a type="button" name="delete" id="'.$row->ID_vykres.'" class="deletebutton" href="vykresy/delete/'.$row->ID_vykres.'" >Zmazať</a>';
$data[] = $sub_array;
}
$output = array("draw" => $draw,
"recordsTotal" => $vykres->num_rows(),
"recordsFiltered" => $vykres->num_rows(),
"data" => $data);
echo json_encode($output);
exit();
}
Maybe too much data at once? Is it possible to chop it up to smaller ones at times? setting deferRender to true didnt do the trick.
This discussion has been closed.
Answers
The error message includes a link where you will find diagnostic steps.
Yeah I used that but still couldnt fix my problem.
This is the response:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>502 Proxy Error</title>
</head><body>
Proxy Error
The proxy server received an invalid response from an upstream server.
The proxy server could not handle the request GET /index.php/vykresy/vykresy_page.
Reason: Error reading from remote server
</body></html>
I'm guessing too much data at a simple time as you say. Try adding a LIMIT to your SQL query to see if that helps. Beyond that, you'd need to look at the proxy server's settings to see if you can increase the size of the pages it can handle.
Server-side processing is your other option, which splits the data into each display by DataTables and makes an Ajax request for more data on each draw. The disadvantage of course is the extra complexity for the server-side code you'd need to add.
Allan
@allan ,
I have used the code from the example given by you https://datatables.net/examples/data_sources/server_side.html
my datatable would be handling more than 60000, it wont be an issue with displaying the record in the datatable right ?
No,
serverSide
won't be an issue with large datasets - it only returns the data required for each page. @vaishnavkoka , if you have an issue with it, please raise a new forum post, as this is for a different issue (CodeIgniter, custom script, etc.).