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

RadGrid changeCellValue Index

3 Answers 249 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Nick
Top achievements
Rank 1
Nick asked on 20 Mar 2015, 12:29 AM
Sorry for the long description but it's the only way I can explain this.

I'm currently working on a RadGrid with 5 columns. On page load if there are existing rows for an invoice, they are loaded into the grid, if there are none then it creates a new one ready for batch editing. When the user fills in the Code cell and tabs to the next which is Description, I make a webmethod call to the database to get the corresponding description and want to will that into the next column. This is all working, until I add multiple rows. For some reason the indexes retrieve the rows in inverse order. For example if I create the first row, fill in Code, hit tab, Description is populated from the database. If I create another row, fill in Code, hit tab, Description in the first row updated, not two. If I change the Code in row one again, Description in row two is updated. This holds up for any number of added rows. If there are any existing rows from the database, this does not happen. I can update Code and Description is updated correctly. When I try to add new rows to a table with existing loaded from the database, the crazy index logic starts again.

Here is the javascript I am using to make the cell changes. This is called on RadGrid2_OnBatchEditCellValueChanged:
function getDescription(sender, args) {
                var grid = $find('<%= RadGrid2.ClientID %>');
                var masterTable = grid.get_masterTableView();
                var rows = masterTable.get_dataItems();
                var rowArgs = args.get_row();
                var rowIndex = rowArgs.sectionRowIndex;
                var row = rows[rowIndex];
                var newValue = args.get_editorValue();
 
                var lineDescCell = row.get_cell("Description");
                var lineDesc = sender.get_batchEditingManager().getCellValue(lineDescCell);
 
                $.ajax({
                    type: "POST",
                    url: "Invoice.aspx/LookupCode",
                    data: JSON.stringify({ code: newValue }),
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (msg) {
                        lineDesc = (!msg || !msg.d) ? "Invalid Code" : msg.d;
                        grid.get_batchEditingManager().changeCellValue(lineDescCell, lineDesc);
                    },
                    error: function (response) {
                        alert('LookupCode failed: ' + response);
                    }
                });
            }

If I can provide any extra explanation or code please let me know. Any help on this issue would be much appreciated.

Nick

3 Answers, 1 is accepted

Sort by
0
Angel Petrov
Telerik team
answered on 24 Mar 2015, 02:00 PM
Hello Nick,

I am not sure what exactly causes this problem but it may be due to the way the row index is extracted. Please try modifying the code as demonstrated below and test the page again.

JavaScript:
function getDescription(sender, args) {
    var grid = $find('<%= RadGrid2.ClientID %>');
    var masterTable = grid.get_masterTableView();
    var rows = masterTable.get_dataItems();
    var rowArgs = args.get_row();
    var rowIndex = $find(rowArgs.id).get_itemIndexHierarchical();
    var row = rows[rowIndex];
    var newValue = args.get_editorValue();
 
    var lineDescCell = row.get_cell("Description");
    var lineDesc = sender.get_batchEditingManager().getCellValue(lineDescCell);
 
    $.ajax({
        type: "POST",
        url: "Invoice.aspx/LookupCode",
        data: JSON.stringify({ code: newValue }),
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
            lineDesc = (!msg || !msg.d) ? "Invalid Code" : msg.d;
            grid.get_batchEditingManager().changeCellValue(lineDescCell, lineDesc);
        },
        error: function (response) {
            alert('LookupCode failed: ' + response);
        }
    });
}

If this does not prove helpful please share with us the page markup and code-behind so we could examine the implementation.

Regards,
Angel Petrov
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
Nick
Top achievements
Rank 1
answered on 25 Mar 2015, 01:13 AM
Hi Angel, thank you for the response.

I ran out of time to solve this issue, but found a work around. By changing the MasterTableView-CommandItemDisplay from Bottom to Top, the issue went away. This is not ideal as the client wanted it at the bottom, but it's working for now.

Nick
0
Nick
Top achievements
Rank 1
answered on 25 Mar 2015, 01:14 AM
Sorry looks like I can't edit my post.

That should be MasterTableView-InsertItemDisplay set to Top.
Tags
Grid
Asked by
Nick
Top achievements
Rank 1
Answers by
Angel Petrov
Telerik team
Nick
Top achievements
Rank 1
Share this question
or