From 468390c337caa62f387bc15c5bc54c0313c99093 Mon Sep 17 00:00:00 2001 From: Allan Jardine Date: Wed, 1 Feb 2012 08:16:49 +0000 Subject: [PATCH] Fix: When mDataProp was used to get a nested object, but a parent object didn't exist it would throw an unrecoverable error. With this change the behaviour matches that of single level data whereby if data cannot be found, at any level, then undefined is returned from the data get object. This means that if sDefaultContent is defined then that will be used instead, and if not defined an error will still be given (although this one under DataTables' control). Dev: Removed the "fast lookup" function for data get and set as they weren't really that useful in terms of speed and would require more code to be added to copy with the above change to the error handling for missing objects. Smaller code and virtually no difference in speed. Sold. --- media/js/jquery.dataTables.js | 70 ++--- media/src/core/core.data.js | 70 ++--- .../6872-default-content-missing-props.js | 285 ++++++++++++++++++ media/unit_testing/unit_test.js | 6 +- 4 files changed, 334 insertions(+), 97 deletions(-) create mode 100644 media/unit_testing/tests_onhold/2_js/6872-default-content-missing-props.js diff --git a/media/js/jquery.dataTables.js b/media/js/jquery.dataTables.js index 14ba3a8c..6d9a087b 100644 --- a/media/js/jquery.dataTables.js +++ b/media/js/jquery.dataTables.js @@ -805,33 +805,24 @@ } else if ( typeof mSource === 'string' && mSource.indexOf('.') != -1 ) { - /* If there is a . in the source string then the data source is in a nested object - * we provide two 'quick' functions for the look up to speed up the most common - * operation, and a generalised one for when it is needed + /* If there is a . in the source string then the data source is in a + * nested object so we loop over the data for each level to get the next + * level down. On each loop we test for undefined, and if found immediatly + * return. This allows entire objects to be missing and sDefaultContent to + * be used if defined, rather than throwing an error */ var a = mSource.split('.'); - if ( a.length == 2 ) - { - return function (data, type) { - return data[ a[0] ][ a[1] ]; - }; - } - else if ( a.length == 3 ) - { - return function (data, type) { - return data[ a[0] ][ a[1] ][ a[2] ]; - }; - } - else - { - return function (data, type) { - for ( var i=0, iLen=a.length ; i 0 ) { - $.fn.dataTableSettings[0].oInstance.fnDestroy(); + try { + $.fn.dataTableSettings[0].oInstance.fnDestroy(); + } catch (e) { + $.fn.dataTableSettings.splice( 0, 1 ); + } } //$.fn.dataTableSettings.splice( 0, $.fn.dataTableSettings.length ); var nDemo = document.getElementById('demo');