This is a migrated thread and some comments may be shown as answers.

changeCellValue when paging in Batch Edit mode

2 Answers 46 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sébastien
Top achievements
Rank 1
Sébastien asked on 27 Sep 2016, 03:04 PM

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 Answers, 1 is accepted

Sort by
0
Sébastien
Top achievements
Rank 1
answered on 29 Sep 2016, 11:35 AM

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

0
Accepted
Konstantin Dikov
Telerik team
answered on 30 Sep 2016, 08:21 AM
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.
Tags
Grid
Asked by
Sébastien
Top achievements
Rank 1
Answers by
Sébastien
Top achievements
Rank 1
Konstantin Dikov
Telerik team
Share this question
or