How to collect all data from selected rows?
How to collect all data from selected rows?

Hi! I'm very new to this so please excuse me if this has been answered before. I have this data table with multiple columns and checkbox, and Submit button below the table. Can I get help on how to collect all values in the rows with the selected checkboxes so I can send them via REST POST as JSON?
For example, here is my table
Product. Description. Type.
P1 Product 1 description A
P2 Product 2 description B
P3 Product 3 description C
P4 Product 4 description A
Let's say that I have selected P1 and P2 and click on Submit button, I would like to have a json as followed
{
{"Product":"P1", "Description":"P1 description", "Type":"A"},
{"Product":"P2", "Description":"P2 description", "Type":"B"}
}
Please help!!!
Answers
This example shows how to get the selected items.
Kevin
Thanks, I came across that example and followed the instruction as well. I'm not stuck at the part where it only seems to return the first row even though I have selected multiple row
var count = myTable.row({ checkboxes: true }).data();
If I tried this, var count = myTable.rows({ checkboxes: true }).data(); then it return all rows.
You need to use
{ selected: true }
not{ checkboxes: true }
. Userows()
to get multiple rows or userow()
for only one row.Kevin
Even I change to selected, I would see the behavior where
row() API
only return first selected row androws API
returns all rowsThat is correct - if you read over the
row()
androws()
documentation, you’ll see thatrow()
only ever returns a single row (hence the singularrow
). The pluralrows()
will return multiple rows if matched.Allan
table.rows({selected: true}).data()
will get the data for all selected rows.Allan