grid save event

1 Answer 3560 Views
Grid
DHHS
Top achievements
Rank 1
DHHS asked on 26 Aug 2015, 09:38 PM

Hi,

 

I have to get the values user entered on edit in the inline grid. So I have kept save event on gird and trying to access the values on the method but I am not sure how to the get the values.

   @(Html.Kendo().Grid<BHEBS.Areas.Admin.Models.ContractBudgetModel.contractBudgetBUModel>()
        .Name("ContractBudgetBUGrid")
                 .Events(e => e.Save("onSave"))
        .Columns(columns =>
        {
            columns.Bound(p => p.Id);
            columns.Bound(p => p.BusinessUnit);
            columns.Bound(p => p.Description);       
            columns.Bound(p => p.ServiceType);
            columns.Bound(p => p.BUAuthAmt);
            columns.ForeignKey(p => p.SpendPriority, (System.Collections.IEnumerable)ViewData["SpendPriority"], "Value", "Text").Width(120);
            columns.Bound(p => p.ContractBUAmt);
            columns.Bound(p => p.BUBudgetAmt);
            columns.ForeignKey(p => p.contractSpendPriority, (System.Collections.IEnumerable)ViewData["SpendPriority"], "Value", "Text").Width(120);
            columns.Command(command =>
            {
                command.Edit().HtmlAttributes(new { @class = "btn-primary" });               
            });         
        })       
        .Pageable(pageable => pageable.Refresh(true).PageSizes(true).ButtonCount(5))      
        .Sortable()
        .Scrollable()
        .Filterable()
        .Selectable()
        .Resizable(resize => resize.Columns(true))
        .HtmlAttributes(new { style = "height:450px;" })
        .DataSource(dataSource => dataSource.Ajax().PageSize(10).Read(read => read.Action("ContractBudgetBU_Read", "ContractBudget").Data("additionalInfo"))
                                .Model(model => { model.Id(p => p.Id); model.Field(p => p.Id).Editable(false); model.Field(p => p.BusinessUnit).Editable(false); model.Field(p => p.Description).Editable(false); model.Field(p => p.ServiceType).Editable(false); model.Field(p => p.BUAuthAmt).Editable(false); model.Field(p => p.BUBudgetAmt).Editable(false); model.Field(p => p.SpendPriority).Editable(false); model.Field(p => p.contractSpendPriority).DefaultValue("Normal"); })
                        .Update(update => update.Action("Update_ContractBudgetBU", "ContractBudget"))))
 
 
 function onSave(e) {
        var data = e.values;
//I am getting error e.values is undefined.
}

 

 

Thanks,

Veena

1 Answer, 1 is accepted

Sort by
0
Kiril Nikolov
Telerik team
answered on 28 Aug 2015, 08:06 AM

Hello Veena,

 

The e.model property is what you need, as explained here:

 

http://docs.telerik.com/kendo-ui/api/javascript/ui/grid#events-save

 

Regards,
Kiril Nikolov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Veena
Top achievements
Rank 1
commented on 18 Jan 2016, 06:51 PM

Hi, 

I got the save event work. But I have a requirement where I should show a pop up message with yes or no on grid edit event and wait for the user to respond and then based on the response I should save the event or cancel the event. Message box is showing up but before i respond to the message box, the update event is triggering and going to controller method. Is there a way that i can wait till the user responds and based on the response i should save the event or cancel the event.

 

Thanks,

Veena

Boyan Dimitrov
Telerik team
commented on 20 Jan 2016, 02:46 PM

Hello Veena,

 

A possible solution is simply to prevent the save event by calling e.preventDefault(); and show the box to the user. If user wants to send the changes to the server then you can call explicitly the sync method of the Kendo UI DataSource. This will sync the changes made on the client-side with the server. 

 

 

 

Regards,
Boyan Dimitrov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Jon
Top achievements
Rank 1
Iron
commented on 04 Apr 2024, 07:41 PM

The code in the linked page (from above) does use e.values as well as e.model.  It implies that the values can be compared to the model to determine what has changed.  I'm needing this functionality, but in my MVC grid, when I save, e.values is undefined.  Any ideas why that might be?

Thanks,

Jon

Mihaela
Telerik team
commented on 08 Apr 2024, 04:48 PM

Hi Jon, 

The "values" property is available when the Grid is in InCell edit mode. If the Grid is configured for InLine or Popup editing, the "values" property will be "undefined":

You can use the "e.model.dirtyFields" property that indicates which fields have changed.

Best,

Mihaela

 

Jon
Top achievements
Rank 1
Iron
commented on 08 Apr 2024, 04:50 PM

Hello Miheala,

Thanks for the clarification and the suggestion!  Works great!

Jon

Tags
Grid
Asked by
DHHS
Top achievements
Rank 1
Answers by
Kiril Nikolov
Telerik team
Share this question
or