Grid Filtering on an Object Column

1 Answer 531 Views
Filter Grid
Kevin
Top achievements
Rank 1
Kevin asked on 19 May 2021, 08:05 PM

I have a grid with an object as a column. For example, let's say we have column.Bound(b => b.Product), where Product is an object of { Id: int, Name: string }. I also use an editor template dropdrownlist which has the same model so it binds properly, so just having Product.Name bound to the column wouldn't seem to work well in this case. 

Is there a way to make it so that the filters just take in the value of Product.Name? I saw others with similar issues online, but didn't see a solution that worked for me. 

1 Answer, 1 is accepted

Sort by
0
Georgi
Telerik team
answered on 24 May 2021, 08:02 AM

Hi Kevin,

A possible solution is to bind the column to the Product.Name field and the editor of the column to the Product field.

The same approach is demonstrated in the grid's overview demo:

Please note that the category column is bound to the category name field in order to enable filtering/sorting/grouping. However, to edit the whole category object, the editor is bound to the category object field.

e.g.

@(Html.Kendo().DropDownListFor(m => m)
            .DataValueField("CategoryID")
            .DataTextField("CategoryName")
            .HtmlAttributes(new {data_bind="value: Category" })
            .BindTo((System.Collections.IEnumerable)ViewData["categories"])
)

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

Tags
Filter Grid
Asked by
Kevin
Top achievements
Rank 1
Answers by
Georgi
Telerik team
Share this question
or