dynamic form import

dynamic form import

montoyammontoyam Posts: 568Questions: 136Answers: 5

I am trying to create a dynamic dataTable from an ajax call that has input boxes in the second column like in this example:
https://datatables.net/examples/api/form.html

In the example the text boxes are hard coded. Can they be created dynamically?

Also, in the example, the button grabs only the input boxes. I will need to get the row data including the inputs. Is this possible?

here is a sample I threw together:
http://live.datatables.net/tunafeti/1/edit

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,139Questions: 26Answers: 4,735
    edited February 2022 Answer ✓

    You can use columns.defaultContent or columns.render to render the inputs. If you want to populate the input with data from the row then use columns.render.

    There are lots of ways to do this depending on your needs. Generally I like to update the Datatables data cache with the input changes. I updated your test case with a columns.render function to display a text input with the default being the data for that column.

    I added an event handler for the position input that updates the Datatables cache with the changed data. I updated the Process Data button to get all the rows with rows().data(). Note the use of toArray() to turn the result into a Javascript array.

    http://live.datatables.net/tunafeti/2/edit

    Kevin

  • montoyammontoyam Posts: 568Questions: 136Answers: 5

    yes, this was awesome. thank you so much!!

Sign In or Register to comment.