mirror of
https://github.com/DataTables/DataTables.git
synced 2025-03-15 16:29:16 +01:00
New: API methods rows().nodes(), rows().data() and columns().header()
- rows().nodes() - Get the TR nodes for the selected rows - rows().data() - Get the data for the selected rows - columns().header() - Get the header cells for the selected columns - This also introduces the `iterator` method to the API instance, which can be used to loop over selected columns / rows, for the context (tables), returning a flat array / API instance.
This commit is contained in:
parent
c53806feee
commit
a3b90fd0cc
@ -19,20 +19,20 @@ var _intVal = function ( s ) {
|
||||
var _selector_run = function ( selector, select )
|
||||
{
|
||||
var
|
||||
out = [],
|
||||
a, i, ien, res;
|
||||
out = [], res,
|
||||
a, i, ien, j, jen;
|
||||
|
||||
if ( ! $.isArray( selector ) ) {
|
||||
selector = [ selector ];
|
||||
}
|
||||
|
||||
for ( i=0, ien=selector.length ; i<ien ; i++ ) {
|
||||
a = sel.split ?
|
||||
sel.split(',') :
|
||||
[ sel ];
|
||||
a = selector[i].split ?
|
||||
selector[i].split(',') :
|
||||
[ selector[i] ];
|
||||
|
||||
for ( i=0, ien=a.length ; i<ien ; i++ ) {
|
||||
res = select( typeof a[i] === 'string' ? $.trim(a[i]) : a[i] );
|
||||
for ( j=0, jen=a.length ; j<jen ; j++ ) {
|
||||
res = select( typeof a[j] === 'string' ? $.trim(a[j]) : a[j] );
|
||||
|
||||
if ( res && res.length ) {
|
||||
out.push.apply( out, res );
|
||||
|
@ -18,25 +18,9 @@ _api.register( 'columns()', function ( selector ) {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
_api.register( 'columns().cells()', function ( selector ) {
|
||||
var that = this;
|
||||
|
||||
return this.tables( function ( settings, thatIdx ) {
|
||||
var cols = that[thatIdx];
|
||||
var a = [];
|
||||
|
||||
// cols is an array of columns for the table
|
||||
for ( var i=0, ien=cols.length ; i<ien ; i++ ) {
|
||||
var colIdx = cols[i];
|
||||
var col = settings.aoColumns[ colIdx ];
|
||||
|
||||
|
||||
}
|
||||
|
||||
return a;
|
||||
|
||||
// should the resulting API instance be flattened, otherwise it is an
|
||||
// array item for each table. Thinking yes. How?
|
||||
_api.register( 'columns().header()', function ( selector, opts ) {
|
||||
return this.iterator( function ( settings, el ) {
|
||||
return settings.aoColumns[ el ].nTh;
|
||||
} );
|
||||
} );
|
||||
|
||||
|
@ -311,6 +311,33 @@ _Api.prototype = /** @lends DataTables.Api */{
|
||||
return -1;
|
||||
},
|
||||
|
||||
// Internal only at the moment - relax?
|
||||
iterator: function ( fn ) {
|
||||
var
|
||||
a = [], ret,
|
||||
i, ien, j, jen, k, ken,
|
||||
context = this.context,
|
||||
items;
|
||||
|
||||
for ( i=0, ien=context.length ; i<ien ; i++ ) {
|
||||
for( j=0, jen=this.length ; j<jen ; j++ ) {
|
||||
items = this[i];
|
||||
|
||||
for ( k=0, ken=items.length ; k<ken ; k++ ) {
|
||||
ret = fn( context[i], items[k], i, j, k );
|
||||
|
||||
if ( ret !== undefined ) {
|
||||
a.push( ret );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return a.length ?
|
||||
new _Api( context, a ) :
|
||||
this;
|
||||
},
|
||||
|
||||
|
||||
lastIndexOf: _arrayProto.lastIndexOf || function (obj, start)
|
||||
{
|
||||
|
@ -6,6 +6,8 @@ var _api = DataTable.Api;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@ -16,6 +18,19 @@ _api.register( 'rows()', function ( selector, opts ) {
|
||||
} );
|
||||
|
||||
|
||||
_api.register( 'rows().nodes()', function () {
|
||||
return this.iterator( function ( settings, el ) {
|
||||
return settings.aoData[ el ].nTr || undefined;
|
||||
} );
|
||||
} );
|
||||
|
||||
|
||||
_api.register( 'rows().data()', function ( data ) {
|
||||
return this.iterator( function ( settings, el ) {
|
||||
return settings.aoData[ el ]._aData;
|
||||
} );
|
||||
} );
|
||||
|
||||
|
||||
}());
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user