Cannot override a default value for aaData

Cannot override a default value for aaData

timtuckertimtucker Posts: 48Questions: 0Answers: 0
edited August 2012 in General
Up until now I've been using aaData as the data source for all my tables.

I just came across an instance where it would make sense to use a DOM-based source, but came across a small problem.

It would appear that if I override the value in the defaults and set aaData to an empty array, I cannot "unset" it to null.

Here's a quick example of what I'm talking about -- the default gets set to [] and the options attempt to set the value to null, but the override gets ignored:
live.datatables.net/ohoyib/

Looking at the code for 1.9.2, it looks like this is a case where _fnExtend isn't coping well when the default value is an array and the overriding value is null.

I was able to get the behavior I was expecting by changing the following from:
[code]
if ( oExtender.hasOwnProperty(prop) )
{
if ( typeof oInit[prop] === 'object' && $.isArray(oExtender[prop]) === false )
{
$.extend( true, oOut[prop], oExtender[prop] );
}
else
{
oOut[prop] = oExtender[prop];
}
}
[/code]

to:
[code]
if ( oExtender.hasOwnProperty(prop) )
{
if ( oExtender[prop] !== null && typeof oInit[prop] === 'object' && $.isArray(oExtender[prop]) === false )
{
$.extend( true, oOut[prop], oExtender[prop] );
}
else
{
oOut[prop] = oExtender[prop];
}
}
[/code]

Replies

  • allanallan Posts: 63,541Questions: 1Answers: 10,476 Site admin
    Fantastic - thanks for bringing this up and for the fix :-). I've just committed it and your example on the live site now works :-). This will be in DataTables 1.9.3.

    Regards,
    Allan
This discussion has been closed.