Bugfix for fnDataTablesPipeline

Bugfix for fnDataTablesPipeline

SentackSentack Posts: 2Questions: 0Answers: 0
edited April 2011 in Bug reports
Recently, I've been using dataTables in a new project with server side processing. I used the pipeline function provided by the website since it helped with overhead a lot but, we've found a bug in the code dealing with the "ALL" record condition. It would show all but the last record in the set. Provided here is a fix for just the fnDataTablesPipeline function

[code]
function fnDataTablesPipeline ( sSource, aoData, fnCallback ) {
var iPipe = 5; /* Ajust the pipe size */

var bNeedServer = false;
var sEcho = fnGetKey(aoData, "sEcho");
var iRequestStart = fnGetKey(aoData, "iDisplayStart");
var iRequestLength = fnGetKey(aoData, "iDisplayLength");
var iRequestEnd = iRequestStart + iRequestLength;
oCache.iDisplayStart = iRequestStart;

/* outside pipeline? */
if ( oCache.iCacheLower < 0 || iRequestStart < oCache.iCacheLower || iRequestEnd > oCache.iCacheUpper )
{
bNeedServer = true;
}

/* sorting etc changed? */
if ( oCache.lastRequest && !bNeedServer )
{
for( var i=0, iLen=aoData.length ; i= 0 )
{
json.aaData.splice( oCache.iDisplayLength, json.aaData.length );
}

fnCallback(json)
} );
}
else
{
json = jQuery.extend(true, {}, oCache.lastJson);
json.sEcho = sEcho; /* Update the echo for each response */
json.aaData.splice( 0, iRequestStart-oCache.iCacheLower );
if ( iRequestLength >= 0 )
{
json.aaData.splice( iRequestLength, json.aaData.length );
}
fnCallback(json);
return;
}
}
[/code]

A Diff of the change for those interested

[code]
-bash-3.1$ diff fnDataTablesPipeline.org.js fnDataTablesPipeline.new.js
61c61,64
< json.aaData.splice( oCache.iDisplayLength, json.aaData.length );
---
> if ( oCache.iDisplayLength >= 0 )
> {
> json.aaData.splice( oCache.iDisplayLength, json.aaData.length );
> }
71c74,77
< json.aaData.splice( iRequestLength, json.aaData.length );
---
> if ( iRequestLength >= 0 )
> {
> json.aaData.splice( iRequestLength, json.aaData.length );
> }
-bash-3.1$
[/code]
This discussion has been closed.