This is a migrated thread and some comments may be shown as answers.

Filter on Composite column?

4 Answers 772 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tim
Top achievements
Rank 1
Tim asked on 21 Feb 2020, 04:21 PM

I have a grid with a custom column:

<kendo-grid-column field="Category" title="Category" width="200">
      <ng-template kendoGridCellTemplate let-dataItem>
        {{ dataItem.Category.CategoryName }}
      </ng-template>
</kendo-grid-column>

When using the default filtering, I get a type error ((a || "").indexOf is not a function).  I am assuming it is due to trying to filter on the Category object and not the Category.CategoryName string value.

How can I setup a kendoGridFilterMenuTemplate template so that it will just filter on the string value that ends up in the column?  Do I have to have a custom filter?

Thanks,

Tim

4 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 25 Feb 2020, 09:33 AM

Hello Tim,

The requested functionality could indeed be implemented with a custom filter, however, there's a much simpler solution out-of-the-box. The Grid supports setting nested fields as column source. Instead of using a template to extract the CategoryName value from the Category field, you can directly specify as field Category.CategoryName. Refer to this example.

Let me know if further assistance on the topic is required.

Regards,
Dimitar
Progress Telerik

Get quickly onboarded and successful with your Telerik and Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Tim
Top achievements
Rank 1
answered on 25 Feb 2020, 02:31 PM

Thanks Dimitar,

What if the field ends up being a concatenation of a couple of properties in the object.  Using your example, what if the column was something like below, where both the CategoryName and Description are displayed in the column, and we want to filter on anything in either field (CategoryName or Description).  Basically, allow filtering on anything that is displayed in the column.

<kendo-grid-column field="Category" title="Category" width="200">
      <ng-template kendoGridCellTemplate let-dataItem>
        {{ dataItem.Category.CategoryName }} ({{ dataItem.Category.Description }})
      </ng-template>
</kendo-grid-column>

 

Thanks,

Tim

 

0
Accepted
Dimitar
Telerik team
answered on 26 Feb 2020, 02:39 PM

Hello Tim,

Filtering of the column template content is not possible out-of-the-box. You can put there strings, images, links, etc. and naturally the Grid doesn't know how to process content of unknown form. 

You can create a custom filter for such scenarios that looks up multiple fields. Here's a simplified example of what I have in mind. The custom filter can be extracted into a standalone component and the fields that it looks-up can be passed to it as an input prop, so that you can reuse the filter.

Make sure to write back, if further information is needed.

Regards,
Dimitar
Progress Telerik

Get quickly onboarded and successful with your Telerik and Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Tim
Top achievements
Rank 1
answered on 26 Feb 2020, 10:18 PM

Perfect.  I think this is exactly what I was trying to achieve.

Thanks,

Tim

Tags
Grid
Asked by
Tim
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Tim
Top achievements
Rank 1
Share this question
or