Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion js/core/core.ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,6 @@ function _fnAjaxDataSrc ( oSettings, json )
}

return dataSrc !== "" ?
_fnGetObjectDataFn( dataSrc )( json ) :
_fnGetObjectDataFn( dataSrc, oSettings )( json ) :
json;
}
6 changes: 3 additions & 3 deletions js/core/core.columns.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 ) {
Expand Down
1 change: 1 addition & 0 deletions js/core/core.constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ _fnMap( oSettings, oInit, [
"fnStateLoadCallback",
"fnStateSaveCallback",
"renderer",
"newCellRender",
"searchDelay",
[ "iCookieDuration", "iStateDuration" ], // backwards compat
[ "oSearch", "oPreviousSearch" ],
Expand Down
63 changes: 45 additions & 18 deletions js/core/core.data.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand All @@ -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;
Expand Down Expand Up @@ -192,25 +204,33 @@ 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 ) )
{
/* Build an object of get functions, and wrap them in a single call */
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;
};
}
Expand All @@ -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) )
Expand All @@ -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 !== "" )
Expand Down Expand Up @@ -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<jLen ; j++ ) {
out.push( fetchData( data[j], type, innerSrc ) );
out.push( fetchData( data[j], innerSrc ) );
}

// If a string is given in between the array notation indicators, that
Expand Down Expand Up @@ -297,14 +324,14 @@ function _fnGetObjectDataFn( mSource )
return data;
};

return function (data, type) { // row and meta also passed, but not used
return fetchData( data, type, mSource );
return function (data) { // type, row and meta also passed, but not used
return fetchData( data, mSource );
};
}
else
{
/* Array or flat object mapping */
return function (data, type) { // row and meta also passed, but not used
return function (data) { // type, row and meta also passed, but not used
return data[mSource];
};
}
Expand Down Expand Up @@ -503,8 +530,8 @@ function _fnInvalidate( settings, rowIdx, src, colIdx )
while ( cell.childNodes.length ) {
cell.removeChild( cell.firstChild );
}

cell.innerHTML = _fnGetCellData( settings, rowIdx, col, 'display' );
_fnGetCellData.call(cell, settings, rowIdx, col, 'display' );
};

// Are we reading last data from DOM or the data object?
Expand Down
2 changes: 1 addition & 1 deletion js/core/core.draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function _fnCreateTr ( oSettings, iRow, nTrIn, anTds )
// Need to create the HTML if new, or if a rendering function is defined
if ( !nTrIn || oCol.mRender || oCol.mData !== i )
{
nTd.innerHTML = _fnGetCellData( oSettings, iRow, i, 'display' );
_fnGetCellData.call(nTd, oSettings, iRow, i, 'display' );
}

/* Add user defined class */
Expand Down
13 changes: 9 additions & 4 deletions js/core/core.sizing.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,14 @@ function _fnGetWidestNode( settings, colIdx )
}

var data = settings.aoData[ idx ];
return ! data.nTr ? // Might not have been created when deferred rendering
$('<td/>').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;
}
}


Expand All @@ -292,7 +297,7 @@ function _fnGetMaxLenString( settings, colIdx )
var s, max=-1, maxIdx = -1;

for ( var i=0, ien=settings.aoData.length ; i<ien ; i++ ) {
s = _fnGetCellData( settings, i, colIdx, 'display' )+'';
s = _fnGetCellData( settings, i, colIdx, 'adjust' )+'';
s = s.replace( __re_html_remove, '' );

if ( s.length > max ) {
Expand Down