find neighboring cell values during batchEditCellValueChanged

2 posts, 0 answers
  1. Austin
    Austin avatar
    13 posts
    Member since:
    Apr 2009

    Posted 18 May 2015 Link to this post

    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?

  2. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1793 posts

    Posted 21 May 2015 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top