mirror of
https://github.com/DataTables/DataTables.git
synced 2024-11-29 11:24:10 +01:00
New: cells() and cell() API methods now accept a cell selector and options
- For consistency and completeness, the cell() and cells() methods now accept their own cell selector option (rather than just rows and columns) which is a jQuery selector, or no selector at all for all cells. Additionally it allows an options object to be passed in, to allow configuraiton of the order of data etc. - The cells() method now has these calling options: - cells() - all cells - cells( opts ) - option configuration - cells( selector ) - cell selector - cells( selector, opts ) - cell selector + options - cells( rowSelector, columnSelector ) - row + column selector - cells( rowSelector, columnSelector, opts ) - row + column selector + opttions - The cell() method as the same signature.
This commit is contained in:
parent
a30468a1f4
commit
8e583a51b3
@ -61,7 +61,7 @@ var _selector_run = function ( selector, select )
|
||||
}
|
||||
|
||||
for ( i=0, ien=selector.length ; i<ien ; i++ ) {
|
||||
a = selector[i].split ?
|
||||
a = selector[i] && selector[i].split ?
|
||||
selector[i].split(',') :
|
||||
[ selector[i] ];
|
||||
|
||||
@ -337,3 +337,56 @@ var _column_selector = function ( settings, selector, opts )
|
||||
}
|
||||
} );
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Cells
|
||||
*
|
||||
* {node} - cell node
|
||||
* "{string}" - jquery selector to run on the nodes
|
||||
*
|
||||
*/
|
||||
|
||||
var _cell_selector = function ( settings, selector, opts )
|
||||
{
|
||||
var data = settings.aoData;
|
||||
var rows = _row_selector_indexes( settings, opts );
|
||||
var cells = _pluck_order( data, rows, 'anCells' );
|
||||
var allCells = $( [].concat.apply([], cells) );
|
||||
var row;
|
||||
var columns = settings.aoColumns.length;
|
||||
var a, i, ien, j;
|
||||
|
||||
return _selector_run( selector, function ( s ) {
|
||||
if ( ! s ) {
|
||||
// All cells
|
||||
a = [];
|
||||
|
||||
for ( i=0, ien=rows.length ; i<ien ; i++ ) {
|
||||
row = rows[i];
|
||||
|
||||
for ( j=0 ; j<columns ; j++ ) {
|
||||
a.push( {
|
||||
row: row,
|
||||
column: j
|
||||
} );
|
||||
}
|
||||
}
|
||||
|
||||
return a;
|
||||
}
|
||||
|
||||
// jQuery filtered cells
|
||||
return allCells.filter( s ).map( function (i, el) {
|
||||
row = el.parentNode._DT_RowIndex;
|
||||
|
||||
return {
|
||||
row: row,
|
||||
column: $.inArray( el, data[ row ].anCells )
|
||||
};
|
||||
} );
|
||||
} );
|
||||
};
|
||||
|
||||
|
@ -6,6 +6,24 @@ var _api = DataTable.Api;
|
||||
|
||||
|
||||
_api.register( 'cells()', function ( rowSelector, columnSelector, opts ) {
|
||||
// Argument shifting
|
||||
if ( $.isPlainObject( rowSelector ) ) {
|
||||
opts = rowSelector;
|
||||
rowSelector = null;
|
||||
}
|
||||
if ( $.isPlainObject( columnSelector ) ) {
|
||||
opts = columnSelector;
|
||||
columnSelector = null;
|
||||
}
|
||||
|
||||
// Cell selector
|
||||
if ( columnSelector === null || columnSelector === undefined ) {
|
||||
return this.iterator( 'table', function ( settings ) {
|
||||
return _cell_selector( settings, rowSelector, _selector_opts( opts ) );
|
||||
} );
|
||||
}
|
||||
|
||||
// Row + column selector
|
||||
var columns = this.columns( columnSelector, opts );
|
||||
var rows = this.rows( rowSelector, opts );
|
||||
var a, i, ien, j, jen;
|
||||
@ -74,17 +92,18 @@ _api.register( 'cell()', function ( rowSelector, columnSelector, opts ) {
|
||||
|
||||
_api.register( 'cell().data()', function ( data ) {
|
||||
var ctx = this.context;
|
||||
var cell = this[0];
|
||||
|
||||
if ( data === undefined ) {
|
||||
// Get
|
||||
return ctx.length && this.length ?
|
||||
_fnGetCellData( ctx[0], this[0].row, this[0].column ) :
|
||||
return ctx.length && cell.length ?
|
||||
_fnGetCellData( ctx[0], cell[0].row, cell[0].column ) :
|
||||
undefined;
|
||||
}
|
||||
|
||||
// Set
|
||||
_fnSetCellData( ctx[0], this[0].row, this[0].column, data );
|
||||
_fnInvalidateRow( ctx[0], this[0].row, 'data' );
|
||||
_fnSetCellData( ctx[0], cell[0].row, cell[0].column, data );
|
||||
_fnInvalidateRow( ctx[0], cell[0].row, 'data' );
|
||||
|
||||
return this;
|
||||
} );
|
||||
|
Loading…
Reference in New Issue
Block a user