I have a grid which I need to refresh after a new record has been added or an existing record is amended.
If I call the setDataSource function the datasource is read and the grid is populated with fresh data. Unfortunately the column sort will then no longer work. It does work on first read of the data.
If I destroy the grid and recreate it the sortable columns continue to work, but then all button click handlers run multiple times, eg. second grid create they run 2x, third grid create 3x etc.
What is the correct way to refresh a grid without either breaking the sortable option or getting multiple registrations of the command handlers?
*** UPDATE ***
When the sort breaks I have found that calling setDataSource again fixes it!?
If I call the setDataSource function the datasource is read and the grid is populated with fresh data. Unfortunately the column sort will then no longer work. It does work on first read of the data.
If I destroy the grid and recreate it the sortable columns continue to work, but then all button click handlers run multiple times, eg. second grid create they run 2x, third grid create 3x etc.
What is the correct way to refresh a grid without either breaking the sortable option or getting multiple registrations of the command handlers?
*** UPDATE ***
When the sort breaks I have found that calling setDataSource again fixes it!?
Here is setDataSource that breaks sortable columns:
$(
"#dvTargetGrid"
).data(
"kendoGrid"
).setDataSource(wwit.targets.getDataSource());
Here is the grid:
try { $("#dvTargetGrid").data("kendoGrid").destroy(); }
catch (e) { }
$("#dvTargetGrid").empty();
$("#dvTargetGrid").kendoGrid({
columns: [
{ field: "Year", title: "Year", width: 45 },
{ field: "Month", title: "Month", width: 50 },
{ field: "TargetType", title: "Target Type" },
{ field: "MeasurementType", title: "Measure", width: 70 },
{ field: "Target", title: "Target" },
{ field: "TargetItem", title: "TargetItem" },
{ command: {
name: "EditT", text: "Edit",
click: wwit.targets.editTarget,
imageClass: "k-edit",
className: "k-grid-edit",
iconClass: "k-icon"
}, width: 85
},
{ command: {
name: "DeleteT", text: "Delete",
click: wwit.targets.deleteTarget,
imageClass: "k-delete",
className: "k-grid-delete",
iconClass: "k-icon"
}, width: 90
}],
sortable: true
});