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

Martyn.sMartyn.s Posts: 5Questions: 2Answers: 0

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

  • rf1234rf1234 Posts: 3,114Questions: 91Answers: 429
    edited June 10

    to a multi row / entry creation instance from one that would only create one.

    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

  • Martyn.sMartyn.s Posts: 5Questions: 2Answers: 0

    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

  • kthorngrenkthorngren Posts: 22,025Questions: 26Answers: 5,082
    edited June 10

    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 calls inlineCreate(). Use something like submitSuccess to decrement the inputted value and call inlineCreate() 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

  • allanallan Posts: 64,540Questions: 1Answers: 10,668 Site admin

    create() can indeed be used to create multiple rows at a time - it has an optional count 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

Sign In or Register to comment.