When performing Edit on a real-time grid, hide edit button to prevent simultaneous editing and data overwrite. There was a similar solution previous to signalR integration, http://www.telerik.com/forums/using-kendoui-grid-with-signalr#-3DZMT4HHE-rOWdEf_1mgQ But with SignalR enabled grid, this could all be built-in.
Hello, Gary,
The solution provided in the forum thread can be used to lock and unlock the rows for editing:
Project available at: http://www.telerik.com/forums/using-kendoui-grid-with-signalr#-3DZMT4HHE-rOWdEf_1mgQ
<script>
var lockedRecords = {};
var productHub = {};
var hubStart = {};
$(function () {
productHub = $.connection.productHub;
productHub.client.lockRecord = function (record) {
lockedRecords[record.id] = true;
};
productHub.client.unlockRecord = function (record) {
lockedRecords[record.id] = false;
}
hubStart = $.connection.hub.start();
$(function () {
$("[data-role=grid]").each(function () {
var grid = $(this).data("kendoGrid");
grid.table.on("click", ".k-grid-edit", function (e) {
debugger;
var item = grid.dataItem($(this).closest("tr"));
if (!lockedRecords[item.id]) {
$.connection.productHub.server.lockRecord(item.id);
}
else {
alert("Currently the record cannot be edited");
return false;
}
});
});
});
})
function edit(e) {
var model = e.model;
e.container.find(".k-grid-cancel").click(function () {
$.connection.productHub.server.unlockRecord(model.id);
});
}
function save(e) {
$.connection.productHub.server.unlockRecord(e.model.id);
}
</script>
The grid is a UI component responsible for displaying the data and the request here would require us to bind the grid and the data source and break good quality coding principles by coupling the two. It would mean adding code that verifies the grid instance is bound to a signalR data source type and so we believe it is better to use the grid events instead.
Kind Regards,
Alex Hajigeorgieva
Progress Telerik