Editor-create-submit in the "for"
Editor-create-submit in the "for"
I need to automate the process of creating new rows in the database.
I read it:
https://editor.datatables.net/reference/api/
https://editor.datatables.net/reference/api/create()
https://editor.datatables.net/manual/api
I did this:
for (i = 1; i <= 10; i++) {
editor
.create( false )
.val( 'field', 'value_test' )
.submit();
}
table.ajax.reload();
As a result, only 1 record is created in the database!
I don't understand what's wrong?
This question has an accepted answers - jump to answer
Answers
submit()
is an async action and Editor can only perform one submission at a time. While the Ajax request is going on for the first time around the loop, the Javascript will quickly spin over the other items in the loop but Editor won't be able to process them.For this sort of thing it is much better to use multi-row editing (creation in this case). The requests will all be grouped together and submitted as a single Ajax call - e.g.:
Allan
It's okay! Thanks, Allan!