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

[Solved] KendoGrid Save Event causing controller to be called twice

2 Answers 727 Views
Grid
This is a migrated thread and some comments may be shown as answers.
bobthecoder
Top achievements
Rank 1
bobthecoder asked on 14 Apr 2015, 04:42 PM

01.
 .Events(e =>
02.                    {
03.                        e.DataBound("onDetailsGridDataBound");
04.                        e.Edit("onRowEdit");
05.                        e.Save("fieldChanged");
06......more grid stuff
07.                    })
08.                    .Editable(editable => { editable.Mode(Kendo.Mvc.UI.GridEditMode.InCell);
09.                                                     editable.DisplayDeleteConfirmation("Are you sure you want to  delete this line item");
10.                    })

I added an event call on Save to call a javascript function, so I can determine whcih cell the user changed, as I need this in the controller for a calcuation where the changed field takes precedence. However when I used the e.model.set('TriggeringField', 'whateverFieldWaschanged'); this causes the controller to be called twice, which I can't live with as it will cause the back end auditing to log the event twice. When I put in e.PreventDefault in the JS method, then the controller is not called at all. How do I get my controller called just ONCE, AND supply the name of the field that was changed. Nolte as above I am using Incell editing.

1.function fieldChanged(e) {
2.              var colindex = e.container[0].cellIndex;
3.              if (colindex==8)
4.                  e.model.set('TriggeringField', 'UnitPrice');
5.              if (colindex == 9)
6.                  e.model.set('TriggeringField', 'DiscountPercentage');
7. 
8.          }

2 Answers, 1 is accepted

Sort by
0
bobthecoder
Top achievements
Rank 1
answered on 14 Apr 2015, 04:47 PM

I should have added the following snippet to my question

.ServerOperation(false)
                        .Group(groups => groups.Add(p => p.yy)).AutoSync(true)
                         .Aggregates(aggregates => aggregates.Add(p => p.uuu).Sum())
                        .Read(read => read.Action("I_read", "sdfs", new {IDfield=Model}))
                        .Update(update => update.Action("I_Update", "Inv" ))
                         .Destroy(destroy => destroy.Action("I_Destroy", "Inv"))
                    )

0
bobthecoder
Top achievements
Rank 1
answered on 14 Apr 2015, 10:44 PM
function fieldChanged(e) {
               var colindex = e.container[0].cellIndex;
               var grid = $("#gridLine").data("kendoGrid");
               var selectedItem = grid.dataItem($(e.container).closest("tr"));
               if (colindex == 8)
               //e.model.set('TriggeringField', 'UnitPrice');
                   selectedItem.TriggeringField = 'UnitPrice';
               if (colindex == 9)
                   selectedItem.TriggeringField = 'DiscountPercentage';
                  // e.model.set('TriggeringField', 'DiscountPercentage');
 
           }
OK I fixed this by not using the e.model.set feature and instead just set the value directly on the selectedItem as above
Tags
Grid
Asked by
bobthecoder
Top achievements
Rank 1
Answers by
bobthecoder
Top achievements
Rank 1
Share this question
or