Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

New: mDataProp can now be a function as well as either a string or an

integer. This allows dynamic reading of information from the source
object (for example getting the length of an array in the data source
object) as well as the deep object reading and array index reading
already available. The function is called with a single argument (the
data object) when being read and two arguments (the data object, new
value) when being set. This can be seen as an alternative to fnRender
but it makes sense to include this functionality here as an option.
  • Loading branch information...
commit 8859dfe3806129acc62bee9fe803b6216b50a8ff 1 parent 2530ea1
Allan Jardine authored
Showing with 24 additions and 12 deletions.
  1. +24 −12 media/js/jquery.dataTables.js
36 media/js/jquery.dataTables.js
View
@@ -6611,24 +6611,30 @@
* Purpose: 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
* Returns: function: - Data get function
- * Inputs: string:sSource - The data source for the object
+ * Inputs: string|int|function:mSource - The data source for the object
*/
- function _fnGetObjectDataFn( sSource )
+ function _fnGetObjectDataFn( mSource )
{
- if ( sSource === null )
+ if ( mSource === null )
{
/* Give an empty string for rendering / sorting etc */
return function (data) {
return null;
};
}
- else if ( typeof sSource == 'string' && sSource.indexOf('.') != -1 )
+ else if ( typeof mSource == 'function' )
+ {
+ return function (data) {
+ return mSource( data );
+ };
+ }
+ else if ( typeof mSource == 'string' && mSource.indexOf('.') != -1 )
{
/* If there is a . in the source string then the data source is in a nested object
* we provide two 'quick' functions for the look up to speed up the most common
* operation, and a generalised one for when it is needed
*/
- var a = sSource.split('.');
+ var a = mSource.split('.');
if ( a.length == 2 )
{
return function (data) {
@@ -6656,7 +6662,7 @@
{
/* Array or flat object mapping */
return function (data) {
- return data[sSource];
+ return data[mSource];
};
}
}
@@ -6666,21 +6672,27 @@
* Purpose: Return a function that can be used to set data from a source object, taking
* into account the ability to use nested objects as a source
* Returns: function: - Data set function
- * Inputs: string:sSource - The data source for the object
+ * Inputs: string|int|function:mSource - The data source for the object
*/
- function _fnSetObjectDataFn( sSource )
+ function _fnSetObjectDataFn( mSource )
{
- if ( sSource === null )
+ if ( mSource === null )
{
/* Nothing to do when the data source is null */
return function (data, val) {};
}
- else if ( typeof sSource == 'string' && sSource.indexOf('.') != -1 )
+ else if ( typeof mSource == 'function' )
+ {
+ return function (data, val) {
+ return mSource( data, val );
+ };
+ }
+ else if ( typeof mSource == 'string' && mSource.indexOf('.') != -1 )
{
/* Like the get, we need to get data from a nested object. Again two fast lookup
* functions are provided, and a generalised one.
*/
- var a = sSource.split('.');
+ var a = mSource.split('.');
if ( a.length == 2 )
{
return function (data, val) {
@@ -6708,7 +6720,7 @@
{
/* Array or flat object mapping */
return function (data, val) {
- data[sSource] = val;
+ data[mSource] = val;
};
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.