Select multiple cells from selected rows
Select multiple cells from selected rows
Hi,
I'm using datatables but my code is all in c#, trying to send information from the datatable to the code behind, but the objects are not helping. After some research I'm able to get the first value from the cell that has been selected with:
let selectedCells = table.cell('.selected', 5).data();
This only gets me the first selected cell, how can i choose the second one in case multiple rows were selected?
I have tried using cells() api but it only returns objects and i'm not able to send it to c# cause it just wont work.
My ideia is to create a string with all the cells that were selected and then send that to the code behind, something like this:
let size = table.rows('.selected').data().length;
for (let i = 0; i < size; i++) {
var d = table.cell('.selected', 5, i).data();
}
Considering that i'm able to select any cell with that "i".
This question has accepted answers - jump to:
Answers
You can chain
toArray()
to get an array of just the data. Let us know if that works or if you still need help. Maybe you can provide a simple test case showing what you are trying to do so we can help with the code.Kevin
This makes an array and converts it into a comma separated string.
@kthorngren @rf1234
Thank you very much for the help.
With trial and error I managed to single out the information with:
let result = table.cells('.selected',5).data()[i];
Where i can change the i to get all the information from other selected cells.
But the Array methoed provided also worked and it's a better solution, thank you!