1
0
mirror of https://github.com/DataTables/DataTables.git synced 2025-03-21 13:29:04 +01:00

New: row() methods - operate on a single row.

- The rows() method allows operations on multiple rows with a single
  call, this new singualr option, `row()` performs operations on a
  single row, allowing fine grain control and easy access to certain
  aspects. For example. `rows().data()` will return an array of data
  objects, even if there is only one row as a result of the selector,
  while `row().data()` will return the data object directly.

- Impletemented thus far:

  - row()
  - row().node()
  - row().cells()
  - row().data() - get only as of yet
  - row().index()
  - row().remove()
This commit is contained in:
Allan Jardine 2013-05-06 07:14:43 +01:00
parent 955eb2cd99
commit ed34f7972d
3 changed files with 91 additions and 0 deletions

View File

@ -116,6 +116,7 @@
require('api.order.js');
require('api._selectors.js');
require('api.rows.js');
require('api.row.js');
require('api.columns.js');
require('api.search.js');
require('api.static.js');

View File

@ -102,6 +102,29 @@ var _range = function ( len )
};
var _selector_first = function ( inst )
{
// Reduce the API instance to the first item found
var found = false;
for ( var i=0, ien=inst.length ; i<ien ; i++ ) {
if ( ! found ) {
if ( inst[i].length > 0 ) {
inst[i].splice( 1, inst[i].length );
inst.context = [ inst.context[i] ];
found = true;
}
}
else {
inst[i].splice( 0, inst[i].length );
}
}
return inst;
};
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Tables
*/

67
media/src/api/api.row.js Normal file
View File

@ -0,0 +1,67 @@
(/** @lends <global> */function() {
var _api = DataTable.Api;
/**
*
*/
_api.register( 'row()', function ( selector, opts ) {
return _selector_first( this.rows( selector, opts ) );
} );
_api.register( 'row().node()', function () {
var ctx = this.context;
if ( ctx.length && this.length ) {
return ctx[0].aoData[ this[0] ].nTr || undefined;
}
// return undefined;
} );
_api.register( 'row().cells()', function () {
var ctx = this.context;
if ( ctx.length && this.length ) {
return ctx[0].aoData[ this[0] ].anCells || undefined;
}
// return undefined;
} );
_api.register( 'row().data()', function ( data ) {
var ctx = this.context;
if ( ctx.length && this.length ) {
return ctx[0].aoData[ this[0] ]._aData;
}
// return undefined;
// @todo - Set operator
} );
_api.register( 'row().index()', function () {
return this.length ? this[0] : undefined;
} );
_api.register( 'row().remove()', function () {
if ( this.length ) {
// Hand off to the rows function
this.rows( this[0] ).remove();
}
return this;
} );
}());