table.cells() doesn`t return cells with opts

table.cells() doesn`t return cells with opts

EgorSLEgorSL Posts: 1Questions: 1Answers: 0

Hello.
As i think, i have found some bug.
I want to get data from one column of currently selected rows, for this i try to use:

table.cells(null,1,{selected: true}).data()

But with any quantity of selected rows this returns an empty array.
I have found, that in

_api_register( 'cells()', function ( rowSelector, columnSelector, opts ) {

at lines:

var columns = this.columns( columnSelector, opts );
var rows = this.rows( rowSelector, opts );

when I use this method, the columns variable does not return any column, the rows variable returns quantity of rows as it should be.

Due to columns=0, cells() return nothing.

I have found, that when i dont use opts like this:

var columns = this.columns( columnSelector );

It works, as it should and returns rows. But this way obviously we can`t use another options for column selection.

Another way that I have tried:

table.cells(".selected",1,null).data();

It works as it should only when I click at rows with mouse.
When I use table.rows(some selector).select(), it returns an empty array.

Thank you for attention.

Answers

  • Tom (DataTables)Tom (DataTables) Posts: 139Questions: 0Answers: 26

    When using the cells selector you are only selecting individual cells, as you are selecting rows you should use the rows() selector and then filter out the data that you need from that row, in this case you want the data from column 1.

    This might seem a little backwards, but this is because you can select individual cells as well as rows. As you can see in this example

    This is an example of how you might do that-

    var array = $('#example').DataTable().rows({selected:true}).indexes()
    $('#example').DataTable().cells(array,1).nodes()
    
    

    Thanks

    Tom

This discussion has been closed.