mirror of
https://github.com/DataTables/DataTables.git
synced 2025-01-30 23:52:11 +01:00
New: mRender option for columns - this is effectively a simpiler version of mDataProp for reading data only (while mDataProp also sets data), and much more comprhensive than fnRender (as such fnRender is now offically deprecated). See the documentation comments in model.defaults.columns.js for further information on how to use mRender.
This commit is contained in:
parent
0ed6ceda95
commit
4886322183
107
media/js/jquery.dataTables.js
vendored
107
media/js/jquery.dataTables.js
vendored
@ -145,7 +145,18 @@
|
||||
}
|
||||
|
||||
/* Cache the data get and set functions for speed */
|
||||
oCol.fnGetData = _fnGetObjectDataFn( oCol.mDataProp );
|
||||
var mRender = oCol.mRender ? _fnGetObjectDataFn( oCol.mRender ) : null;
|
||||
var mData = _fnGetObjectDataFn( oCol.mDataProp );
|
||||
|
||||
oCol.fnGetData = function (oData, sSpecific) {
|
||||
var innerData = mData( oData, sSpecific );
|
||||
|
||||
if ( oCol.mRender && (sSpecific && sSpecific !== '') )
|
||||
{
|
||||
return mRender( innerData, sSpecific, oData );
|
||||
}
|
||||
return innerData;
|
||||
};
|
||||
oCol.fnSetData = _fnSetObjectDataFn( oCol.mDataProp );
|
||||
|
||||
/* Feature sorting overrides column specific when off */
|
||||
@ -806,8 +817,8 @@
|
||||
}
|
||||
else if ( typeof mSource === 'function' )
|
||||
{
|
||||
return function (data, type) {
|
||||
return mSource( data, type );
|
||||
return function (data, type, extra) {
|
||||
return mSource( data, type, extra );
|
||||
};
|
||||
}
|
||||
else if ( typeof mSource === 'string' && (mSource.indexOf('.') !== -1 || mSource.indexOf('[') !== -1) )
|
||||
@ -831,7 +842,11 @@
|
||||
|
||||
if ( arrayNotation ) {
|
||||
a[i] = a[i].replace(__reArray, '');
|
||||
|
||||
// Condition allows simply [] to be passed in
|
||||
if ( a[i] !== "" ) {
|
||||
data = data[ a[i] ];
|
||||
}
|
||||
out = [];
|
||||
|
||||
// Get the remainder of the nested object to get
|
||||
@ -7634,6 +7649,16 @@
|
||||
*/
|
||||
"mDataProp": null,
|
||||
|
||||
/**
|
||||
* Partner property to mDataProp which is used (only when defined) to get
|
||||
* the data - i.e. it is basically the same as mDataProp, but without the
|
||||
* 'set' option, and also the data fed to it is the result from mDataProp.
|
||||
* This is the rendering method to match the data method of mDataProp.
|
||||
* @type function|int|string|null
|
||||
* @default null
|
||||
*/
|
||||
"mRender": null,
|
||||
|
||||
/**
|
||||
* Unique header TH/TD element for this column - this is what the sorting
|
||||
* listener is attached to (if sorting is enabled.)
|
||||
@ -9830,12 +9855,12 @@
|
||||
* (before rendering) for sorting and filtering (the default is to used the
|
||||
* rendered data that the user can see). This may be useful for dates etc.
|
||||
*
|
||||
* *NOTE* It is it is advisable now to use mDataProp as a function and make
|
||||
* use of the 'type' that it gives, allowing (potentially) different data to
|
||||
* be used for sorting, filtering, display and type detection.
|
||||
* *NOTE* This property is now deprecated, and it is suggested that you use
|
||||
* mDataProp and / or mRender to render data for the DataTable.
|
||||
* @type boolean
|
||||
* @default true
|
||||
* @dtopt Columns
|
||||
* @deprecated
|
||||
*
|
||||
* @example
|
||||
* // Using aoColumnDefs
|
||||
@ -10099,6 +10124,76 @@
|
||||
"mDataProp": null,
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* This property is the rendering partner to mDataProp and it is suggested that
|
||||
* when you want to manipulate data for display (including filtering, sorting etc)
|
||||
* but not altering the underlying data for the table, use this property. mDataProp
|
||||
* can actually do everything this property can and more, but this parameter is
|
||||
* easier to use since there is no 'set' option. Like mDataProp is can be given
|
||||
* in a number of different ways to effect its behaviour, with the addition of
|
||||
* supporting array syntax for easy outputting of arrays (including arrays of
|
||||
* objects):
|
||||
* <ul>
|
||||
* <li>integer - treated as an array index for the data source. This is the
|
||||
* default that DataTables uses (incrementally increased for each column).</li>
|
||||
* <li>string - read an object property from the data source. Note that you can
|
||||
* use Javascript dotted notation to read deep properties/arrays from the
|
||||
* data source and also array brackets to indicate that the data reader should
|
||||
* loop over the data source array. When characters are given between the array
|
||||
* brackets, these characters are used to join the data source array together.
|
||||
* For example: "accounts[, ].name" would result in a comma separated list with
|
||||
* the 'name' value from the 'accounts' array of objects.</li>
|
||||
* <li>function - the function given will be executed whenever DataTables
|
||||
* needs to set or get the data for a cell in the column. The function
|
||||
* takes three parameters:
|
||||
* <ul>
|
||||
* <li>{array|object} The data source for the row (based on mDataProp)</li>
|
||||
* <li>{string} The type call data requested - this will be 'filter', 'display',
|
||||
* 'type' or 'sort'.</li>
|
||||
* <li>{array|object} The full data source for the row (not based on mDataProp)</li>
|
||||
* </ul>
|
||||
* The return value from the function is what will be used for the data
|
||||
* requested.</li>
|
||||
* </ul>
|
||||
* @type string|int|function|null
|
||||
* @default null <i>Use mDataProp</i>
|
||||
* @dtopt Columns
|
||||
*
|
||||
* @example
|
||||
* // Create a comma separated list from an array of objects
|
||||
* $(document).ready(function() {
|
||||
* var oTable = $('#example').dataTable( {
|
||||
* "sAjaxSource": "sources/deep.txt",
|
||||
* "aoColumns": [
|
||||
* { "mDataProp": "engine" },
|
||||
* { "mDataProp": "browser" },
|
||||
* {
|
||||
* "mDataProp": "platform",
|
||||
* "mRender": "[, ].name"
|
||||
* }
|
||||
* ]
|
||||
* } );
|
||||
* } );
|
||||
*
|
||||
* @example
|
||||
* // Use as a function to create a link from the data source
|
||||
* $(document).ready(function() {
|
||||
* var oTable = $('#example').dataTable( {
|
||||
* "aoColumnDefs": [
|
||||
* {
|
||||
* "aTargets": [ 0 ],
|
||||
* "mDataProp": "download_link",
|
||||
* "mRender": function ( data, type, full ) {
|
||||
* return '<a href="'+data+'">Download</a>';
|
||||
* }
|
||||
* ]
|
||||
* } );
|
||||
* } );
|
||||
*/
|
||||
"mRender": null,
|
||||
|
||||
|
||||
/**
|
||||
* Change the cell type created for the column - either TD cells or TH cells. This
|
||||
* can be useful as TH cells have semantic meaning in the table body, allowing them
|
||||
|
@ -85,7 +85,18 @@ function _fnColumnOptions( oSettings, iCol, oOptions )
|
||||
}
|
||||
|
||||
/* Cache the data get and set functions for speed */
|
||||
oCol.fnGetData = _fnGetObjectDataFn( oCol.mDataProp );
|
||||
var mRender = oCol.mRender ? _fnGetObjectDataFn( oCol.mRender ) : null;
|
||||
var mData = _fnGetObjectDataFn( oCol.mDataProp );
|
||||
|
||||
oCol.fnGetData = function (oData, sSpecific) {
|
||||
var innerData = mData( oData, sSpecific );
|
||||
|
||||
if ( oCol.mRender && (sSpecific && sSpecific !== '') )
|
||||
{
|
||||
return mRender( innerData, sSpecific, oData );
|
||||
}
|
||||
return innerData;
|
||||
};
|
||||
oCol.fnSetData = _fnSetObjectDataFn( oCol.mDataProp );
|
||||
|
||||
/* Feature sorting overrides column specific when off */
|
||||
|
@ -381,8 +381,8 @@ function _fnGetObjectDataFn( mSource )
|
||||
}
|
||||
else if ( typeof mSource === 'function' )
|
||||
{
|
||||
return function (data, type) {
|
||||
return mSource( data, type );
|
||||
return function (data, type, extra) {
|
||||
return mSource( data, type, extra );
|
||||
};
|
||||
}
|
||||
else if ( typeof mSource === 'string' && (mSource.indexOf('.') !== -1 || mSource.indexOf('[') !== -1) )
|
||||
@ -406,7 +406,11 @@ function _fnGetObjectDataFn( mSource )
|
||||
|
||||
if ( arrayNotation ) {
|
||||
a[i] = a[i].replace(__reArray, '');
|
||||
|
||||
// Condition allows simply [] to be passed in
|
||||
if ( a[i] !== "" ) {
|
||||
data = data[ a[i] ];
|
||||
}
|
||||
out = [];
|
||||
|
||||
// Get the remainder of the nested object to get
|
||||
|
@ -142,6 +142,16 @@ DataTable.models.oColumn = {
|
||||
*/
|
||||
"mDataProp": null,
|
||||
|
||||
/**
|
||||
* Partner property to mDataProp which is used (only when defined) to get
|
||||
* the data - i.e. it is basically the same as mDataProp, but without the
|
||||
* 'set' option, and also the data fed to it is the result from mDataProp.
|
||||
* This is the rendering method to match the data method of mDataProp.
|
||||
* @type function|int|string|null
|
||||
* @default null
|
||||
*/
|
||||
"mRender": null,
|
||||
|
||||
/**
|
||||
* Unique header TH/TD element for this column - this is what the sorting
|
||||
* listener is attached to (if sorting is enabled.)
|
||||
|
@ -146,12 +146,12 @@ DataTable.defaults.columns = {
|
||||
* (before rendering) for sorting and filtering (the default is to used the
|
||||
* rendered data that the user can see). This may be useful for dates etc.
|
||||
*
|
||||
* *NOTE* It is it is advisable now to use mDataProp as a function and make
|
||||
* use of the 'type' that it gives, allowing (potentially) different data to
|
||||
* be used for sorting, filtering, display and type detection.
|
||||
* *NOTE* This property is now deprecated, and it is suggested that you use
|
||||
* mDataProp and / or mRender to render data for the DataTable.
|
||||
* @type boolean
|
||||
* @default true
|
||||
* @dtopt Columns
|
||||
* @deprecated
|
||||
*
|
||||
* @example
|
||||
* // Using aoColumnDefs
|
||||
@ -415,6 +415,76 @@ DataTable.defaults.columns = {
|
||||
"mDataProp": null,
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* This property is the rendering partner to mDataProp and it is suggested that
|
||||
* when you want to manipulate data for display (including filtering, sorting etc)
|
||||
* but not altering the underlying data for the table, use this property. mDataProp
|
||||
* can actually do everything this property can and more, but this parameter is
|
||||
* easier to use since there is no 'set' option. Like mDataProp is can be given
|
||||
* in a number of different ways to effect its behaviour, with the addition of
|
||||
* supporting array syntax for easy outputting of arrays (including arrays of
|
||||
* objects):
|
||||
* <ul>
|
||||
* <li>integer - treated as an array index for the data source. This is the
|
||||
* default that DataTables uses (incrementally increased for each column).</li>
|
||||
* <li>string - read an object property from the data source. Note that you can
|
||||
* use Javascript dotted notation to read deep properties/arrays from the
|
||||
* data source and also array brackets to indicate that the data reader should
|
||||
* loop over the data source array. When characters are given between the array
|
||||
* brackets, these characters are used to join the data source array together.
|
||||
* For example: "accounts[, ].name" would result in a comma separated list with
|
||||
* the 'name' value from the 'accounts' array of objects.</li>
|
||||
* <li>function - the function given will be executed whenever DataTables
|
||||
* needs to set or get the data for a cell in the column. The function
|
||||
* takes three parameters:
|
||||
* <ul>
|
||||
* <li>{array|object} The data source for the row (based on mDataProp)</li>
|
||||
* <li>{string} The type call data requested - this will be 'filter', 'display',
|
||||
* 'type' or 'sort'.</li>
|
||||
* <li>{array|object} The full data source for the row (not based on mDataProp)</li>
|
||||
* </ul>
|
||||
* The return value from the function is what will be used for the data
|
||||
* requested.</li>
|
||||
* </ul>
|
||||
* @type string|int|function|null
|
||||
* @default null <i>Use mDataProp</i>
|
||||
* @dtopt Columns
|
||||
*
|
||||
* @example
|
||||
* // Create a comma separated list from an array of objects
|
||||
* $(document).ready(function() {
|
||||
* var oTable = $('#example').dataTable( {
|
||||
* "sAjaxSource": "sources/deep.txt",
|
||||
* "aoColumns": [
|
||||
* { "mDataProp": "engine" },
|
||||
* { "mDataProp": "browser" },
|
||||
* {
|
||||
* "mDataProp": "platform",
|
||||
* "mRender": "[, ].name"
|
||||
* }
|
||||
* ]
|
||||
* } );
|
||||
* } );
|
||||
*
|
||||
* @example
|
||||
* // Use as a function to create a link from the data source
|
||||
* $(document).ready(function() {
|
||||
* var oTable = $('#example').dataTable( {
|
||||
* "aoColumnDefs": [
|
||||
* {
|
||||
* "aTargets": [ 0 ],
|
||||
* "mDataProp": "download_link",
|
||||
* "mRender": function ( data, type, full ) {
|
||||
* return '<a href="'+data+'">Download</a>';
|
||||
* }
|
||||
* ]
|
||||
* } );
|
||||
* } );
|
||||
*/
|
||||
"mRender": null,
|
||||
|
||||
|
||||
/**
|
||||
* Change the cell type created for the column - either TD cells or TH cells. This
|
||||
* can be useful as TH cells have semantic meaning in the table body, allowing them
|
||||
|
Loading…
x
Reference in New Issue
Block a user