Editor Create 2 new records simultaneously
Editor Create 2 new records simultaneously
vincmeister
Posts: 136Questions: 36Answers: 4
in Editor
Hello Allan,
Is it possible to create 2 new records simultaneously using 1 create action ?
I want to split quantity
field value into 2 new record and edit the changes
field on old record
Let's say i have this data:
ID, item_name, quantity, changes, old_id
{
"data": [
[
"1",
"book",
"100",
"0",
"0"
],
[
"2",
"pencil",
"50",
"0",
"0"
]
}
user select the row_1, and want to change the quantity from 100 to 60
my scenario:
- user input the new
quantity
(let's say 60) - editor on hidden field, set default value for the rest field by duplicating data from row_1
- user click create button, editor will create 2 new rows like example data below (row_4 and row_5)
- on php, postCreate will update the row_1, field
changes
to 1 (like my question here )
->on('postCreate',function( $editor, $id, $values, $row ) {
$editor->db()
->query('update', 'tr_receiving_detail')
->set('changes', 1)
->where('id', $values['tr_receiving_detail']['old_id'])
->exec();
})
The data will be:
{
"data": [
[
"1",
"book",
"100",
"1",
"0"
],
[
"2",
"pencil",
"50",
"0",
"0"
],
[
"3",
"book",
"60",
"0",
"1"
],
[
"4",
"book",
"40",
"0",
"1"
]
}
Please advise, thank you
Danny
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Yes it is possible for Editor to create multiple rows using the
create()
but this is API only.In this case it looks like what you want to do is using the
postCreate
function again and insert the row using that.After this you would need to use
ajax.reload()
in order to show the extra row.Thanks
Tom
Hello Tom,
How to call the postCreate function again? I already using postCreate to update, as i mention on number 4 above. Maybe link for example or reference
Please advise, thank you
danny
Two options:
->on( 'postCreate', function ... )
to your Editor instance. Like in Javascript you can listen for the same event multiple timesAllan
Hello Allan & Tom
I've got an error
Uncaught TypeError: Cannot read property 'replace' of undefined dataTables.editor.min.js:66
when i click theCreate
buttonHere's my code:
I'm using a create button to submit the new 2 rows
This is the trDOEditEditor, user only fill the New Quantity field
Populate init value for the editor's field
when user click submit button, 2 records will create with 2 different data on
tr_receiving_detail.quantity
field.1st value from the user input
2nd value from original quantity - 1st value
I'm using this code to genereate the 2nd value
my php:
Please advise, thank you
Danny
Hi Danny,
Can you link to the page showing the issue so we can attempt to debug it please. It sounds like the Javascript error is occurring from the JSON return, but really I'm not sure without being able to see it.
If you comment out the second
postCreate
so that stop thereplace
error from occurring?Allan
Hi Allan,
Here's the live link
Step:
1. Select Delivery Order
2. Select a line from the loaded data
3. Click Edit Lines Button
4. Fill the new quantity
Pleas advise, thank you
Thanks for the link. Could you use the non-min version of Editor please? The page is taking about 5 minutes to load at the moment, so I'll try to debug it later.
Allan
hello Allan
please try this link
load time problem maybe from the IX server problem
Thanks - that's much faster.
The issue is that although the "Edit" button is clicked on a "Create" form is shown (demonstrated by the form title: Create new entry). In your Editor initialisation you have:
Nothing about
create
, which is the mode the form is in, hence the error.I'm not sure if the bug is that
create
should be specified or if the form should be put into edit mode.Allan
Hi Allan,
Thanks for the correction. Changing edit to create, no error, but still no result as expected. Please take a look, thank you
No data is being returned from the server:
I can only presume that is due to a
where
condition being applied to the table. When Editor creates a new row (as it is being instructed to do here) it should automatically read that new row and return the values to the client-side.Allan
Hi Allan,
Thanks for the clue
The problem is on the select2 filter value so the data return []
I add ajax data on editor
d.kode_distro = $("#SelectDO").val();
and works perfectly as i expected. It's solves now. You're the best Many thanksDanny