From 3464502c06b7b71719549c8e3c0884e2e418ccac Mon Sep 17 00:00:00 2001 From: Allan Jardine Date: Mon, 9 May 2011 19:07:16 +0100 Subject: [PATCH] New: sDefaultContent property for aoColumns / aoColumDefs. This new property allows a default value to be given for a column's data, and will be used whenever a null data source is encountered (this can be because mDataProp is set to null, or because the data source itself is null). In addition to this, when set if the mDataProp value is undefined, the default will be used instead (and no error given). If sDefaultContent is not set (default is null), and the mDataProp value is undefined, an error will be given as it currently is. --- media/js/jquery.dataTables.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/media/js/jquery.dataTables.js b/media/js/jquery.dataTables.js index b640488d..fc29c6d5 100644 --- a/media/js/jquery.dataTables.js +++ b/media/js/jquery.dataTables.js @@ -2539,6 +2539,7 @@ "fnGetData": null, "fnSetData": null, "sSortDataType": 'std', + "sDefaultContent": null, "nTh": nTh ? nTh : document.createElement('th'), "nTf": null }; @@ -2607,6 +2608,7 @@ _fnMap( oCol, oOptions, "mDataProp" ); _fnMap( oCol, oOptions, "asSorting" ); _fnMap( oCol, oOptions, "sSortDataType" ); + _fnMap( oCol, oOptions, "sDefaultContent" ); } /* Cache the data get and set functions for speed */ @@ -6517,16 +6519,23 @@ if ( (sData=oCol.fnGetData( oData )) === undefined ) { - if ( oSettings.iDrawError != oSettings.iDraw ) + if ( oSettings.iDrawError != oSettings.iDraw && oCol.sDefaultContent === null ) { _fnLog( oSettings, 0, "Requested unknown parameter '"+oCol.mDataProp+ "' from the data source for row "+iRow ); oSettings.iDrawError = oSettings.iDraw; - return ''; } + return oCol.sDefaultContent; } - if ( sSpecific == 'display' && sData === null ) { + /* When the data source is null, we can use default column data */ + if ( sData === null && oCol.sDefaultContent !== null ) + { + sData = oCol.sDefaultContent; + } + + if ( sSpecific == 'display' && sData === null ) + { return ''; } return sData; @@ -6562,7 +6571,7 @@ { /* Give an empty string for rendering / sorting etc */ return function (data) { - return ''; + return null; }; } else if ( typeof sSource == 'string' && sSource.indexOf('.') != -1 )