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

Grid Batch Editing

1 Answer 141 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 31 Oct 2013, 03:27 AM
I am using the Kendo Grid Batch Editing Tool. I do not want to use the create button. I want to save(create) the records if the do not exist and if they do exist I want to update the records.

This should all be performed under the update function.

Basically I want to combine the following lines of code somehow:

xxx.Entry(entity).State = EntityState.Added;
xxx.Entry(entity).State = EntityState.Modified;

1 Answer, 1 is accepted

Sort by
0
Vladimir Iliev
Telerik team
answered on 01 Nov 2013, 10:15 AM
Hi Michael,

 
You can achieve the desired behavior in the following way: 

  • Define toolbar template:
    toolbar: "<a href='javascript: void(0)' onclick='createOrUpdateRow()' title='button create'>button create/save</a>", 
  • Define "createOrUpdateRow" function: 
    function createOrUpdateRow() {
        grid = $("#Grid").data("kendoGrid");
     
        //check if Grid contains not saved records then save changes:
        var data = grid.dataSource.view();
        for (var i = 0; i < data.length; i++) {
            if (data[i].isNew()) {
                grid.saveChanges();
                return;
            }
        }
     
        //if no new records are available create one
        grid.addRow();
    }
Regards,
Vladimir Iliev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Michael
Top achievements
Rank 1
Answers by
Vladimir Iliev
Telerik team
Share this question
or