Trying to change single create editor instance to multi entry creation based on field value
Trying to change single create editor instance to multi entry creation based on field value
Hello everyone,
As the title says, I'm trying to figure out if I can change an editor instance created with the .create() function to a multi row / entry creation instance from one that would only create one.
Is this possible? I've tried looking through documentation and I am still not sure. Many thanks!
Answers
What does this really mean? Do you want to create multiple identical rows? How many and why? What is your use case in terms of desired business outcome?
Have you read this?
https://editor.datatables.net/manual/multi-row#Create-new-rows
Not multiple identical rows, but each row would have a different identifier / serial number. I'm trying to let the user select the quantity of how many entries they want with an input field, and then adjust the form to create that many entries into the database, each with a different serial number (i.e 001-1-1, then 001-1-2, etc). Otherwise, the multiple entries will remain the same.
This is to allow for the capacity to bulk add as many new serial numbers to the database as the user wants without needing to go back and refill the form over and over again
Possibly use
inlineCreate()
to create rows in the current table. They will need to be added one at a time. Your input to choose the number of rows to add can trigger an event handler that callsinlineCreate()
. Use something likesubmitSuccess
to decrement the inputted value and callinlineCreate()
if needed. I built a simplistic example showing this:https://live.datatables.net/guwafemu/621/edit
Also see this example.
There may be other better options/solutions that others might provide.
Kevin
create()
can indeed be used to create multiple rows at a time - it has an optionalcount
parameter that can be passed in.If the sequence is created client-side based on user input, have it throw up the form as normal then use
initSubmit
with the multi-row editing API to set the values.If it is a database generated sequence, even better - just submit the form as normal and the server-side scripts will insert the rows indicated.
I use exactly this approach for the booking of a Village Hall that I help run when we have repeating events (weekly classes).
Allan