1
0
mirror of https://github.com/DataTables/DataTables.git synced 2024-11-29 11:24:10 +01:00

API: Consistency of data return for columns().data()

- The columns().data() method was flattening the returned array. While
  possibly okay on its own, that doesn't match the behaviour of how
  rows().data() works, where each row is an entry in the array, rather
  than the array being flattened. As such I've changed columns().data()
  to work work in the say way, for each column you select, you get an
  entry in the api instance - an array with the data for the that
  column.

- To allow for hte fact that some may want to work with the flattened
  data, I've added a `flatten()` method to the instance base, which is
  basically a shortcut call to `reduce`.
This commit is contained in:
Allan Jardine 2013-05-19 09:54:46 +01:00
parent f0a73ce595
commit 1b4688cdf3
4 changed files with 13 additions and 5 deletions

View File

@ -307,6 +307,14 @@ _Api.prototype = /** @lends DataTables.Api */{
},
flatten: function ()
{
return this.reduce( function ( a, b ) {
return a.concat( b );
} );
},
indexOf: _arrayProto.indexOf || function (obj, start)
{
for ( var i=(start || 0), ien=this.length ; i<ien ; i++ ) {

View File

@ -36,14 +36,14 @@ _api.register( 'cells()', function ( rowSelector, columnSelector, opts ) {
_api.register( 'cells().nodes()', function () {
return this.iterator( true, 'cell', function ( settings, row, column ) {
return this.iterator( 'cell', function ( settings, row, column ) {
return settings.aoData[ row ].anCells[ column ];
} );
} );
_api.register( 'cells().data()', function () {
return this.iterator( true, 'cell', function ( settings, row, column ) {
return this.iterator( 'cell', function ( settings, row, column ) {
return _fnGetCellData( settings, row, column );
} );
} );

View File

@ -46,7 +46,7 @@ _api.register( 'columns().header()', function ( selector, opts ) {
*
*/
_api.register( 'columns().data()', function () {
return this.iterator( true, 'column-rows', function ( settings, column, i, j, rows ) {
return this.iterator( 'column-rows', function ( settings, column, i, j, rows ) {
var a = [];
for ( var row=0, ien=rows.length ; row<ien ; row++ ) {
a.push( _fnGetCellData( settings, rows[row], column, '' ) );

View File

@ -51,7 +51,7 @@ _api.register( 'rows().data()', function ( data ) {
_api.register( 'rows().invalidate()', function ( src ) {
return this.iterator( true, 'row', function ( settings, row ) {
return this.iterator( 'row', function ( settings, row ) {
_fnInvalidateRow( settings, row, src );
} );
} );
@ -60,7 +60,7 @@ _api.register( 'rows().invalidate()', function ( src ) {
_api.register( 'rows().remove()', function () {
var that = this;
return this.iterator( true, 'row', function ( settings, row, thatIdx ) {
return this.iterator( 'row', function ( settings, row, thatIdx ) {
var data = settings.aoData;
data.splice( row, 1 );