This is a migrated thread and some comments may be shown as answers.

Grid custom popup edit form won't always save

2 Answers 392 Views
Grid
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 17 Aug 2015, 10:15 PM

I have a grid, which shows a number of details, including a list of email addresses.  This data comes from a stored proc.  In my custom edit form, I show a grid with email addresses, which are loaded via AJAX ( from the table that stores them, one per row ).  If I only edit this list, then the grid does not save anything.

I did read up on this, and found this code below.

This 'works' but, the dirty flag is ALWAYS false, so, no matter what, it saves.  This means if the built in functionality does a save, it all gets saved twice.  What is the *proper* way to force the grid to save changes after the edit dialog is changed ? I am hoping for something I can set, when the user changes the email list, which will never result in two 'save' calls to the server.

 Thanks

     

e.container.data("kendoWindow").bind("close", function (a, b, c) {
 
               // This actually sucks.  We can't make it work nicely when we have our own UI, so we just need to force it to always save.
               var uid = this.element.closest("[data-role=window]").data("uid");
 
               var dataSource = $("#adminGrid").data("kendoGrid").dataSource
               //get the model from the dataSource
               var model = dataSource.getByUid(uid);
 
               if (!model.dirty)
               {
                   model.dirty = true;
                   dataSource.sync();
               }
           })

 

2 Answers, 1 is accepted

Sort by
0
Accepted
Daniel
Telerik team
answered on 19 Aug 2015, 03:12 PM
Hello John,

If the main grid model should be saved when there changes only in the address grid then I would suggest to use the addresses grid dataSource change event to set the model dirty field to true. For example using the grid edit event:
function onEdit(e) {
    var model = e.model;
    $('#AddressesGridID').data("kendoGrid").dataSource.bind("change", function (e) {
        if (e.action) {
            model.dirty = true;
        }
    });
}




Regards,
Daniel
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
John
Top achievements
Rank 1
answered on 21 Aug 2015, 04:47 AM
Thank you Daniel, that works perfectly.
Tags
Grid
Asked by
John
Top achievements
Rank 1
Answers by
Daniel
Telerik team
John
Top achievements
Rank 1
Share this question
or