mirror of
https://github.com/DataTables/DataTables.git
synced 2025-02-27 00:54:15 +01:00
New: Instance methods for a data source are now executed in the scope of that instance
* When `dt-init columns.data` / `dt-init columns.render` resolve to a function, that function is executed. Previously this execution was in the global scope, but in order to be able to use an instance as a data source for the row (something I wanted as part of 1.10) we need to execute the function with the instance's scope. A simple `call()` does this. * I could add a check to see if the `rowData` is a plain object or not, but that would add significant overhead to the processing, and this particular part of the code needs to be very fast. Additionally, I think it is unlikely that any one was dependant on this being executed in global scope, so the change is made. * This fixes DataTables/DataTables #368.
This commit is contained in:
parent
264e1f0a60
commit
cd920b0605
@ -1 +1 @@
|
||||
3541d0e0d78cf88a97186f1e6c3346997f6a14f4
|
||||
778f3938168a642602117744f7c89743a78385b4
|
||||
|
11
media/js/jquery.dataTables.js
vendored
11
media/js/jquery.dataTables.js
vendored
@ -1054,16 +1054,16 @@
|
||||
* @returns {*} Cell data
|
||||
* @memberof DataTable#oApi
|
||||
*/
|
||||
function _fnGetCellData( settings, rowIdx, coliDx, type )
|
||||
function _fnGetCellData( settings, rowIdx, colIdx, type )
|
||||
{
|
||||
var draw = settings.iDraw;
|
||||
var col = settings.aoColumns[coliDx];
|
||||
var col = settings.aoColumns[colIdx];
|
||||
var rowData = settings.aoData[rowIdx]._aData;
|
||||
var defaultContent = col.sDefaultContent;
|
||||
var cellData = col.fnGetData( rowData, type, {
|
||||
settings: settings,
|
||||
row: rowIdx,
|
||||
col: coliDx
|
||||
col: colIdx
|
||||
} );
|
||||
|
||||
if ( cellData === undefined ) {
|
||||
@ -1081,8 +1081,9 @@
|
||||
cellData = defaultContent;
|
||||
}
|
||||
else if ( typeof cellData === 'function' ) {
|
||||
// If the data source is a function, then we run it and use the return
|
||||
return cellData();
|
||||
// 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 );
|
||||
}
|
||||
|
||||
if ( cellData === null && type == 'display' ) {
|
||||
|
2
media/js/jquery.dataTables.min.js
vendored
2
media/js/jquery.dataTables.min.js
vendored
@ -11,7 +11,7 @@ a=-1!==h.inArray("asc",b.asSorting);c=-1!==h.inArray("desc",b.asSorting);!b.bSor
|
||||
a.oScroll;(""!==b.sY||""!==b.sX)&&W(a);u(a,null,"column-sizing",[a])}function ga(a,b){var c=X(a,"bVisible");return"number"===typeof c[b]?c[b]:null}function Y(a,b){var c=X(a,"bVisible"),c=h.inArray(b,c);return-1!==c?c:null}function Z(a){return X(a,"bVisible").length}function X(a,b){var c=[];h.map(a.aoColumns,function(a,e){a[b]&&c.push(e)});return c}function Da(a){var b=a.aoColumns,c=a.aoData,d=p.ext.type.detect,e,f,g,j,i,h,m,n,k;e=0;for(f=b.length;e<f;e++)if(m=b[e],k=[],!m.sType&&m._sManualType)m.sType=
|
||||
m._sManualType;else if(!m.sType){g=0;for(j=d.length;g<j;g++){i=0;for(h=c.length;i<h&&!(k[i]===l&&(k[i]=A(a,i,e,"type")),n=d[g](k[i],a),!n||"html"===n);i++);if(n){m.sType=n;break}}m.sType||(m.sType="string")}}function hb(a,b,c,d){var e,f,g,j,i,o,m=a.aoColumns;if(b)for(e=b.length-1;0<=e;e--){o=b[e];var n=o.targets!==l?o.targets:o.aTargets;h.isArray(n)||(n=[n]);f=0;for(g=n.length;f<g;f++)if("number"===typeof n[f]&&0<=n[f]){for(;m.length<=n[f];)Aa(a);d(n[f],o)}else if("number"===typeof n[f]&&0>n[f])d(m.length+
|
||||
n[f],o);else if("string"===typeof n[f]){j=0;for(i=m.length;j<i;j++)("_all"==n[f]||h(m[j].nTh).hasClass(n[f]))&&d(j,o)}}if(c){e=0;for(a=c.length;e<a;e++)d(e,c[e])}}function I(a,b,c,d){var e=a.aoData.length,f=h.extend(!0,{},p.models.oRow,{src:c?"dom":"data"});f._aData=b;a.aoData.push(f);for(var b=a.aoColumns,f=0,g=b.length;f<g;f++)c&&Ea(a,e,f,A(a,e,f)),b[f].sType=null;a.aiDisplayMaster.push(e);(c||!a.oFeatures.bDeferRender)&&Fa(a,e,c,d);return e}function ha(a,b){var c;b instanceof h||(b=h(b));return b.map(function(b,
|
||||
e){c=ia(a,e);return I(a,c.data,e,c.cells)})}function A(a,b,c,d){var e=a.iDraw,f=a.aoColumns[c],g=a.aoData[b]._aData,j=f.sDefaultContent,c=f.fnGetData(g,d,{settings:a,row:b,col:c});if(c===l)return a.iDrawError!=e&&null===j&&(P(a,0,"Requested unknown parameter "+("function"==typeof f.mData?"{function}":"'"+f.mData+"'")+" for row "+b,4),a.iDrawError=e),j;if((c===g||null===c)&&null!==j)c=j;else if("function"===typeof c)return c();return null===c&&"display"==d?"":c}function Ea(a,b,c,d){a.aoColumns[c].fnSetData(a.aoData[b]._aData,
|
||||
e){c=ia(a,e);return I(a,c.data,e,c.cells)})}function A(a,b,c,d){var e=a.iDraw,f=a.aoColumns[c],g=a.aoData[b]._aData,j=f.sDefaultContent,c=f.fnGetData(g,d,{settings:a,row:b,col:c});if(c===l)return a.iDrawError!=e&&null===j&&(P(a,0,"Requested unknown parameter "+("function"==typeof f.mData?"{function}":"'"+f.mData+"'")+" for row "+b,4),a.iDrawError=e),j;if((c===g||null===c)&&null!==j)c=j;else if("function"===typeof c)return c.call(g);return null===c&&"display"==d?"":c}function Ea(a,b,c,d){a.aoColumns[c].fnSetData(a.aoData[b]._aData,
|
||||
d,{settings:a,row:b,col:c})}function Ga(a){return h.map(a.match(/(\\.|[^\.])+/g),function(a){return a.replace(/\\./g,".")})}function U(a){if(h.isPlainObject(a)){var b={};h.each(a,function(a,c){c&&(b[a]=U(c))});return function(a,c,f,g){var j=b[c]||b._;return j!==l?j(a,c,f,g):a}}if(null===a)return function(a){return a};if("function"===typeof a)return function(b,c,f,g){return a(b,c,f,g)};if("string"===typeof a&&(-1!==a.indexOf(".")||-1!==a.indexOf("[")||-1!==a.indexOf("("))){var c=function(a,b,f){var g,
|
||||
j;if(""!==f){j=Ga(f);for(var i=0,h=j.length;i<h;i++){f=j[i].match($);g=j[i].match(Q);if(f){j[i]=j[i].replace($,"");""!==j[i]&&(a=a[j[i]]);g=[];j.splice(0,i+1);j=j.join(".");i=0;for(h=a.length;i<h;i++)g.push(c(a[i],b,j));a=f[0].substring(1,f[0].length-1);a=""===a?g:g.join(a);break}else if(g){j[i]=j[i].replace(Q,"");a=a[j[i]]();continue}if(null===a||a[j[i]]===l)return l;a=a[j[i]]}}return a};return function(b,e){return c(b,e,a)}}return function(b){return b[a]}}function Ba(a){if(h.isPlainObject(a))return Ba(a._);
|
||||
if(null===a)return function(){};if("function"===typeof a)return function(b,d,e){a(b,"set",d,e)};if("string"===typeof a&&(-1!==a.indexOf(".")||-1!==a.indexOf("[")||-1!==a.indexOf("("))){var b=function(a,d,e){var e=Ga(e),f;f=e[e.length-1];for(var g,j,i=0,h=e.length-1;i<h;i++){g=e[i].match($);j=e[i].match(Q);if(g){e[i]=e[i].replace($,"");a[e[i]]=[];f=e.slice();f.splice(0,i+1);g=f.join(".");j=0;for(h=d.length;j<h;j++)f={},b(f,d[j],g),a[e[i]].push(f);return}j&&(e[i]=e[i].replace(Q,""),a=a[e[i]](d));if(null===
|
||||
|
Loading…
x
Reference in New Issue
Block a user