在我的剑道网格中,我有 3 列,平衡、调整和调整平衡。调整平衡是平衡和调整的总和。它将被计算。如果我对调整字段进行更改。调整平衡应自动改变。
我将保存事件绑定到网格。
$("#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();
}
我调试了以下函数,我看到 newBalance 被计算,并且在我设置了 textadjustmentbalance 之后。我检查了 e.model,没有任何改变。它仍然具有旧的价值。
e.model.set('TaxAdjustmentBalance', newBalance);
这是我的网格。
@(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()
)