Loading time of the datatable is very slow
Loading time of the datatable is very slow
leningi
Posts: 7Questions: 1Answers: 1
Sorry, my english is bad.
I'm using Xampp and the codeigniter framework.
I have a table with more than three hundred thousand rows and using Server-side processing, however, it takes three minutes to process the table, this is normal?
my JavaScript is:
$(document).ready(function() {
//datatables
$('#tbltecate').DataTable({
"lengthMenu": [ 5, 10, 25, 50, 75, 100 ],
"paging": true,
"deferRender": true,
"responsive": true,
"order": [],
"language": {
"url": "http://cdn.datatables.net/plug-ins/1.10.16/i18n/Spanish.json"
},
"processing": true,
"serverSide": true,
"ajax": {
"url": urlgetdata,
"type": "POST",
"data": function ( data ) {
data.seccion = $('#seccion').val();
data.nombre = $('#nombre').val();
data.domicilio = $('#domicilio').val();
}
},
"columnDefs": [
{
"targets": [ 0 ],
"orderable": false,
},
],
});
$('#btn-filter').click(function() {
table.ajax.reload();
});
$('#btn-reset').click(function(){
$('#form-filter')[0].reset();
table.ajax.reload();
});
});
function reload_table()
{
table.ajax.reload(null,false);
}
function update(id, estatus) {
$.ajax({
url : urlUpdateProm + id + "/" + estatus,
type : "POST",
data : $('#form_prom').serialize(),
dataType : "JSON",
success: function(data) {
if (data.status) {
reload_table();
} else {
alert('Error adding / update data');
}
},
error: function (jqXHR, textStatus, errorThrown) {
alert('Error adding / update data');
}
});
}
Beforehand thank you very much.
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
No - that isn't normal. Have you fully implemented server-side processing?
Is the server only returning 10 records at a time?
Allan
I dont know exactly. I am learning to use datatables
Json return:
recordsFiltered : 324000
recordsTotal : 324000
My controller and model are:
I see the limit there, so yes it looks like it probably is. Are there only ten items in the JSON
data
array? If you link to the page I can check.Allan
The problem is that, I'm on localhost.
But I attached an image.
(I reduced the database to 150000 rows)
It appears that the time taken is in the server-side script. What database library are you using? Is it pulling in everything from the SQL server? Are you able to get it to output the SQL that it is using?
Allan
I use XAMPP (MariaDB, phpMyAdmin)
mysqli_driver.php
That doesn't appear to have worked (the attachment), could you try it with a .txt extension please?
I suspect you'll need to enable PHP tracing (perhaps something like this) to determine why your PHP script is taking so long to execute.
Allan
mysqli_driver.php (txt)
Thanks. Yes, I think you would almost certainly need to use a tracer or profiler in your PHP. I don't immediately see what is wrong with the code there.
Allan
Thank you very much! Allan. I already found the problem.
The problem had to do with the JOIN statement, add LEFT was solved.
In SQL it would be "LEFT JOIN table2 ON table1.column_name = table2.column_name;"
I have several screens with large datatables (up to 10,000 rows). I found the following worked for me (load time for 10,000 rows approx 5 seconds in Chrome)
CSS definition of:
In your WebGrid definition, include the CSS from above:
@GridView.GetHtml(
tableStyle: "table table-striped table-bordered table-responsive table-hover cell-border compact webgrid-table-hidden"...
This hides the table on initial load.
Now in the document.ready jquery, add this:
I found this significantly improves loading times...