null bug in _fnDataToSearch
null bug in _fnDataToSearch
SuprF1y
Posts: 2Questions: 0Answers: 0
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
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
This discussion has been closed.
Replies
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
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
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;
}
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