Retreive data from rows selected to update my table
Retreive data from rows selected to update my table
Hello,
I would like to select several lines and get idDelivery to update fields date, numberParcels, idReceptionist from my delivery table.
Debugger code : otoxog
When I make a first selection (click checkbox) nothing appears in the console, it is only when I make a second selection that in the console I see the different fields of the selected rows. I don't understand why during the first click nothing is displayed in the console.
And I'm not sure I'm using the right way
Regards.
Answers
You are going to have to give me a little bit more of a clue of what is being used. Ideally a link to the page showing the issue, but if that isn't possible some screenshots and the code for the DataTable.
Allan
Sorry. Forgot '''
Hell Allan,
Here is the code.
Use the
select
event to perform actions when a row is selected. Replace theclick
event on 212 with theselect
event. See this example.It might be that the
tr
click event executes before Datatables selects the row so the value ofrowLivr
is an empty array.Kevin
Hi
Thank you!
It works with :
Hi,
Now I can't manage to get the idLivraison based on the demo script here:
https://live.datatables.net/feqekoje/39/edit
I don't understand how to use/replace/place "data('id')", may I have to change id to idLivraison? I changed my td to <td id="data-id">... nothing works.
I receive an "undefined" in console.log()
Many thanks for your help.
```
table.on('select', function () {
})
```
What is
idLivraison
. Do you mean something defined withcolumns.data
like{ data: 'idLivraison-14' }
. If so then usecells().data()
instead ofcells().nodes()
.I'm not sure in what context you are referring to. Please provide more details.
Your test case seems to work.
Kevin
Maybe you are looking for something like this:
https://live.datatables.net/feqekoje/42/edit
It uses
rows().data()
to get the selected rows. Then usespluck()
to get thename
data object ( seecolumns.data
config ) followed bytoArray()
to convert the Datatables API result set to a Javascript array.Kevin
Hi kthorngren,
The test case is not from me, I just take the script code.
In this script code, it used id and #data-id and i don't see the link between the two to adapt it to my idLivraison(-14).
In the script I sent at first I use checkboxes and multi-select to get the values of idLivraison-14 (is the same as idLivraison) for each rows is selected to be abble to update the fields of the rows selected to the datatabase from the controller.
Wish it is a little clearer.
Thanks a lot for your time.
Hi Hi kthorngren,
With your big help I managed it to work, I can retreive idLivraison to console.log when checked but what append if some rows are checked and then unchecked?
Diedeer
If you want to perform an action when unchecked, ie unselected, then use the
deselect
event.Maybe you will want to perform an action on the selected rows when a button is clicked instead of each time a row is selected/deselected. See this example.
Kevin