How do i add multiple rows in a table using .create

How do i add multiple rows in a table using .create

Aryan1703Aryan1703 Posts: 47Questions: 11Answers: 0

I want to add 15 dummy entries when i press the button with the same value. I cannot use rows.add() function as my id in database is auto incremented so it throws an error saying row id is not defined

 table.button().add(
            null, {
            text: 'Create Entries',
            action: function (e, dt, node, config) {
                // Function to generate and submit a new entry
                var tomorrow = new Date();
                tomorrow.setDate(tomorrow.getDate() + 1);
                var tomorrowFormatted = tomorrow.toISOString().slice(0, 19).replace("T", " ");
                editor
                    .create({
                        title: 'Create Entry',
                        buttons: 'Add',
                        formOptions: {
                            main: {
                                onSubmit: function (e, action) {
                                    action.submit();
                                }
                            }
                        }
                    })
                    .set('editdeliveredBy', 0)
                    .set('R.leadLRV', '52070')
                    .set('R.trailLrv', '52070')
                    .set('R.createdOn', tomorrowFormatted)
                    .submit();
            },
        });

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin
    Answer ✓

    You can optionally pass the first parameter of create() as a row count to make it create multiple new rows. So:

    editor.create(15, {
      // ...
    

    would be the way to do what you are looking for.

    Allan

  • Aryan1703Aryan1703 Posts: 47Questions: 11Answers: 0

    Thanks, You're Awesome

Sign In or Register to comment.