diff --git a/media/src/DataTables.js b/media/src/DataTables.js index de4bda79..329c8a41 100644 --- a/media/src/DataTables.js +++ b/media/src/DataTables.js @@ -117,6 +117,7 @@ require('api.rows.js'); require('api.row.js'); require('api.columns.js'); + require('api.cells.js'); require('api.order.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 4c43205c..2d31d720 100644 --- a/media/src/api/api._selectors.js +++ b/media/src/api/api._selectors.js @@ -106,21 +106,20 @@ 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] ]; + if ( inst[i].length > 0 ) { + // Assign the first element to the first item in the instance + // and truncate the instance and context + inst[0] = inst[i][0]; + inst.length = 1; + inst.context = [ inst.context[i] ]; - found = true; - } - } - else { - inst[i].splice( 0, inst[i].length ); + return inst; } } + // Not found - return an empty instance + inst.length = 0; return inst; }; diff --git a/media/src/api/api.base.js b/media/src/api/api.base.js index fed37c37..82c2294e 100644 --- a/media/src/api/api.base.js +++ b/media/src/api/api.base.js @@ -324,7 +324,7 @@ _Api.prototype = /** @lends DataTables.Api */{ a = [], ret, i, ien, j, jen, context = this.context, - rows, items, + rows, items, item, selector = this.selector; // Argument shifting @@ -350,7 +350,7 @@ _Api.prototype = /** @lends DataTables.Api */{ a.push( ret ); } } - else if ( type === 'column' || type === 'column-rows' || type === 'row' ) { + else if ( type === 'column' || type === 'column-rows' || type === 'row' || type === 'cell' ) { // columns and rows share the same structure. // 'this' is an array of column indexes for each context items = this[i]; @@ -360,7 +360,14 @@ _Api.prototype = /** @lends DataTables.Api */{ } for ( j=0, jen=items.length ; j */function() { + +var _api = DataTable.Api; + + +_api.register( 'cells()', function ( rowSelector, columnSelector, opts ) { + var columns = this.columns( columnSelector, opts ); + var rows = this.rows( rowSelector, opts ); + var a, i, ien, j, jen; + + return this.iterator( 'table', function ( settings, idx ) { + a = []; + + for ( i=0, ien=rows[idx].length ; i