Package version: 2020.1.406
We have a grid taking advantage of a client template and the onChange event to automatically save changes.
Everything works correctly if the user presses "Enter" or clicks out of the cell.
If the user uses the "Tab" key to navigate to the next cell, the onChange event fires before the value actually updates in the input.
In the onChange event, if it fires after using the tab key the value is the previous value, but hen using "enter" or clicking out of cell the values are the correct updated value.
Here is the code.
@(Html.Kendo().Grid<StubAmountsViewModel>
()
.Name("stubAmountsGrid")
.Columns(columns =>
{
//columns.Bound(c => c.AccrualHeaderId).Visible(false);
columns.Bound(c => c.CustomerNumber);
columns.Bound(c => c.BusinessUnit).Visible(false);
//columns.Bound(c => c.CustomerDescription);
columns.Bound(c => c.DataDate).Format("{0:MMM-yyyy}");
columns.Bound(c => c.JobDescription);
columns.Bound(c => c.StubAccrualValue).HtmlAttributes(new {onChange = "stubAccrualValueChange(this)"})
.ClientTemplate("<input type='text' class='numeric k-textbox k-grid-StubAccrualValue stubAccrualValueInput' min='0' step='0.01' value='#=StubAccrualValue#' style='width: 100% !important;' />");
})
.DataSource(source => source
.Ajax()
.PageSize(20)
.Model(m => m.Id(r => r.AccrualHeaderId))
.Read(read => read.Action("ReadStubAmounts", "Admin").Data("getClosedMonthData")))
.Groupable()
.Pageable(pageable => pageable
.Refresh(true)
.PageSizes(true)
.ButtonCount(5))
.Sortable()
.Events(events => events.DataBound("stubAmountsDataBound"))
)
function stubAccrualValueChange(e) {
const accrual = $("#stubAmountsGrid").data("kendoGrid").dataItem($(e).closest('tr'));
const newValue = $(e).find("input.stubAccrualValueInput").first()[0].ariaValueNow;
$.ajax({
url: '@Url.Action("UpdateStubAccrualValue", "Admin")',
type: 'POST',
data: { accrualHeaderId: accrual.AccrualHeaderId, stubAccrualValue: newValue },
cache: false,
success: function() {
//$("#stubAmountsGrid").data("kendoGrid").dataSource.read();
}
});
}