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

find neighboring cell values during batchEditCellValueChanged

1 Answer 169 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Austin
Top achievements
Rank 1
Austin asked on 18 May 2015, 05:20 PM

I have a batch edit grid, using 'cell' edit mode.  I have subscribed to the 'batchEditCellValueChanged' client side event.  I'm having extreme difficulty in finding out how to get the cell values from other cells in the same row.  The example is I have an 'amount' column where I want to add/subtract the entered amount into a selective total field outside the grid based on the ddl value from another cell in that same row.

 

One major issue I came across is that adding new rows to the grid causes the index number obtained from 'args.get_row().rowIndex' does not then match up with the order of rows listed from the 'grid.get_masterTableView().get_dataItems()' method call... this issue having already been pointed out in another post, the result of which was the information passed on to Telerik dev team.

 

Based on this information, how do I get other cell values from the same row during the 'batchEditCellValueChanged' event?

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 21 May 2015, 12:52 PM
Hello Austin,

Within the OnBatchEditCellValueChanged event of the grid you can use the row's ID to get reference to the dataItem corresponding to that row. Once you have a reference to the dataItem you can use the get_cell(columnUniqueName) method for getting reference to the cell of a particular column and finally, use the BatchEditingManager getCellValue(cell) method for retrieving the value of that cell.

For your convenience, following is a simple example demonstrating such implementation:
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
    <script type="text/javascript">
        function pageLoad() {
            //force the initialization of the data items
            $find("<%=RadGrid1.ClientID%>").get_masterTableView().get_dataItems();
        }
 
        function batchEditCellValueChanged(sender, args) {
            var batchManager = sender.get_batchEditingManager();
            var dataItem = $find(args.get_row().id);
 
            var idCell = dataItem.get_cell("ID");
            var idValue = batchManager.getCellValue(idCell);
            alert(idValue);
        }
    </script>
</telerik:RadCodeBlock>
 
<telerik:RadGrid runat="server" ID="RadGrid1" OnNeedDataSource="RadGrid1_NeedDataSource">
    <MasterTableView EditMode="Batch">
    </MasterTableView>
    <ClientSettings>
        <ClientEvents OnBatchEditCellValueChanged="batchEditCellValueChanged" />
    </ClientSettings>
</telerik:RadGrid>

And the dummy data:
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    DataTable table = new DataTable();
    table.Columns.Add("ID", typeof(int));
    table.Columns.Add("FirstName", typeof(string));
    table.Columns.Add("LastName", typeof(string));
    table.Columns.Add("Age", typeof(int));
    table.Columns.Add("Date", typeof(DateTime));
    table.Columns.Add("BoolValue", typeof(Boolean));
    for (int i = 0; i < 5; i++)
    {
        table.Rows.Add(i, "FirstName" + i, "LastName" + i, 20 + i, DateTime.Now.AddDays(i), i % 2 == 0);
    }
 
    (sender as RadGrid).DataSource = table;
}

Hope this helps.


Regards,
Konstantin Dikov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Austin
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or