Filter For GridColumn using <Template>

1 Answer 58 Views
Grid
Timothy J
Top achievements
Rank 1
Iron
Iron
Timothy J asked on 28 May 2021, 04:44 AM

We have a grid as the snippet below.

I can't figure out how to put a FilterMenu on the Template(d) columns.  

The Filter shows up for the "Id" column, which is just a field.

Is it possible to have a filter menu for the columns which are Template?


            <TelerikGrid Data="@_vehicleParts"
                         Pageable="true"
                         Sortable="true"
                         FilterMode="Telerik.Blazor.GridFilterMode.FilterMenu"
                         Resizable="true"
                         Reorderable="true"
                         PageSize="20"
                         Navigable="true"
                         OnRead=@OnVehiclePartsRead
                         TotalCount="@TotalCount">
                <GridColumns>
                    <GridColumn Width="10%" Field="Id"/>
                    <GridColumn Width="10%" Title="Year">
                        <Template Context="vehiclePartCtx">
                            @{
                                if (vehiclePartCtx is VehiclePart { BaseVehicle: { } } vehiclePart)
                                {
                                    <span>@vehiclePart.BaseVehicle.YearId</span>
                                }
                                else
                                {
                                    <span>???</span>
                                }
                            }

                        </Template>
                    </GridColumn>

1 Answer, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 28 May 2021, 07:01 AM

Hello Timothy,

Column filtering, sorting and editing depends on the column Field. Without it, the Grid doesn't know which data to use for these data operations and what is the data type (i.e. what filtering component and operators to use).

The Field property for template columns is set in the same way as for non-templated columns. Afterwards, you can still use any other field in the template.

https://demos.telerik.com/blazor-ui/grid/templates

https://docs.telerik.com/blazor-ui/components/grid/templates/column

Regards,
Dimo
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.

Timothy J
Top achievements
Rank 1
Iron
Iron
commented on 28 May 2021, 12:45 PM

>>column Field. Without it, the Grid doesn't know which data to use << Sure, I was hoping there was some event where we could handle the filtering if not using a field.
Dimo
Telerik team
commented on 28 May 2021, 12:51 PM

Well, I am afraid there is no such event. Even the filter template for the column requires a Field, otherwise it will not render. Out of curiosity, can you describe your use case and why you prefer not to define a Field for the template column?
Timothy J
Top achievements
Rank 1
Iron
Iron
commented on 28 May 2021, 02:51 PM

Sure, I am trying to filter on a property that is off of the main model, for example Year in the above code
Dimo
Telerik team
commented on 31 May 2021, 11:21 AM

I see. Well, I can only suggest that you create a grid model that includes the base vehicle's year and then you will be able to set it as a field and filter by it. I assume you have already considered that and I hope it is an acceptable.
Tags
Grid
Asked by
Timothy J
Top achievements
Rank 1
Iron
Iron
Answers by
Dimo
Telerik team
Share this question
or