diff --git a/media/src/DataTables.js b/media/src/DataTables.js index 5897f0a4..74c050e1 100644 --- a/media/src/DataTables.js +++ b/media/src/DataTables.js @@ -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'); diff --git a/media/src/api/api._selectors.js b/media/src/api/api._selectors.js index b5265428..4c43205c 100644 --- a/media/src/api/api._selectors.js +++ b/media/src/api/api._selectors.js @@ -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 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 */ diff --git a/media/src/api/api.row.js b/media/src/api/api.row.js new file mode 100644 index 00000000..6c7e6bf2 --- /dev/null +++ b/media/src/api/api.row.js @@ -0,0 +1,67 @@ + + +(/** @lends */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; +} ); + + + +}()); +