From 0a5ee8c0dbcf4ea71d3a24d1c12ed2f3d0441273 Mon Sep 17 00:00:00 2001 From: anu91ab Date: Sun, 23 Jan 2022 22:49:56 +0530 Subject: [PATCH 1/3] Trigger a callback function for render return with parameters similar to createdCell callback --- js/core/core.data.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/core/core.data.js b/js/core/core.data.js index 05721a538..91650955b 100644 --- a/js/core/core.data.js +++ b/js/core/core.data.js @@ -150,7 +150,7 @@ function _fnGetCellData( settings, rowIdx, colIdx, type ) else if ( typeof cellData === 'function' ) { // If the data source is a function, then we run it and use the return, // executing in the scope of the data object (for instances) - return cellData.call( rowData ); + return cellData(settings.aoData[rowIdx].anCells[colIdx], col.mData ? rowData[col.mData] : defaultContent, rowData, rowIdx); } if ( cellData === null && type === 'display' ) { From 8759dcf2d5bfca8a66610484f05fd83bf32ac4c7 Mon Sep 17 00:00:00 2001 From: anu91ab Date: Sun, 23 Jan 2022 23:28:21 +0530 Subject: [PATCH 2/3] To listen to a returned function in render callback; and not expect to insert string into innerHTML --- js/core/core.data.js | 10 ++++++++-- js/core/core.draw.js | 9 ++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/js/core/core.data.js b/js/core/core.data.js index 05721a538..c1aab20f4 100644 --- a/js/core/core.data.js +++ b/js/core/core.data.js @@ -150,7 +150,7 @@ function _fnGetCellData( settings, rowIdx, colIdx, type ) else if ( typeof cellData === 'function' ) { // If the data source is a function, then we run it and use the return, // executing in the scope of the data object (for instances) - return cellData.call( rowData ); + return cellData; } if ( cellData === null && type === 'display' ) { @@ -311,7 +311,13 @@ function _fnInvalidate( settings, rowIdx, src, colIdx ) cell.removeChild( cell.firstChild ); } - cell.innerHTML = _fnGetCellData( settings, rowIdx, col, 'display' ); + var cellData = _fnGetCellData( settings, rowIdx, col, 'display' ); + if (typeof cellData === 'string') { + cell.innerHTML = cellData; + } else if (typeof cellData === 'function') { + var targetCol = settings.aoColumns[col] + cellData(cell, targetCol.mData ? row._aData[targetCol.mData] : col.sDefaultContent, row._aData, rowIdx) + } }; // Are we reading last data from DOM or the data object? diff --git a/js/core/core.draw.js b/js/core/core.draw.js index 588d4b137..3489733a0 100644 --- a/js/core/core.draw.js +++ b/js/core/core.draw.js @@ -50,7 +50,14 @@ function _fnCreateTr ( oSettings, iRow, nTrIn, anTds ) if ( create || ((oCol.mRender || oCol.mData !== i) && (!$.isPlainObject(oCol.mData) || oCol.mData._ !== i+'.display') )) { - nTd.innerHTML = _fnGetCellData( oSettings, iRow, i, 'display' ); + + var cellData = _fnGetCellData( oSettings, iRow, i, 'display' ); + + if (typeof cellData === 'string') { + nTd.innerHTML = cellData; + } else if (typeof cellData === 'function') { + cellData(nTd, oCol.mData ? row._aData[oCol.mData] : oCol.sDefaultContent, row._aData, iRow) + } } /* Add user defined class */ From 796da6b13ad576602da5ed349917758ffce731c2 Mon Sep 17 00:00:00 2001 From: anu91ab Date: Sun, 23 Jan 2022 23:48:28 +0530 Subject: [PATCH 3/3] Correction to process existing feature of return function returning string in render --- js/core/core.data.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/js/core/core.data.js b/js/core/core.data.js index c1aab20f4..18b6320fa 100644 --- a/js/core/core.data.js +++ b/js/core/core.data.js @@ -150,7 +150,11 @@ function _fnGetCellData( settings, rowIdx, colIdx, type ) else if ( typeof cellData === 'function' ) { // If the data source is a function, then we run it and use the return, // executing in the scope of the data object (for instances) - return cellData; + if (col.renderReturnType === 'function') { + return cellData; + } else { + return cellData.call(rowData) + } } if ( cellData === null && type === 'display' ) {