1
0
mirror of https://github.com/DataTables/DataTables.git synced 2025-01-30 23:52:11 +01:00

Fix #39 - null values should also be considered like undefined values when working with nested data and have properties created as needed.

This commit is contained in:
Allan Jardine 2012-08-08 20:16:40 +01:00
parent 0804c50d72
commit fd0e0a42e4
3 changed files with 79 additions and 6 deletions

View File

@ -867,11 +867,11 @@
break;
}
data = data[ a[i] ];
if ( data === undefined )
if ( data === null || data[ a[i] ] === undefined )
{
return undefined;
}
data = data[ a[i] ];
}
}
@ -949,7 +949,7 @@
// If the nested object doesn't currently exist - since we are
// trying to set the value - create it
if ( data[ a[i] ] === undefined )
if ( data[ a[i] ] === null || data[ a[i] ] === undefined )
{
data[ a[i] ] = {};
}

View File

@ -433,11 +433,11 @@ function _fnGetObjectDataFn( mSource )
break;
}
data = data[ a[i] ];
if ( data === undefined )
if ( data === null || data[ a[i] ] === undefined )
{
return undefined;
}
data = data[ a[i] ];
}
}
@ -515,7 +515,7 @@ function _fnSetObjectDataFn( mSource )
// If the nested object doesn't currently exist - since we are
// trying to set the value - create it
if ( data[ a[i] ] === undefined )
if ( data[ a[i] ] === null || data[ a[i] ] === undefined )
{
data[ a[i] ] = {};
}

View File

@ -0,0 +1,73 @@
// DATA_TEMPLATE: empty_table
oTest.fnStart( "39 - nested null values" );
$(document).ready( function () {
var test = false;
$.fn.dataTable.ext.sErrMode = "throw";
oTest.fnTest(
"No default content throws an error",
function () {
try {
$('#example').dataTable( {
"aaData": [
{ "a": "0", "b": {"c": 0} },
{ "a": "1", "b": {"c": 3} },
{ "a": "2", "b": null }
],
"aoColumns": [
{ "mDataProp": "a" },
{ "mDataProp": "b.c" }
]
} );
}
catch(err) {
test = true;
}
},
function () { return test; }
);
oTest.fnTest(
"Table renders",
function () {
oSession.fnRestore();
$('#example').dataTable( {
"aaData": [
{ "a": "0", "b": {"c": 0} },
{ "a": "1", "b": {"c": 3} },
{ "a": "2", "b": null }
],
"aoColumns": [
{ "mDataProp": "a" },
{ "mDataProp": "b.c", "sDefaultContent": "allan" }
]
} );
},
function () { return $('#example tbody td:eq(0)').html() === "0"; }
);
oTest.fnTest(
"Default content applied",
function () {
oSession.fnRestore();
$('#example').dataTable( {
"aaData": [
{ "a": "0", "b": {"c": 0} },
{ "a": "1", "b": {"c": 3} },
{ "a": "2", "b": null }
],
"aoColumns": [
{ "mDataProp": "a" },
{ "mDataProp": "b.c", "sDefaultContent": "allan" }
]
} );
},
function () { return $('#example tbody td:eq(5)').html() === "allan"; }
);
oTest.fnComplete();
} );