Cascading parameters do not traverse into RadzenDataGrid custom cells #233

Closed
opened 2026-01-29 17:33:55 +00:00 by claunia · 1 comment
Owner

Originally created by @avl on GitHub (Oct 29, 2021).

Describe the bug
RadzenDataGrid stops CascadingValue from cascading parameters into custom cells (cells using Template tag).

To Reproduce
When running the following example:

<EditForm EditContext="@SaveEditContext" OnSubmit="OnSave">
<FluentValidationValidator/>

<RadzenDataGrid @ref="TheGrid" AllowFiltering="true" AllowColumnResize="true" 
                FilterMode="FilterMode.Advanced" PageSize="10" AllowPaging="true" AllowSorting="true" Data="@_selectedLocation.Contents" TItem="StorageLocationBalance" ColumnWidth="300px" 
                FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive"
                LogicalFilterOperator="LogicalFilterOperator.And">
    <Columns>
        <RadzenDataGridColumn TItem="StorageLocationBalance" Property="Article" Filterable="true" Title="Article" Frozen="true" Width="200px" TextAlign="TextAlign.Left" />
        <RadzenDataGridColumn TItem="StorageLocationBalance" Property="Batch" Filterable="true" Title="Batch" Frozen="true" Width="200px" TextAlign="TextAlign.Left" />
        <RadzenDataGridColumn TItem="StorageLocationBalance" Property="Quantity" Filterable="true" Title="Quantity" Frozen="true" Width="200px" TextAlign="TextAlign.Left">
            <Template Context="data">

                        <div class="radzen-datagrid-custom-cell">                            
                            <InputNumber @bind-Value="@data.Quantity" />
                            <ValidationMessage For="@(() => @data.Quantity)"/>
                        </div>

            </Template>
        </RadzenDataGridColumn>
    </Columns>
</RadzenDataGrid>

<button title="@DisableReason" Disabled="@SaveDisabled" class="btn btn-primary" type="submit">Save</button>
</EditForm>

There is an exception, saying " Unhandled exception rendering component: Microsoft.AspNetCore.Components.Forms.InputNumber1[System.Decimal] requires a cascading parameter of type EditContext. For example, you can use Microsoft.AspNetCore.Components.Forms.InputNumber1 inside an EditForm."

This is because the ValidationMessage component expects to find a Cascading parameter of type EditContext. Such a parameter is provided by EditForm, but does not (for some reason) reach the ValidationMessage component.

According to the documentation, the cascading parameter supplied by EditForm should reach both children and grandchildren in the tree. However, the cascading parameter seems to be unable to traverse through to children of RadzenDataGrid. Changing the RadzenDataGrid to RadzenDataList fixes the problem. Manually inserting an extra "" just after the Template tag also fixes the problem.

Expected behavior
I would expect cascading parameters to be able to traverse through to the contents of a RadzenDataGrid. Using an editable textbox in the data grid like this might be strange, but there are other cases where cascading parameters are useful inside grid cells.

Desktop (please complete the following information):

  • OS: Windows 10
  • Browser: Chrome, but not browser-dependent
  • Version: 3.11.9

Additional context

Originally created by @avl on GitHub (Oct 29, 2021). **Describe the bug** RadzenDataGrid stops CascadingValue from cascading parameters into custom cells (cells using Template tag). **To Reproduce** When running the following example: ```csharp <EditForm EditContext="@SaveEditContext" OnSubmit="OnSave"> <FluentValidationValidator/> <RadzenDataGrid @ref="TheGrid" AllowFiltering="true" AllowColumnResize="true" FilterMode="FilterMode.Advanced" PageSize="10" AllowPaging="true" AllowSorting="true" Data="@_selectedLocation.Contents" TItem="StorageLocationBalance" ColumnWidth="300px" FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive" LogicalFilterOperator="LogicalFilterOperator.And"> <Columns> <RadzenDataGridColumn TItem="StorageLocationBalance" Property="Article" Filterable="true" Title="Article" Frozen="true" Width="200px" TextAlign="TextAlign.Left" /> <RadzenDataGridColumn TItem="StorageLocationBalance" Property="Batch" Filterable="true" Title="Batch" Frozen="true" Width="200px" TextAlign="TextAlign.Left" /> <RadzenDataGridColumn TItem="StorageLocationBalance" Property="Quantity" Filterable="true" Title="Quantity" Frozen="true" Width="200px" TextAlign="TextAlign.Left"> <Template Context="data"> <div class="radzen-datagrid-custom-cell"> <InputNumber @bind-Value="@data.Quantity" /> <ValidationMessage For="@(() => @data.Quantity)"/> </div> </Template> </RadzenDataGridColumn> </Columns> </RadzenDataGrid> <button title="@DisableReason" Disabled="@SaveDisabled" class="btn btn-primary" type="submit">Save</button> </EditForm> ``` There is an exception, saying " Unhandled exception rendering component: Microsoft.AspNetCore.Components.Forms.InputNumber`1[System.Decimal] requires a cascading parameter of type EditContext. For example, you can use Microsoft.AspNetCore.Components.Forms.InputNumber`1[[System.Decimal, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]] inside an EditForm." This is because the ValidationMessage component expects to find a Cascading parameter of type EditContext. Such a parameter is provided by EditForm, but does not (for some reason) reach the ValidationMessage component. According to the documentation, the cascading parameter supplied by EditForm should reach both children and grandchildren in the tree. However, the cascading parameter seems to be unable to traverse through to children of RadzenDataGrid. Changing the RadzenDataGrid to RadzenDataList fixes the problem. Manually inserting an extra "<CascadingValue Value="@SaveEditContext">" just after the Template tag also fixes the problem. **Expected behavior** I would expect cascading parameters to be able to traverse through to the contents of a RadzenDataGrid. Using an editable textbox in the data grid like this might be strange, but there are other cases where cascading parameters are useful inside grid cells. **Desktop (please complete the following information):** - OS: Windows 10 - Browser: Chrome, but not browser-dependent - Version: 3.11.9 **Additional context**
Author
Owner

@akorchev commented on GitHub (Nov 1, 2021):

RadzenDataGrid injects its internal EditContext because of inline editing. You can inject probably use CascadingValue to inject your context:

            <Template Context="data">
                    <CascadingValue Value=@SaveEditContext>
                        <div class="radzen-datagrid-custom-cell">                            
                            <InputNumber @bind-Value="@data.Quantity" />
                            <ValidationMessage For="@(() => @data.Quantity)"/>
                        </div>
                     </CascadingValue>
            </Template>
@akorchev commented on GitHub (Nov 1, 2021): RadzenDataGrid injects its internal EditContext because of inline editing. You can inject probably use CascadingValue to inject your context: ``` <Template Context="data"> <CascadingValue Value=@SaveEditContext> <div class="radzen-datagrid-custom-cell"> <InputNumber @bind-Value="@data.Quantity" /> <ValidationMessage For="@(() => @data.Quantity)"/> </div> </CascadingValue> </Template> ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/radzen-blazor#233