Cannot override a default value for aaData
Cannot override a default value for aaData
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]
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]
This discussion has been closed.
Replies
Regards,
Allan