null bug in _fnDataToSearch

null bug in _fnDataToSearch

SuprF1ySuprF1y Posts: 2Questions: 0Answers: 0
edited July 2011 in Bug reports
Hi,
Doing ajax searching I was getting intermittent errors related to returned data being null.
I modified _fnDataToSearch : line 4553 so the null check is the first if rather than the last and this seemed to fix it.
The error message was complaining about sData being null.
Cheers,
(and great plugin btw),
Will

Replies

  • allanallan Posts: 63,689Questions: 1Answers: 10,500 Site admin
    Hi Will,

    Good one! The one thing I would say is that it might be that you actually want a function to operate on null, so it should probably go after the custom function call, but before the built in type options. Could you give me a sample of the JSON data that was showing this up so I can be sure that I fix it properly?

    Thanks,
    Allan
  • SuprF1ySuprF1y Posts: 2Questions: 0Answers: 0
    Hi again,
    So I went back and had another look and it seems little more subtle than I first thought.
    To replicate it I need to have all of the following
    "iDeferLoading" : some vale > than the actual number of rows returned,
    no sType set for my 3rd column def of 4 column defs i.e. the following prevents the bug from manifesting
    "aoColumnDefs" : [
    {"sType": "string", "aTargets" : [ 3 ]}
    }
    all other sTypes don't seem to affect it.
    the bug occurs before the ajax call goes to the server
    I ran the js debugger in firebug and the problem occurs when
    sType != null && SData == null
    The other cases work fine
    if ( sType != null && sData != null ) //ok
    if ( sType == null && sData == null) //ok

    This only occurs on one of my half a dozen datatables. They all use mostly the same codebase serverside and js/wise but there must be something for this particular table that is throwing it off.
    Afraid I don't have any more time to try and debug this. If you want me to do something specific though to test I'll be happy to do it.
    Cheers,
    W

    Some sample json from the problem table

    {"iTotalRecords":11696,"iTotalDisplayRecords":7,"sEcho":5,"aaData":[["Adam De Jong ",null,null,null,"action"],["Adam De Jong ",null,null,null,"action"],["Adam De Jong ",null,null,null,"action"],["Adam De Jong ",null,null,null,"action"],["Adam De Jong ",null,null,null,"action"],["Adam Dujong ",null,null,null,"action"],["Mick Demasi & Adam Dejong ",null,null,null,"action"]]}


    the full js - note commenting out my overriding of fnServerData makes no difference.
    $(document).ready(documentReady);
    function documentReady() {
    register();
    }
    function register() {
    var datatableOpts = {
    // sort first column ascending
    // "aoColumnDefs" : [
    // {"bSortable": false, "aTargets": [ 2 ]}],
    "aLengthMenu" : [ [ 25, 50, 100, -1 ], [ 25, 50, 100, "All" ] ],
    "aaSorting" : [ [ 0, "asc" ] ],
    "bPaginate" : false,
    "bServerSide" : true,
    "iDeferLoading" : 2222,
    "sAjaxSource" : "/realEstateAgents/datatablesCb",
    // global filter
    "oSearch" : {
    "sSearch" : ""
    },
    "aoColumnDefs" : [
    // {"bVisible": false, "aTargets": [ 0 ]},
    // {"sType": "string", "aTargets" : [ 0 ]},
    // {"sType": "string", "aTargets" : [ 1 ]},
    // {"sType": "string", "aTargets" : [ 2 ]},
    // {"sType": "string", "aTargets" : [ 3 ]}
    // {
    // "sType": "string",
    // "bSortable" : false,
    // "aTargets" : [ 4 ]
    // }
    ],
    'sDom' : '<"wrapper"fit>',
    "fnServerData" : function(sSource, aoData, fnCallback) {
    var sSearch = null;
    for ( i=0; i
  • markbmarkb Posts: 1Questions: 0Answers: 0
    edited September 2011
    I think I ran into this same issue on 1.8.2. Not sure if this resolved an underlying issue, but I moved the sData === null up a couple levels, as it did all this stuff then the final check was a null. The filtering seemed to be okay afterwards. Might need to move the null check up one more level in the if block, but not sure what the _oExt routine does.

    function _fnDataToSearch ( sData, sType )
    {
    if ( typeof _oExt.ofnSearch[sType] == "function" )
    {
    return _oExt.ofnSearch[sType]( sData );
    }
    else if ( sData === null )
    {
    return '';
    }
    else if ( sType == "html" )
    {
    return sData.replace(/\n/g," ").replace( /<.*?>/g, "" );
    }
    else if ( typeof sData == "string" )
    {
    return sData.replace(/\n/g," ");
    }
    return sData;
    }
  • allanallan Posts: 63,689Questions: 1Answers: 10,500 Site admin
    Hi markb,

    That's awesome - thanks for the input. I've bookmarked the post to have a proper close look at it and figure out what is going on. Hopefully in the next day or two.

    Regards,
    Allan
This discussion has been closed.