Updating option when using datatable as an input.
Updating option when using datatable as an input.
![MustangProgrammer](https://secure.gravatar.com/avatar/1fae0715539ce3ffd941b890483f1e14/?default=https%3A%2F%2Fvanillicon.com%2F1fae0715539ce3ffd941b890483f1e14_200.png&rating=g&size=120)
I'm using datatables as an input, and when I add or delete a record I want to update the datatable I'm using as an input's options to reflect changes to the array of objects I'm using to populate that input.
Here is the input into the editor:
{
label: "Search People",
name: "user_email",
type: "datatable",
multiple: true,
options: usersForFillNoteEditor,
config: {
paging: true,
columns: [
{
title: "Select Person",
data: "label",
},
],
lengthMenu: [25],
select: {
info: true,
},
},
}
usersForFillNoteEditor
is the array of objects I'd like to update.
Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
This question has an accepted answers - jump to answer
Answers
field().update()
is probably the method to use here. Pass in the updated array and it will redraw the table with the new data. The DataTable isn't "responsive" to the data - it doesn't look for changes manually, you need to tell it that data has changed and it should update.The other option is to use the
field().dt()
method that is part ofdatatable
to get the DataTable instance and update the data of the specific row that has changed. This is perhaps more efficient in terms of clock cycles, but will involve more work. I'd stick withfield().update()
.Allan
As always, thanks Allan. I was hunting around and didn't grasp that the field().update() would update the option.