angular-datatables icon indicating copy to clipboard operation
angular-datatables copied to clipboard

Question v0.4.3: how to get several selected rows

Open nemcuon opened this issue 10 years ago • 2 comments

Dear all,

with the .withOption('select', true) I can select multiple rows, using Ctrl or Shift, because it would enable the underlying jquery datatable's Select plugin https://datatables.net/extensions/select/

Now the question is: how can I get the selected rows ?

I know that the methods mentioned at https://github.com/l-lin/angular-datatables/issues/21 are deprecated (no dt-rows nor TableTools is supported with version 0.4.3), and I know that the angular-datatables method

withOption('rowCallback', function (nRow, aData, iDisplayIndex, iDisplayIndexFull) {}

can only work with one row. A pity !.

Thanks,

nemcuon avatar May 31 '16 07:05 nemcuon

According to the DataTable's documentation, you can fetch the data of the selected rows by calling table.rows( { selected: true } ).data();.

One example:

<button ng-click="showCase.doSomethingWithSelectedRows()>
    Do something with selected rows
</button>
<table datatable dt-options="showCase.dtOptions" dt-instance="showCase.dtInstance">
</table>
vm.dtOptions = DTOptionsBuilder.fromSource('data.json');
vm.dtInstance = {};
vm.doSomethingWithSelectedRows = function() {
    var data = vm.dtInstance.DataTable.rows( { selected: true } ).data();
    // You do your thing
};

l-lin avatar May 31 '16 09:05 l-lin

Thanks Louis,

.data() is the one I have been looking for.

nemcuon avatar May 31 '16 11:05 nemcuon