# DataGrid Inline Editing Losing Focus

**URL:** <https://forum.radzen.com/t/datagrid-inline-editing-losing-focus/18487>\
**Category:** Radzen.Blazor Components\
**Created:** [September 17, 2024, 12:16pm UTC](https://forum.radzen.com/t/datagrid-inline-editing-losing-focus/18487 "2024-09-17T12:16:17Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Robot](https://forum.radzen.com/letter_avatar_proxy/v4/letter/r/7993a0/32.png) [@Robot](https://forum.radzen.com/u/Robot)\
**Post date:** [September 17, 2024, 12:16pm UTC](https://forum.radzen.com/t/datagrid-inline-editing-losing-focus/18487/1 "2024-09-17T12:16:18Z")

</div>

Hi,

In my application, I am using 2 data grids in one another like master-detail. In detail, I am using inline editing like in your [DataGrid InLine Editing](https://blazor.radzen.com/datagrid-inline-edit).

If I click to edit a row let's say on the third page, edited data is saved but it loses focus on the third page and gets back to the first page. I tried many things but couldn't find a way to keep the focus on the page where the data is edited. Or it is even perfect if I somehow keep the detail expanded.

Here is the sample screenshot that I am facing:  
[Datagrid screenshot](https://streamable.com/80zxa9)

Here is the simplified code:

```auto
<RadzenDataGrid @ref="_grid" AllowFiltering="true" AllowPaging="true" PageSize="20" AllowSorting="false" RowClick="RowClick" ExpandMode="DataGridExpandMode.Single"
                Data="@_ordersDto" TItem="OrderDto" EditMode="DataGridEditMode.Single" RowUpdate="@OnUpdateRow" RowCreate="@OnCreateRow" @bind-Value="@SelectedOrders"
                ShowExpandColumn="false" ShowPagingSummary="true" AllowColumnResize="true" >
<Template Context="order">
<RadzenCard Style="margin-bottom: 20px">
    Customer:
    <b>@order?.Customer?.Name</b>
</RadzenCard>
<RadzenTabs>
<Tabs>
<RadzenTabsItem Text="Order Details">

<RadzenDataGrid @ref="_gridDetail" AllowFiltering="@(_detailToInsert == null)" AllowPaging="true" PageSize="5" AllowSorting="@(_detailToInsert == null)" Data="@order.OrderDetailsDto"
                TItem="OrderDetailDto" EditMode="DataGridEditMode.Multiple" RowUpdate="@OnUpdateRowDetail" RowCreate="@OnCreateRowDetail" AllowColumnResize="true"
                                    AllowColumnPicking="true" ShowPagingSummary="true" ColumnWidth="150px" Density="Density.Compact" >
<Columns>

<RadzenDataGridColumn TItem="OrderDetailDto" Property="ProductCode" Title="Product Code" OrderIndex="2">
    <EditTemplate Context="orderDetail">
        <RadzenTextBox @bind-Value="orderDetail.ProductCode" Style="width: 100%; display: block" Name="ProductCode" />        
    </EditTemplate>
</RadzenDataGridColumn>
<RadzenDataGridColumn TItem="OrderDetailDto" Property="Quantity" Title="Quantity" OrderIndex="7">
    <EditTemplate Context="orderDetail">
        <RadzenNumeric TValue="int" Min="1" @bind-Value="orderDetail.Quantity" Style="width: 100%; display: block" Name="Quantity"/>        
    </EditTemplate>    
</RadzenDataGridColumn>
<RadzenDataGridColumn TItem="OrderDetailDto" Property="CostRatio" Title="Cost Ratio" OrderIndex="10">
    <EditTemplate Context="orderDetail">
        <RadzenNumeric TValue="double" Min="0" @bind-Value="orderDetail.CostRatio" Style="width: 100%; display: block" Name="CostRatio"/>
    </EditTemplate>
</RadzenDataGridColumn>
<RadzenDataGridColumn TItem="OrderDetailDto" Property="PoNotes" Title="PO Notes" OrderIndex="23">
    <EditTemplate Context="orderDetail">
        <RadzenTextBox @bind-Value="orderDetail.PoNotes" Style="width: 100%; display: block" Name="PoNotes"/>
    </EditTemplate>
</RadzenDataGridColumn>
<RadzenDataGridColumn TItem="OrderDetailDto" Context="orderDetail" Filterable="false" Sortable="false" TextAlign="TextAlign.Center" Width="200px" OrderIndex="24">
    <Template Context="detail">
        <RadzenButton Icon="edit" ButtonStyle="ButtonStyle.Primary" Class="m-1" Click="@(args => EditRowDetail(detail))" @onclick:stopPropagation="true" Size="ButtonSize.Small">
        </RadzenButton>
    </Template>
    <EditTemplate Context="detail">
        <RadzenButton Icon="check" ButtonStyle="ButtonStyle.Primary" Class="m-1" Click="@(args => SaveRowDetail(detail))" @onclick:stopPropagation="true" Size="ButtonSize.Small">
        </RadzenButton>        
    </EditTemplate>
</RadzenDataGridColumn>
</Columns>
</RadzenDataGrid>
</RadzenTabsItem>

</Tabs>
</RadzenTabs>
</Template>
<Columns>
    
    <RadzenDataGridColumn TItem="OrderDto" Property="Status" Title="Status" Width="100px">

    </RadzenDataGridColumn>
    <RadzenDataGridColumn TItem="OrderDto" Context="order" Filterable="false" Sortable="false" TextAlign="TextAlign.Center" Width="120px">
        <Template Context="order">
            <RadzenButton Icon="edit" ButtonStyle="ButtonStyle.Primary" Class="m-1" Click="@(args => EditRow(order))" @onclick:stopPropagation="true" Size="ButtonSize.Small">
            </RadzenButton>               
        </Template>        
    </RadzenDataGridColumn>

</Columns>
</RadzenDataGrid>

@code {
   

    IList<OrderDto?> SelectedOrders { get; set; }
    IQueryable<OrderDto?> _ordersDto;
    IQueryable<Order?> _order;   

    RadzenDataGrid<OrderDto?> _grid;
    RadzenDataGrid<OrderDetailDto> _gridDetail;

    OrderDto? _orderToInsert;
    OrderDetailDto? _detailToInsert;
    OrderDto orders;
    Order orderMap;
    OrderDetail orderDetailMap;
    
       
   
    protected override async Task OnInitializedAsync()
    {
        
        _order = ViewOrdersUseCase.Execute(user);
        _ordersDto = Mapper.ProjectTo<OrderDto>(_order);
           
        SelectedOrders = new List<OrderDto?> { _ordersDto.FirstOrDefault() };
        
    }
    
    private async Task RowClick(DataGridRowMouseEventArgs<OrderDto> mouseClick)
    {
        await _grid!.ExpandRow(mouseClick.Data);
        SelectedOrders = _ordersDto.Where(o => o.Id == mouseClick.Data.Id).ToList();

        if (SelectedOrders.Count > 0)
        {
            if (SelectedOrders[0].Status == "Completed" || SelectedOrders[0].Status == "Cancelled")
            {
                _detailToInsert = new OrderDetailDto();
            }
            else
            {
                _detailToInsert = null;
            }
        }
    }
    
    private async Task OnCreateRowDetail(OrderDetailDto? orderDetail)
    {
        if (orderDetail != null)
        {
            orderDetailMap = new OrderDetail();
            Mapper.Map(orderDetail, orderDetailMap);
                      
            var addedOrderDetail = await AddOrderDetailUseCase.ExecuteAsync(orderDetailMap);
            
                     
            await _gridDetail.Reload();
            await _grid.Reload();

        }
    }    

    private async Task OnUpdateRowDetail(OrderDetailDto orderDetail)
    {
        if (orderDetail == _detailToInsert)
        {
            _detailToInsert = null;
        }
        if (orderDetail != null)
        {
            orderDetailMap = new OrderDetail();
            Mapper.Map(orderDetail, orderDetailMap);
			//Updates in DB
            var updatedOrderDetail = await EditOrderDetailUseCase.ExecuteAsync(orderDetailMap);
            
            _orders = await ViewAllOrdersUseCase.ExecuteAsync(user);
            _ordersDto = Mapper.ProjectTo<OrderDto>(_order);
            
            await _gridDetail.Reload();
            await _grid.Reload();
            
           
        }
    }    

    async Task EditRowDetail(OrderDetailDto orderDetail)
    {
        await _gridDetail.EditRow(orderDetail);
    }     

    async Task SaveRowDetail(OrderDetailDto orderDetail)
    {
        await _gridDetail.UpdateRow(orderDetail);

        if (orderDetail.ProductCode != null)
        {
            if (orderDetail == _detailToInsert)
            {
                _detailToInsert = null;
            }
        }

        await _gridDetail.ExpandRow(orderDetail);
        StateHasChanged();

    }
   
}

```

Is there anyone who can help or guide me on this matter?

---

<div class="post-metadata">

**Author:** ![enchev](https://forum.radzen.com/user_avatar/forum.radzen.com/enchev/32/16_2.png) [@enchev](https://forum.radzen.com/u/enchev)\
**Post date:** [September 17, 2024, 12:25pm UTC](https://forum.radzen.com/t/datagrid-inline-editing-losing-focus/18487/2 "2024-09-17T12:25:49Z")

</div>

If you want to restore the current page after reload you can use the technique demonstrated here:  
[https://blazor.radzen.com/datagrid-save-settings](https://blazor.radzen.com/datagrid-save-settings)  
[https://blazor.radzen.com/datagrid-save-settings-loaddata](https://blazor.radzen.com/datagrid-save-settings-loaddata)

---

<div class="post-metadata">

**Author:** ![Robot](https://forum.radzen.com/letter_avatar_proxy/v4/letter/r/7993a0/32.png) [@Robot](https://forum.radzen.com/u/Robot)\
**Post date:** [September 17, 2024, 12:29pm UTC](https://forum.radzen.com/t/datagrid-inline-editing-losing-focus/18487/3 "2024-09-17T12:29:55Z")

</div>

Does your DataGrid InLine Editing sample use restore/reload? Because I think it is similar to my issue.

---

<div class="post-metadata">

**Author:** ![enchev](https://forum.radzen.com/user_avatar/forum.radzen.com/enchev/32/16_2.png) [@enchev](https://forum.radzen.com/u/enchev)\
**Post date:** [September 17, 2024, 12:31pm UTC](https://forum.radzen.com/t/datagrid-inline-editing-losing-focus/18487/4 "2024-09-17T12:31:58Z")

</div>

No, it's not using such technique.

---

<div class="post-metadata">

**Author:** ![Robot](https://forum.radzen.com/letter_avatar_proxy/v4/letter/r/7993a0/32.png) [@Robot](https://forum.radzen.com/u/Robot)\
**Post date:** [September 17, 2024, 12:36pm UTC](https://forum.radzen.com/t/datagrid-inline-editing-losing-focus/18487/5 "2024-09-17T12:36:15Z")

</div>

How can I do it without using restore/reload in my case?

---

<div class="post-metadata">

**Author:** ![enchev](https://forum.radzen.com/user_avatar/forum.radzen.com/enchev/32/16_2.png) [@enchev](https://forum.radzen.com/u/enchev)\
**Post date:** [September 17, 2024, 12:39pm UTC](https://forum.radzen.com/t/datagrid-inline-editing-losing-focus/18487/6 "2024-09-17T12:39:42Z")

</div>

I'm afraid that I'm not familiar enough with your case to provide you additional details.

---

<div class="post-metadata">

**Author:** ![Robot](https://forum.radzen.com/letter_avatar_proxy/v4/letter/r/7993a0/32.png) [@Robot](https://forum.radzen.com/u/Robot)\
**Post date:** [September 17, 2024, 1:05pm UTC](https://forum.radzen.com/t/datagrid-inline-editing-losing-focus/18487/7 "2024-09-17T13:05:33Z")

</div>

I would like to add this in case anyone has encountered a similar problem before. This situation does not occur in the master section. In other words, on which page I update the information in the master, it stays on that page. Hope someone in this forum can help.

---

<div class="post-metadata">

**Author:** ![Robot](https://forum.radzen.com/letter_avatar_proxy/v4/letter/r/7993a0/32.png) [@Robot](https://forum.radzen.com/u/Robot)\
**Post date:** [September 21, 2024, 1:11pm UTC](https://forum.radzen.com/t/datagrid-inline-editing-losing-focus/18487/8 "2024-09-21T13:11:56Z")

</div>

Any idea why the row does NOT expand? `_ordersDto.FirstOrDefault(o => o.Id == parentOrder.Id)` returns a valid Order.

```auto
private async Task OnCreateRowDetail(OrderDetailDto? orderDetail)
{
    if (orderDetail != null)
    {
        orderDetailMap = new OrderDetail();
        Mapper.Map(orderDetail, orderDetailMap);

        // Add the new order detail to the database
        var addedOrderDetail = await AddOrderDetailUseCase.ExecuteAsync(orderDetailMap);

        Mapper.Map(addedOrderDetail, orderDetail);
        // Find the parent order
        var parentOrder = GetParentOrder(orderDetail);

        if (parentOrder != null)
        {
            pageIndex = current_page;
            _order = ViewOrdersUseCase.Execute(user);
            _ordersDto = Mapper.ProjectTo<OrderDto>(_order);

            await _gridDetail.GoToPage((int)pageIndex);
            await _grid.ExpandRow(_ordersDto.FirstOrDefault(o => o.Id == parentOrder.Id));

            StateHasChanged();
        }
        
    }

```

---

<div class="post-metadata">

**Author:** ![Robot](https://forum.radzen.com/letter_avatar_proxy/v4/letter/r/7993a0/32.png) [@Robot](https://forum.radzen.com/u/Robot)\
**Post date:** [September 26, 2024, 12:22pm UTC](https://forum.radzen.com/t/datagrid-inline-editing-losing-focus/18487/9 "2024-09-26T12:22:55Z")

</div>

Is there a way to keep the parent row expanded after adding a row into detail? I tried many things but couldn't find a logic. @yordanov

---

<div class="post-metadata">

**Author:** ![enchev](https://forum.radzen.com/user_avatar/forum.radzen.com/enchev/32/16_2.png) [@enchev](https://forum.radzen.com/u/enchev)\
**Post date:** [September 26, 2024, 1:03pm UTC](https://forum.radzen.com/t/datagrid-inline-editing-losing-focus/18487/10 "2024-09-26T13:03:31Z")

</div>

Hey @Robot,

You can check this thread for some ideas:

> [@Keep expanded state on RadzenDataGrid Master Detail erarchy](http://forum.radzen.com/t/keep-expanded-state-on-radzendatagrid-master-detail-erarchy/18600/2):
>
> There is no built-in way to do that however you can use the Expand/Collapse events to track what is expanded, save some unique field value that identifies the data item and later restore the expanded items using the API demonstrated on our hierarchical demos.

If you continue to demand support from Radzen team without a subscription we will discontinue your forum account.

---

<div class="post-metadata">

**Author:** ![enchev](https://forum.radzen.com/user_avatar/forum.radzen.com/enchev/32/16_2.png) [@enchev](https://forum.radzen.com/u/enchev)\
**Post date:** [September 26, 2024, 1:03pm UTC](https://forum.radzen.com/t/datagrid-inline-editing-losing-focus/18487/11 "2024-09-26T13:03:35Z")

</div>


