mirror of
https://github.com/DataTables/DataTables.git
synced 2024-11-29 11:24:10 +01:00
Updated: data
and render
can now have periods escaped from dotted
object notation. - Previously if you had an object key that contained a period, it wouldn't work with `data` or `render` (or rather it would need a function call to do it manually), since a split was being done on the periods to reconstruct the Javascript object property chain. Now it is possible to escape a period, allowing it to be included in the property name read / set. - Example: $('#example').dataTable( { columns: [ { data: 'a' }, { data: 'b\\.c' } ], data: [ { 'a': 1, 'b.c': 2 }, { 'a': 3, 'b.c': 4 }, { 'a': 5, 'b.c': 6 }, { 'a': 7, 'b.c': 8 } ] } );
This commit is contained in:
parent
b2de50229e
commit
1b6ffeaf78
@ -226,6 +226,19 @@ function _fnSetCellData( oSettings, iRow, iCol, val )
|
|||||||
var __reArray = /\[.*?\]$/;
|
var __reArray = /\[.*?\]$/;
|
||||||
var __reFn = /\(\)$/;
|
var __reFn = /\(\)$/;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Split string on periods, taking into account escaped periods
|
||||||
|
* @param {string} str String to split
|
||||||
|
* @return {array} Split string
|
||||||
|
*/
|
||||||
|
function _fnSplitObjNotation( str )
|
||||||
|
{
|
||||||
|
return $.map( str.match(/(\\.|[^\.])+/g), function ( s ) {
|
||||||
|
return s.replace('\\.', '.');
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a function that can be used to get data from a source object, taking
|
* 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
|
* into account the ability to use nested objects as a source
|
||||||
@ -258,7 +271,7 @@ function _fnGetObjectDataFn( mSource )
|
|||||||
* be used if defined, rather than throwing an error
|
* be used if defined, rather than throwing an error
|
||||||
*/
|
*/
|
||||||
var fetchData = function (data, type, src) {
|
var fetchData = function (data, type, src) {
|
||||||
var a = src.split('.');
|
var a = _fnSplitObjNotation( src );
|
||||||
var arrayNotation, funcNotation, out, innerSrc;
|
var arrayNotation, funcNotation, out, innerSrc;
|
||||||
|
|
||||||
if ( src !== "" )
|
if ( src !== "" )
|
||||||
@ -356,7 +369,7 @@ function _fnSetObjectDataFn( mSource )
|
|||||||
{
|
{
|
||||||
/* Like the get, we need to get data from a nested object */
|
/* Like the get, we need to get data from a nested object */
|
||||||
var setData = function (data, val, src) {
|
var setData = function (data, val, src) {
|
||||||
var a = src.split('.'), b;
|
var a = _fnSplitObjNotation( src );
|
||||||
var aLast = a[a.length-1];
|
var aLast = a[a.length-1];
|
||||||
var arrayNotation, funcNotation, o, innerSrc;
|
var arrayNotation, funcNotation, o, innerSrc;
|
||||||
|
|
||||||
|
@ -278,7 +278,8 @@ DataTable.defaults.column = {
|
|||||||
* * `.` - Dotted Javascript notation. Just as you use a `.` in
|
* * `.` - Dotted Javascript notation. Just as you use a `.` in
|
||||||
* Javascript to read from nested objects, so to can the options
|
* Javascript to read from nested objects, so to can the options
|
||||||
* specified in `data`. For example: `browser.version` or
|
* specified in `data`. For example: `browser.version` or
|
||||||
* `browser.name`.
|
* `browser.name`. If your object parameter name contains a period, use
|
||||||
|
* `\\` to escape it - i.e. `first\\.name`.
|
||||||
* * `[]` - Array notation. DataTables can automatically combine data
|
* * `[]` - Array notation. DataTables can automatically combine data
|
||||||
* from and array source, joining the data with the characters provided
|
* from and array source, joining the data with the characters provided
|
||||||
* between the two brackets. For example: `name[, ]` would provide a
|
* between the two brackets. For example: `name[, ]` would provide a
|
||||||
@ -453,7 +454,8 @@ DataTable.defaults.column = {
|
|||||||
* * `.` - Dotted Javascript notation. Just as you use a `.` in
|
* * `.` - Dotted Javascript notation. Just as you use a `.` in
|
||||||
* Javascript to read from nested objects, so to can the options
|
* Javascript to read from nested objects, so to can the options
|
||||||
* specified in `data`. For example: `browser.version` or
|
* specified in `data`. For example: `browser.version` or
|
||||||
* `browser.name`.
|
* `browser.name`. If your object parameter name contains a period, use
|
||||||
|
* `\\` to escape it - i.e. `first\\.name`.
|
||||||
* * `[]` - Array notation. DataTables can automatically combine data
|
* * `[]` - Array notation. DataTables can automatically combine data
|
||||||
* from and array source, joining the data with the characters provided
|
* from and array source, joining the data with the characters provided
|
||||||
* between the two brackets. For example: `name[, ]` would provide a
|
* between the two brackets. For example: `name[, ]` would provide a
|
||||||
|
Loading…
Reference in New Issue
Block a user