Share: Pipeline splice of undefined

Share: Pipeline splice of undefined

skipdevskipdev Posts: 2Questions: 0Answers: 0
edited April 2014 in DataTables 1.9
I use DataTables 1.9.4, Colvis 1.1.0-dev and columnFilter 1.5.6

UPDATE: See my post below (3rd comment)

Recently got issue "splice of undefined" with pipeline around:

[code]json.aaData.splice( 0, iRequestStart-oCache.iCacheLower );
json.aaData.splice( iRequestLength, json.aaData.length );[/code]

I notice that at the same time the issue appear, the range input of columnFilter had value "undefined" because it's invisible before.

Since I'm new to dataTables and not advanced at javascript this is what I do:

Add method below before function fnDataTablesPipeline ( sSource, aoData, fnCallback )
[code]function strpos(haystack, needle, offset) {
// discuss at:
// original by: Kevin van Zonneveld (
// improved by: Onno Marsman
// improved by: Brett Zamir (
// bugfixed by: Daniel Esteban
// example 1: strpos('Kevin van Zonneveld', 'e', 5);
// returns 1: 14

var i = (haystack + '')
.indexOf(needle, (offset || 0));
return i === -1 ? false : i;

[code](aoData[i].value != oCache.lastRequest[i].value)[/code]

[code]if ( (aoData[i].value != oCache.lastRequest[i].value) || (strpos(aoData[i].value, 'undefined') !== false)) [/code]

Basicly the code will catch any "undefined" word and set bNeedServer = true.
This not remove the "undefined" value in input filter, but at least bProcessing isn't stuck and the table show data.

This solve my problem but not sure if this will help others, so I hope anyone will found it usefull.


  • allanallan Posts: 56,851Questions: 1Answers: 9,035 Site admin
    Thanks for sharing with us.

  • skipdevskipdev Posts: 2Questions: 0Answers: 0
    Your welcome Allan..

    My solution above isn't really cut the problem, instead it's raise another issue where changing page is triggering request to server side (no pipeline).

    I found the root of problem and fix my issue.

    ### First Issue

    Uncaught TypeError: Cannot read property 'value' of undefined
    -- at code --> if ( aoData[i].value != oCache.lastRequest[i].value )

    # Issue Cause with columnFilter:
    When page first load, sRangeSeparator is not requested as parameter. But when load another page (pagination), sRangeParameter is requested.

    # Fix
    [code]&& aoData[i].name != "sRangeSeparator"[/code]
    [code]if ( aoData[i].name != "iDisplayStart" && aoData[i].name != "iDisplayLength" && aoData[i].name != "sEcho" && aoData[i].name != "sRangeSeparator" )[/code]

    ### Second Issue

    Uncaught TypeError: Cannot call method 'splice' of undefined
    -- at code --> json.aaData.splice( 0, iRequestStart-oCache.iCacheLower );

    # Issue Cause:
    If we reload the page after several filter, oCache.lastJson is not created.
    Somehow bNeedServer isn't set to true, to request data from server and create oCache.lastJson.

    # Fix
    [code]if (oCache.lastJson === undefined) { bNeedServer = true; }[/code]
    [code]if ( bNeedServer )[/code]

    After reading my first post, its kinda contradictive.
    Maybe just too excited to share them lol.. :p

    I hope this time more make sense and really help other
This discussion has been closed.