Custom edit to edit record and creat
Custom edit to edit record and creat
Description of problem:
Hi, I'm using .NET Editor 1.9.2
I need to create a custom edit button: this button must do
1. update one column for the selected row
2. open modal to edit row
3. create a new record in DB; data source is modal (point 2) whitout delete the selected row
I try to do my goal with this example:
* Customised Control Button example to update one column for the selected row
* Duplicate Button to open modal (for the new value) and to create record in DB
This is the code: it's update the desiderata colum, it's open the desiderata modal BUT when I click 'Update' modal button it's insert the new row AND delete the selected row
{
extend: "selectedSingle",
text: "Duplicate",
action: function (e, dt, node, config) {
editor
// Spengo quella che devo modificare
.edit(main_table.row({ selected: true }).index(), false)
.set('valid_to', (new Date()).toISOString().split('T')[0])
.submit();
editor
// Creo il nuovo record
.edit(main_table.row({ selected: true }).index(), {
title: 'Edit entry',
buttons: 'Update'
})
.mode('create');
}
}
Where is my error?
Thanks
This question has an accepted answers - jump to answer
Answers
I'm not seeing that here - I've taken your code and it's doing what you're describing. Could you look at that, please, and see if it helps. If it's still not working for you, please can you update my example, or link to your page, so that we can see the problem.
Cheers,
Colin
Hi @colin , thanks for the help.
It works good on client-side but on server-side it is always in edit mode: in this way the selected row is going to update with duplicate entry.
It's seem that .mode('create') doesn't change the editor behavior
The key thing to remember here is that you cannot have Editor running two operations at the same time and the operations it does perform are asynchronous, so you need to wait for one to complete before the other can happen - otherwise - well who knows what will happen!
The
subnmitComplete
can be used to handle this, or the callback option of thesubmit()
method - e.g.:Allan
Hi @allan ,
This code work like a charm!
editor.on('submitComplete', function (e, json, data, action) {
if (action === "edit") {
editor
// Creo il nuovo record
.edit(main_table.row({ selected: true }).index(), {
title: "Edit entry",
buttons: "Update",
})
.mode("create");
}
});
...But I use Soft Delete to (logical) remove the DB record.
Soft Delete works in edit mode: how can I understand if it's Duplicate or Soft Delete inside submitComplet?
Thanks
You probably need to set a variable on each action:
I'm not sure there is a better way to do it at the moment.
Allan
Thanks @allan , I've found the solution.
In my case, edit operation is a soft delete più duplicate: so I decide to hide edit button and use a custom button "Edit & Delete". In this way, first operation is soft delete; next user can edit table row with duplicate
This is "Edit & Delete" button
On submitComplete, I do this
Thanks again!