Completed
Last Updated: 19 Mar 2020 12:30 by ADMIN
gary davis
Created on: 12 May 2014 20:30
Category: Grid
Type: Feature Request
5
Add row edit locking mechanism to SignalR enabled Real-Time Grid
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.
1 comment
ADMIN
Alex Hajigeorgieva
Posted on: 19 Mar 2020 12:30

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

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.