How can I get the selected row data outside the table?
How can I get the selected row data outside the table?
Leo Bruno
Posts: 19Questions: 3Answers: 0
Hi:
I have a table that only acceppts 1 selection.
I´m having trouble figuring out how to get the selected row data outside the table.
console.log(table.DataTable().rows( { selected: true } ).data().toArray())
I´m receiving the entire datatset, instead of only the the selected one.
Can someone help?
Thank´s
This question has an accepted answers - jump to answer
Answers
I copied your code into this test case and it works as expected:
http://live.datatables.net/hugutaju/1/edit
You have
table.DataTable()
so i assumetable
is the jQuery selector for the HTML table, ie,$("#example")
. If this doesn't help please update the test case to replicate your issue.Kevin
This is a React JS App
I grab a reference (tableRef) and then I use the current value of the reference.
After the html table is rendered, (useEffect) I call the setUpDataTable() function that looks like this:
I haven´t figured out yet.
As mentioned before, I get always the entire dataset.
Oh, it doesn't look like you are using the Select extension. The
{selected:true}
selector-modifier
is used with the Select extension. Either use the Select extension if you want to use{selected:true}
or change to use therow-selector
as a string being the classname which is a jQuery selector.Kevin
Sorry Kevin.
I didn´t understand the last part.
"...or change to use the row-selector as a string being the classname which is a jQuery selector."
Can you explain it?
Also, I want to select the rows using double click.
Which solution would be closer to be a "native" one?
Changing the code in order to use the extension or change the function that should get the selected record?
Thank you very much in advance.
P.S. I´m javascript, react js newbie, but learning fast.
Try this:
Then you probably won't want the select extension. If what you ahve works stick with it
Kevin
It worked.
Thank you Kevin!
Hy Bruno
can you place the full coding to understand what you done?
Thans a lot