2

in my kendo grid, I have 3 columns, balance, adjustment, and adjustment balance. adjustment balance is the total of balance and adjustment. it will be calculated. If I make a change to adjustment field. adjustment balance should automatically changed.

I am binding save event to grid.

$("#DebtGrid").data("kendoGrid").bind("save", onDebtGridEditComplete); 



function onDebtGridEditComplete(e) {

    debugger;

    var grid = $('#NonrecourseDebtGrid').data().kendoGrid;        
    var dataItem = e.model;
    e.model.set('TaxAdjustments', e.values.TaxAdjustments);

    var newBalance = getAdjBalance(dataItem.TaxBalance, e.values.TaxAdjustments);
    e.model.set('TaxAdjustmentBalance', newBalance);
    //grid.refresh();
}

I debugged the following function, I see the newBalance is calcualted and after I set the textadjustmentbalance. I checked the e.model, nothing changed. it still has the old value there.

e.model.set('TaxAdjustmentBalance', newBalance);

here's my grid.

@(Html.Kendo().Grid<LiabilityVM>()
  .Name("DebtGrid")
  .HtmlAttributes(new { style = "height: 300px;" })
  .Columns(columns =>
               {
                   columns.Bound(i => i.Id).Visible(false);
                   columns.Bound(i => i.AccountId).Visible(false);

                   columns.Bound(i => i.AccountNumber)
                       .Title("Account #")

                       .HtmlAttributes(new { nowrap = "nowrap" })
                       .Width(70);
                   columns.Bound(i => i.TaxBalance)
                       .Title("Balance")
                       .HtmlAttributes(textAlign)
                       .Width(70);
                   columns.Bound(i => i.TaxAdjustments)
                       .Title("Adjustments")
                       .EditorTemplateName("AmountEditor")
                       .HtmlAttributes(textAlign)
                       .Width(70)
                       .ClientFooterTemplate("<span><b> Total: </b></span>")
                       .FooterHtmlAttributes(textAlign);
                   columns.Bound(i => i.TaxAdjustmentBalance)
                       .Title("Adj. Balance")
                       .ClientTemplate("<span href='\\#' style='white-space:nowrap'>#= TaxAdjustmentBalance #</span>")
                       .HtmlAttributes(textAlign)
                       .Width(70)
                       .ClientFooterTemplate("#= formatAmount(getTotalAdjBalance('NonrecourseDebtGrid'), '{0:c0}') #").FooterHtmlAttributes(textAlign);
                   columns.Bound(i => i.IsSuppressed)
                       .Title("Suppress")
                       .ClientTemplate("#= showCheckBox(IsSuppressed,Source, Id) #")
                            .Width(50)
                            .Sortable(false)
                            .Filterable(false);

               })
      .Editable(editable => editable.Mode(GridEditMode.InCell))

      .DataSource(grid => grid.Ajax()
                              .Batch(true)
                              .Model(model => { 
                                                model.Id(i => i.Id);
                                                model.Field(p => p.AccountNumber).Editable(false);
                                                model.Field(p => p.TaxBalance).Editable(false);
                                                model.Field(p => p.TaxAdjustmentBalance).Editable(false);
                              })
                              .ServerOperation(true)
                              .Create(create => create.Action("Update", "test", parameters))
                              .Read(read => read.Action("Get", "test", parameters))
                              .Update(update => update.Action("Update", "test", parameters))
                              .Aggregates(aggregates =>
                                         {
                                             aggregates.Add(p => p.TaxAdjustmentBalance).Sum();
                                         })
  )
  .Sortable()
  .Filterable()
  .Selectable(s => s.Mode(GridSelectionMode.Single))
  .Resizable(resize => resize.Columns(true))
  .Reorderable(reorder => reorder.Columns(true))
  .ColumnMenu()
  .Scrollable()
  )
qinking126
  • 11,385
  • 25
  • 74
  • 124

1 Answers1

10

This is happening because you have set the field to be non-editable.

model.Field(p => p.TaxAdjustmentBalance).Editable(false);

You can try to make the field editable and create custom editor which just displays the value, so the users cant edit it.

Petur Subev
  • 19,983
  • 3
  • 52
  • 68