I have an issue where a grid's datasource hasChanges function is not working in IE, but does work in Chrome.
When leaving the page, I check to see if there are changes to the grid's data source, and if there are changes I prompt to make sure they want to leave with unsaved changes. In this example, I save changes successfully and the hasChanges still returns true after the save is complete.
Controller update function:
[AcceptVerbs(HttpVerbs.Post)]
public
ActionResult Minimum_Create([DataSourceRequest] DataSourceRequest request, [Bind(Prefix =
"models"
)]IEnumerable<MinimumsViewModel> records)
{
try
{
CDIWholesaleServiceClient client =
new
CDIWholesaleServiceClient();
if
(records.Any())
{
foreach
(var record
in
records)
{
record.contractID =
int
.Parse(Request[
"globalContractID"
]);
var input = WholesaleDataMapper.ConvertMinimumRate(record);
var output = client.InsertMinimumRate(input);
record.id = output.MinimumID;
}
}
return
Json(records.ToDataSourceResult(request, ModelState));
}
catch
(Exception ex)
{
ModelState.AddModelError(
"Minimum Creation Error"
, ex.Message);
return
Json(records.ToDataSourceResult(request, ModelState));
}
}
Client Code:
function
goodbye(e) {
var
minimumsGrid = $(
'#MinimumsGrid'
).data().kendoGrid;
if
(minimumsGrid.dataSource.hasChanges()
) {
LeavingUnsavedNotify(e);
}
}
window.onbeforeunload = goodbye;
@(Html.Kendo().Grid<WholesaleWeb.Models.MinimumsViewModel>(Model.minimums)
.Name(
"MinimumsGrid"
)
.Columns(columns =>
{
columns.Command(command => command.Destroy()).Width(90);
columns.ForeignKey(x => x.timeUnitID, Model.minimumsTimeUnits,
"Key"
,
"Value"
).Title(
"Time Unit"
).Width(100);
columns.ForeignKey(x => x.qtyTypeID, Model.minimumsQtyTypes,
"Key"
,
"Value"
).EditorTemplateName(
"MinimumsQuantityType"
).Title(
"Qty Type"
).Width(100);
columns.ForeignKey(x => x.unitID, Model.minimumsByTypes,
"Key"
,
"Value"
).EditorTemplateName(
"MinimumsBy"
).Title(
"By"
).Width(100);
columns.Bound(x => x.minDollarAmt).EditorTemplateName(
"PositiveNumber"
).Title(
"Min"
).Width(80);
columns.Bound(x => x.feePerExam).EditorTemplateName(
"PositiveNumber"
).Title(
"Fee Per Exam"
).Width(120).Editable(
"feePerExamEditable"
);
})
.Editable(editable => editable.Mode(GridEditMode.InCell))
.Pageable()
.Navigatable()
.Reorderable(reorder => reorder.Columns(
true
))
.Sortable()
.Scrollable()
.Editable(editable => editable.DisplayDeleteConfirmation(
true
))
.Resizable(resize => resize.Columns(
true
))
.ToolBar(toolbar =>
{
toolbar.Create();
})
.DataSource(dataSource => dataSource
.Ajax()
.Batch(
true
)
.PageSize(10)
.ServerOperation(
false
)
.Events(events => events.Error(
"error_handler"
).RequestEnd(
"MinimumRates_End"
))
.Model(model =>
{
model.Id(x => x.id);
})
.Create(create => create.Action(
"Minimum_Create"
,
"Wholesale"
).Data(
"getGlobalContractID"
))
.Update(update => update.Action(
"Minimum_Update"
,
"Wholesale"
).Data(
"getGlobalContractID"
))
.Destroy(destroy => destroy.Action(
"Minimum_Destroy"
,
"Wholesale"
).Data(
"getGlobalContractID"
))
)
.HtmlAttributes(
new
{ style =
"width:100%"
})
)