How to get values of multi selected rows
How to get values of multi selected rows
kaustubh.agrawal2000
Posts: 88Questions: 39Answers: 2
in Select
Hello,
I have a datatable created like below..
I am using select 1.2.3 plugin and I am able to select multiple rows.. but when I am trying to get the data of selected row
it only returns the first row data and not of all the rows..
receiptTable = $('#receiptModalTable').DataTable( {
dom: "RBt",
ajax: base_url + 'api/partyreceipt?' + $.param(_params),
idSrc: 'receipt_id',
select: {
style: 'multi'
},
autoWidth: false,
columns: [
{ data: "dispatch.parent_id" },
{ data: "receipt_id" },
{ data: "dispatch.dispatch_id"},
{ data: "receipt_date"},
{ data: "delivered_weight"},
],
buttons: [
{
text: 'Use Selected Receipts',
action: function ( e, dt, node, config) {
var data = receiptTable.row('.selected');
console.log(data);
//var receiptId = data['receipt_id'];
//editor.field('purchase_parent_id').val(receiptId);
//editor.field('dispatch.dispatch_id').val(data['dispatch']['dispatch_id']);
//$('#receiptModal').modal('hide');
}
}
]
});
There is no documentation related to getting data for all the rows..
Kindly help..
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
This example shows how to get multiple rows:
https://datatables.net/extensions/select/examples/api/get.html
You need to use the plural version of rows.
var data = receiptTable.rows({ selected: true });
Kevin
Hi Kevin.. that works for only single row selects..
What I needed was user should be able to select multiple rows and when he clicks a button .. data for all the selected rows should be available...
I gave up and used the following plugin..
https://www.gyrocode.com/projects/jquery-datatables-checkboxes/
Hope this helps someone..
Are you sure that you are using
rows()
rather thanrow()
?The example Kevin linked to shows that working (i.e. it gets multiple rows).
Allan
Sorry.. I missed the rows....
Thanks Kevin and Allan.