Long running script problem
Long running script problem
I was having the long running script problem, we have grids with over 10k records (13k is our test case).
I modified the code in the this.each closure to use batch processing. I inhibit drawing of the grid on the page until the load is complete using the callback function. The page uses a looping setTimeout and draws the grid after the callback is called (using a boolean variable).
What I did was move some code into finishLoading() that was at the bottom of the each closure. Then I added the batch processing code. The finishLoading was needed because if that code was called after the 1st batch was processed the grid thought there were only X records, the size of the batch.
function finishLoading()
{
/* Copy the data index array */
oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
/* Initialisation complete - table can be drawn */
oSettings.bInitialised = true;
/* Check if we need to initialise the table (it might not have been handed off to the
* language processor)
*/
if ( bInitHandedOff === false )
{
_fnInitialise( oSettings );
}
}
/* Check if there is data passing into the constructor */
if ( bUsePassedData )
{
//_fnAddData( oSettings, oInit.aaData[ i ] );
//Replacing this long running loop with batch process
function processRows (batchSize) {
var self = this;
var dataIndex = 0;
var doOneBatch = function() {
var c = 0;
while(c < batchSize && dataIndex < oInit.aaData.length) {
_fnAddData( oSettings, oInit.aaData[ dataIndex ] );
c++;
dataIndex++;
}
if (dataIndex < oInit.aaData.length) {
setTimeout(doOneBatch, 1);
}
else
{
if (typeof oInit.fnLoadCallBack == 'function')
{
finishLoading();
oInit.fnLoadCallBack();
}
}
};
doOneBatch(dataIndex);
return;
}
processRows(1000);
}
else
{
/* Grab the data from the page */
_fnGatherData( oSettings );
finishLoading();
}
I modified the code in the this.each closure to use batch processing. I inhibit drawing of the grid on the page until the load is complete using the callback function. The page uses a looping setTimeout and draws the grid after the callback is called (using a boolean variable).
What I did was move some code into finishLoading() that was at the bottom of the each closure. Then I added the batch processing code. The finishLoading was needed because if that code was called after the 1st batch was processed the grid thought there were only X records, the size of the batch.
function finishLoading()
{
/* Copy the data index array */
oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
/* Initialisation complete - table can be drawn */
oSettings.bInitialised = true;
/* Check if we need to initialise the table (it might not have been handed off to the
* language processor)
*/
if ( bInitHandedOff === false )
{
_fnInitialise( oSettings );
}
}
/* Check if there is data passing into the constructor */
if ( bUsePassedData )
{
//_fnAddData( oSettings, oInit.aaData[ i ] );
//Replacing this long running loop with batch process
function processRows (batchSize) {
var self = this;
var dataIndex = 0;
var doOneBatch = function() {
var c = 0;
while(c < batchSize && dataIndex < oInit.aaData.length) {
_fnAddData( oSettings, oInit.aaData[ dataIndex ] );
c++;
dataIndex++;
}
if (dataIndex < oInit.aaData.length) {
setTimeout(doOneBatch, 1);
}
else
{
if (typeof oInit.fnLoadCallBack == 'function')
{
finishLoading();
oInit.fnLoadCallBack();
}
}
};
doOneBatch(dataIndex);
return;
}
processRows(1000);
}
else
{
/* Grab the data from the page */
_fnGatherData( oSettings );
finishLoading();
}
This discussion has been closed.