diff --git a/js/core/core.ajax.js b/js/core/core.ajax.js index 60d7f16eb..54382d63a 100644 --- a/js/core/core.ajax.js +++ b/js/core/core.ajax.js @@ -340,6 +340,6 @@ function _fnAjaxDataSrc ( oSettings, json ) } return dataSrc !== "" ? - _fnGetObjectDataFn( dataSrc )( json ) : + _fnGetObjectDataFn( dataSrc, oSettings )( json ) : json; } diff --git a/js/core/core.columns.js b/js/core/core.columns.js index 14b80cf13..e256ba4d6 100644 --- a/js/core/core.columns.js +++ b/js/core/core.columns.js @@ -97,8 +97,8 @@ function _fnColumnOptions( oSettings, iCol, oOptions ) /* Cache the data get and set functions for speed */ var mDataSrc = oCol.mData; - var mData = _fnGetObjectDataFn( mDataSrc ); - var mRender = oCol.mRender ? _fnGetObjectDataFn( oCol.mRender ) : null; + var mData = _fnGetObjectDataFn( mDataSrc, oSettings ); + var mRender = oCol.mRender ? _fnGetObjectDataFn( oCol.mRender, oSettings ) : null; var attrTest = function( src ) { return typeof src === 'string' && src.indexOf('@') !== -1; @@ -111,7 +111,7 @@ function _fnColumnOptions( oSettings, iCol, oOptions ) var innerData = mData( rowData, type, undefined, meta ); return mRender && type ? - mRender( innerData, type, rowData, meta ) : + mRender.call( this, innerData, type, rowData, meta ) : innerData; }; oCol.fnSetData = function ( rowData, val, meta ) { diff --git a/js/core/core.constructor.js b/js/core/core.constructor.js index bf4567c73..0cdae7345 100644 --- a/js/core/core.constructor.js +++ b/js/core/core.constructor.js @@ -142,6 +142,7 @@ _fnMap( oSettings, oInit, [ "fnStateLoadCallback", "fnStateSaveCallback", "renderer", + "newCellRender", "searchDelay", [ "iCookieDuration", "iStateDuration" ], // backwards compat [ "oSearch", "oPreviousSearch" ], diff --git a/js/core/core.data.js b/js/core/core.data.js index 72c6275f2..1f40772d3 100644 --- a/js/core/core.data.js +++ b/js/core/core.data.js @@ -117,11 +117,23 @@ function _fnGetCellData( settings, rowIdx, colIdx, type ) var col = settings.aoColumns[colIdx]; var rowData = settings.aoData[rowIdx]._aData; var defaultContent = col.sDefaultContent; - var cellData = col.fnGetData( rowData, type, { + var meta = { settings: settings, - row: rowIdx, - col: colIdx - } ); + row: rowIdx, + col: colIdx + }; + var cellData = col.fnGetData.call(this, rowData, type, meta); + + //compatability stuff + if( type === 'display' ) { + if(cellData === undefined) { + //default behaviour with newCellRender, nothting to do here... + return; + } else { + //compatability: set node content to return value, if there is one + this.innerHTML = cellData; + } + } if ( cellData === undefined ) { if ( settings.iDrawError != draw && defaultContent === null ) { @@ -143,7 +155,7 @@ function _fnGetCellData( settings, rowIdx, colIdx, type ) return cellData.call( rowData ); } - if ( cellData === null && type == 'display' ) { + if ( cellData === null && ( type === 'display' || type === 'adjust' ) ) { return ''; } return cellData; @@ -192,10 +204,11 @@ function _fnSplitObjNotation( str ) * Return a function that can be used to get data from a source object, taking * into account the ability to use nested objects as a source * @param {string|int|function} mSource The data source for the object + * @param {object} oSettings dataTables settings object * @returns {function} Data get function * @memberof DataTable#oApi */ -function _fnGetObjectDataFn( mSource ) +function _fnGetObjectDataFn( mSource, oSettings ) { if ( $.isPlainObject( mSource ) ) { @@ -203,14 +216,21 @@ function _fnGetObjectDataFn( mSource ) var o = {}; $.each( mSource, function (key, val) { if ( val ) { - o[key] = _fnGetObjectDataFn( val ); + o[key] = _fnGetObjectDataFn( val, oSettings ); } } ); + //backwards compatibility + if(oSettings === undefined && oSettings.newCellRender !== true) { + if(o.adjust === undefined && o.display !== undefined) { + o.adjust = o.display; + } + } + return function (data, type, row, meta) { var t = o[type] || o._; return t !== undefined ? - t(data, type, row, meta) : + t.call(this, data, type, row, meta) : data; }; } @@ -223,9 +243,16 @@ function _fnGetObjectDataFn( mSource ) } else if ( typeof mSource === 'function' ) { - return function (data, type, row, meta) { - return mSource( data, type, row, meta ); - }; + if(oSettings !== undefined && oSettings.newCellRender === true) { + return function (data, type, row, meta) { + return mSource.call( this, data, type, row, meta ); + }; + } else { + return function (data, type, row, meta) { + //backwards-compatability + return mSource.call( this, data, type === 'adjust' ? 'display' : type, row, meta ); + }; + } } else if ( typeof mSource === 'string' && (mSource.indexOf('.') !== -1 || mSource.indexOf('[') !== -1 || mSource.indexOf('(') !== -1) ) @@ -236,7 +263,7 @@ function _fnGetObjectDataFn( mSource ) * return. This allows entire objects to be missing and sDefaultContent to * be used if defined, rather than throwing an error */ - var fetchData = function (data, type, src) { + var fetchData = function (data, src) { var arrayNotation, funcNotation, out, innerSrc; if ( src !== "" ) @@ -266,7 +293,7 @@ function _fnGetObjectDataFn( mSource ) // Traverse each entry in the array getting the properties requested for ( var j=0, jLen=data.length ; j').html( _fnGetCellData( settings, idx, colIdx, 'display' ) )[0] : - data.anCells[ colIdx ]; + if(data.nTr) { + return data.anCells[ colIdx ]; + } else { + // Might not have been created when deferred rendering + var tempTd = document.createElement("td"); + _fnGetCellData.call( tempTd, settings, idx, colIdx, 'display' ); + return tempTd; + } } @@ -292,7 +297,7 @@ function _fnGetMaxLenString( settings, colIdx ) var s, max=-1, maxIdx = -1; for ( var i=0, ien=settings.aoData.length ; i max ) {