Select multiple cells from selected rows

Select multiple cells from selected rows

FranciscoSouzaFranciscoSouza Posts: 8Questions: 2Answers: 0

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

  • kthorngrenkthorngren Posts: 21,181Questions: 26Answers: 4,924
    Answer ✓

    I have tried using cells() api but it only returns objects

    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

  • rf1234rf1234 Posts: 2,950Questions: 87Answers: 416
    Answer ✓

    This makes an array and converts it into a comma separated string.

    ....
    var str = table.cells('.selected', 5).data().toArray().toString();
    
  • FranciscoSouzaFranciscoSouza Posts: 8Questions: 2Answers: 0

    @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!

This discussion has been closed.