Time load page slow
Time load page slow
Hello,
sorry for my english language...i have a datatable page with 13560 rows. Problem is when i load the page, around 3-4 min and just with google chrome (IE and Firefox crash). I'm using serverside processing but i don't find difference when i use it. I show the code, if someone knows what i have to change or how can i solve this problem i will appreciate.
Code datatable
[code]
var oTable = $('#example').dataTable({
"sPaginationType": "full_numbers",
"bServerSide": true,
"sAjaxSource": "server_processing.php"
})
.columnFilter({sPlaceHolder: "head:after",
aoColumns: [
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
]
}) ;
[/code]
Code serverside processing
[code]
<?php
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Easy set variables
*/
/* Array of database columns which should be read and sent back to DataTables. Use a space where
* you want to insert a non-database field (for example a counter or static image)
*/
$aColumns = array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','ab','bc','cd','de','ef','fg','gh','hi','ij','jk','kl','lm','mn','no','op','pq','qr','rs','tu','vn','vz');
/* Indexed column (used for fast and accurate table cardinality) */
$sIndexColumn = "a";
/* DB table to use */
$sTable = "factura";
/* Database connection information */
$gaSql['user'] = "root";
$gaSql['password'] = "";
$gaSql['db'] = "contabilidad";
$gaSql['server'] = "localhost";
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* If you just want to use the basic configuration for DataTables with PHP server-side, there is
* no need to edit below this line
*/
/*
* MySQL connection
*/
$gaSql['link'] = mysql_pconnect( $gaSql['server'], $gaSql['user'], $gaSql['password'] ) or
die( 'Could not open connection to server' );
mysql_select_db( $gaSql['db'], $gaSql['link'] ) or
die( 'Could not select database '. $gaSql['db'] );
/*
* Paging
*/
$sLimit = "";
if ( isset( $_GET['iDisplayStart'] ) && $_GET['iDisplayLength'] != '-1' )
{
$sLimit = "LIMIT ".mysql_real_escape_string( $_GET['iDisplayStart'] ).", ".
mysql_real_escape_string( $_GET['iDisplayLength'] );
}
/*
* Ordering
*/
$sOrder = "";
if ( isset( $_GET['iSortCol_0'] ) )
{
$sOrder = "ORDER BY ";
for ( $i=0 ; $i $iFilteredTotal,
"aaData" => array()
);
while ( $aRow = mysql_fetch_array( $rResult ) )
{
$row = array();
for ( $i=0 ; $i
[/code]
[code] {"sEcho":1,"iTotalRecords":"4676","iTotalDisplayRecords":"4676","aaData":[["655"....]]} [/code]
sorry for my english language...i have a datatable page with 13560 rows. Problem is when i load the page, around 3-4 min and just with google chrome (IE and Firefox crash). I'm using serverside processing but i don't find difference when i use it. I show the code, if someone knows what i have to change or how can i solve this problem i will appreciate.
Code datatable
[code]
var oTable = $('#example').dataTable({
"sPaginationType": "full_numbers",
"bServerSide": true,
"sAjaxSource": "server_processing.php"
})
.columnFilter({sPlaceHolder: "head:after",
aoColumns: [
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
{ type: "text"},
]
}) ;
[/code]
Code serverside processing
[code]
<?php
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Easy set variables
*/
/* Array of database columns which should be read and sent back to DataTables. Use a space where
* you want to insert a non-database field (for example a counter or static image)
*/
$aColumns = array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','ab','bc','cd','de','ef','fg','gh','hi','ij','jk','kl','lm','mn','no','op','pq','qr','rs','tu','vn','vz');
/* Indexed column (used for fast and accurate table cardinality) */
$sIndexColumn = "a";
/* DB table to use */
$sTable = "factura";
/* Database connection information */
$gaSql['user'] = "root";
$gaSql['password'] = "";
$gaSql['db'] = "contabilidad";
$gaSql['server'] = "localhost";
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* If you just want to use the basic configuration for DataTables with PHP server-side, there is
* no need to edit below this line
*/
/*
* MySQL connection
*/
$gaSql['link'] = mysql_pconnect( $gaSql['server'], $gaSql['user'], $gaSql['password'] ) or
die( 'Could not open connection to server' );
mysql_select_db( $gaSql['db'], $gaSql['link'] ) or
die( 'Could not select database '. $gaSql['db'] );
/*
* Paging
*/
$sLimit = "";
if ( isset( $_GET['iDisplayStart'] ) && $_GET['iDisplayLength'] != '-1' )
{
$sLimit = "LIMIT ".mysql_real_escape_string( $_GET['iDisplayStart'] ).", ".
mysql_real_escape_string( $_GET['iDisplayLength'] );
}
/*
* Ordering
*/
$sOrder = "";
if ( isset( $_GET['iSortCol_0'] ) )
{
$sOrder = "ORDER BY ";
for ( $i=0 ; $i $iFilteredTotal,
"aaData" => array()
);
while ( $aRow = mysql_fetch_array( $rResult ) )
{
$row = array();
for ( $i=0 ; $i
[/code]
[code] {"sEcho":1,"iTotalRecords":"4676","iTotalDisplayRecords":"4676","aaData":[["655"....]]} [/code]
This discussion has been closed.
Replies
Allan
[code] {"sEcho":1,"iTotalRecords":"3519","iTotalDisplayRecords":"3519","aaData":[/code]
I run the page localhost, i looking for link a test page.
Thanks.
See the server-side processing documentation here: http://datatables.net/usage/server-side
Allan
> "iTotalDisplayRecords":"3519" - i think this is not ok.
Its not - it shouldn't be a string.
I use datatable with Xampp and localhost, when i enter the page there is a message "trasferring data from localhost..." when the message dissapear datatable is loaded and run very good. I dont know if someone have used big tables with localhost, can be the long time used to load the page due to use localhost?
I use a 10 million row database on localhost and it runs within 300mS. So there shouldn't be an issue there.
Allan
i solve the problem, it was a while {} inside the table, it loads all data in an array....i have been two weeks with this problem.
Now i have other problem, i know is not a problem of datatable. Last column is an image to open an XML file tahn contains data of the row. In the row there is a column with a unique code, name of the file is this code.
I have used jasonp with this code to insert static image:
[code]$row[] = "";[/code]
Function openxml require the name of the file (unique code, value of a column). I dont know how indicate this value.
1. Modify the HTML you are generating to put the id in there. Since you are generating the HTML, I guess you can just put the id straight in there.
2. Attach an event to the image which will read the data from the row and call the function as needed.
Allan
http://datatables.net/release-datatables/examples/server_side/select_rows.html
[code] /* Click event handler */ $('#example tbody tr').live('click', function () { var id = this.id; var index = jQuery.inArray(id, aSelected); if ( index === -1 ) { aSelected.push( id ); } else { aSelected.splice( index, 1 ); } $(this).toggleClass('row_selected'); } ); [/code]
Allan