changeCellValue when paging in Batch Edit mode

3 posts, 1 answers
  1. Sébastien
    Sébastien avatar
    12 posts
    Member since:
    Apr 2016

    Posted 27 Sep Link to this post

    Hi,

    Using the RadGrid in Batch Editing mode and the EditType is set to row.

    I use pagination and to avoid to loose data when I navigate between pages, I save the data on the client in "sessionStorage" (See Attach file). 

    I try to use the function "changeCellValue" in event "OnGridCreated" but it doesn't work.

    Question: Which event schould I use to set the cells from grid with the values from the sessionStorage, please ? or should I use another method ?

    Thank you

    function GridCreated(sender, eventArgs) {
     
        var values = JSON.parse(sessionStorage.getItem("editedValues"));
        if (values) {
            var masterTable = sender.get_masterTableView();
            var batchEditingManager = sender.get_batchEditingManager();
            var rows = masterTable.get_dataItems();
            for (var i = 0; i < rows.length; i++) {
                var row = rows[i];
                var mandant = row.get_element().cells[0].innerHTML;
                for (var key in values) {
                    var id = key.split("#");
                    if (id[0] == mandant) {
                        var cell = row.get_cell(id[1]);
                        batchEditingManager.changeCellValue(cell, values[key]);
                    }
                }
            }
        }
    }

  2. Sébastien
    Sébastien avatar
    12 posts
    Member since:
    Apr 2016

    Posted 29 Sep in reply to Sébastien Link to this post

    I solved the problem by moving the above code in a function and calling this function, still in the event "OnGridCreated", but as follows:

    @Telerik Team: it is correct or do you recommend another method ?

    function GridCreated(sender, eventArgs) {
        setTimeout(function () { LoadDataSessionStorage(sender, eventArgs); }, 10);
    }
                       
    function LoadDataSessionStorage(sender, args) {
        var values = JSON.parse(sessionStorage.getItem("editedValues"));
        if (values) {
            var masterTable = sender.get_masterTableView();
            var rows = masterTable.get_dataItems();
            var batchEditingManager = sender.get_batchEditingManager();
            var row = null;
            var mandant = null;
            var id = null;
            var cell = null;
            for (var i = 0; i < rows.length; i++) {
                row = rows[i];
                mandant = row.get_element().cells[0].innerHTML;
                for (var key in values) {
                    id = key.split("#");
                    if (id[0] == mandant) {
                        cell = row.get_cell(id[1]);
                        batchEditingManager.changeCellValue(cell, values[key]);
                    }
                }
            }
        }
    }

    Now, I'm facing another problem: when I edit several pages and I click on the button "OK" outside the grid, the "batchEditingManager" contains only the values from the current page. My question is: Is there a client-side function to add values to the "batchEditingManager" ?

    Thank you

    Sebastien

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Answer
    Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1800 posts

    Posted 30 Sep Link to this post

    Hi Sébastien,

    It is not possible to pass changes from other pages through the built-in functionality of the Batch editing, because each change will contain the index of the item on the current page. The only thing that I could suggest is to set the changes that you are storing in a HiddenField for example and initiate the saving through external button. On server-side you can deserialize the values and perform manual updates.

    I would personally recommend that you force the end user to save the changes before performing any data operation (like paging, filtering, sorting, etc.).


    Best Regards,
    Konstantin Dikov
    Telerik by Progress
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Back to Top