Unplanned
Last Updated: 25 Nov 2024 11:57 by ADMIN
Simi
Created on: 18 Nov 2024 17:17
Category: UI for Blazor
Type: Feature Request
1
Enhancing Column Templates with Type-Specific Context to Eliminate Casting Needs

Steps to reproduce:

  1. Insert a simple TelerikGrid on your page
  2. Add Columns with templates for each property
  3. Specify a Column Template

See https://blazorrepl.telerik.com/GyPvFMFr00zLEEdG00

Problem / Inconvenience

  • Context has to be converted/cast before access to the each property is possible
  • Grid columns are not generic which makes them hard to use sometimes
  • Fields have to be specified by name (may lead to wrong names after changing)

Solution / Feature Request

  • Provide new generic columns (to ensure no current implementations break)
  • Add [CascadingTypeParameter(nameof(TItem))] to the TelerikGrid
  • GridColumns automatically "inherit" the typeparam TItem

Idea from: Blazor QuickGrid

Benefits

  • GridColumns can be specified with Expression
  • Template context does not have to be cast anymore
  • Renaming properties affect expression or an error is display (property does not exist)
<GridColumn For="@(t => t.Name)">
        <Template>
                <div>
                    @item.Name
                </div>
        </Template>
</GridColumn>
2 comments
ADMIN
Tsvetomir
Posted on: 25 Nov 2024 11:57

Hello Simon,

Thank you for providing additional details and context regarding your feature request. Here's our response addressing your suggestions and concerns:

  • Casting in Templates - The necessity for casting in template contexts is a limitation that comes from the Blazor framework itself. This is because the templates are not strongly typed, which requires developers to cast the context to the appropriate type manually.

  • Field Specification by Name - As you noted, specifying fields by name can lead to potential errors when property names change. To mitigate this, using the nameof() operator for the Field parameter is recommended. This practice helps catch errors at compile time if the property names change. Additionally, We are not planning to add a For="" parameter to the Grid column because doing so would either result in major breaking changes or require maintaining two different approaches for field binding, which would complicate the framework and its usability.

  • Strongly-Typed Template Context -  We acknowledge the potential benefits of having a strongly-typed template context in the grid columns. This would eliminate the need for casting and enhance the robustness of the code.

With that being said, I can confirm that we accept the feature request in creating a more type specific context in the Column template to ensure that casting the context to specific type not required. With that being said, marking the item as "Unplanned". Also, we rename the feature request name to more generic and easily findable.

      We appreciate your feedback and suggestions, as they are crucial in guiding future enhancements to our components.

        Regards,
        Tsvetomir
        Progress Telerik

        Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

        Simi
        Posted on: 18 Nov 2024 17:24

        Of course I mean:

        <GridColumn For="@(t => t.Name)">
                <Template>
                        <div>
                            @context.Name
                        </div>
                </Template>
        </GridColumn>