Is there a way possible to add incrementing values when using .create for rows for differnt values

Is there a way possible to add incrementing values when using .create for rows for differnt values

Aryan1703Aryan1703 Posts: 77Questions: 20Answers: 1
 table.button().add(
            null, {
            text: 'Create Entries',
            action: function (e, dt, node, config) {
                editor
                    .create(15, {
                        title: 'Create Entry',
                        buttons: 'Add',
                        formOptions: {
                            main: {
                                onSubmit: function (e, action) {
                                    action.submit();
                                }
                            }
                        }
                    })
                    .set('editdeliveredBy', 0)
                    .set('R.createdOn', createdOn)
                    .set('R.departTime',  )
                    .submit();
                table.button(3).enable(false);
            },
        });

I am creating 15 duplicated entries over here but what i am looking for is i want to add time to R.departTime whose value should be increasing like row 1: 6:05, row 2: 6:10, row 3: 6:15 and such on till 6:45. But, the rest of the data remains same for all 15 rows

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    This example from this thread should help.

    It's uses field().multiSet() to add different values to the different record.

              editor.field( 'position' )
                .multiSet( 0, 'first' )
                .multiSet( 1, 'second' )
                .multiSet( 2, 'third' );
    

    It's only adding different strings in that example, but the same principle would apply when adding a different time offset.

    Colin

  • Aryan1703Aryan1703 Posts: 77Questions: 20Answers: 1

    Thank you, that helped. I used a loop to add differnt time

      // Loop to set departTime for each entry
                for (var i = 0; i < 15; i++) {
                    // Calculate the departTime for this entry
                    var departTime = new Date(startTime);
                    departTime.setMinutes(startTime.getMinutes() + i * increment);
                    
                    // Set departTime for this entry
                    editor.field('R.departTime').multiSet(i, departTime.getHours() + ':' + ('0' + departTime.getMinutes()).slice(-2));
                }
    
  • Aryan1703Aryan1703 Posts: 77Questions: 20Answers: 1

    Also, another thing when i press the button to create the entries the editor modal shows up for about 2-3 seconds and then disappears. Is there a way we can prevent that and just create the entries.

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    When you call create() you can tell it not to show:

    editor.create(15, false, {
      ...
    });
    

    Allan

  • Aryan1703Aryan1703 Posts: 77Questions: 20Answers: 1

    Thanks Allan! You are the best !!

Sign In or Register to comment.