Filtering values in grid foreign key column based on another column's value

1 Answer 813 Views
Grid
Lee
Top achievements
Rank 1
Lee asked on 13 May 2021, 03:28 PM

Hi,

I have a grid where amongst other columns, I have two columns which are related - in the first column I select from a list of available options and based on the value selected here, I want to apply a filter to a foreign key column elsewhere in the grid.

So for example if I have a column for "Company ID" with values [1, 2, 3, 4,5] and an FK column "Category", the values bound to the "Category" column are ID/Text pairs for all possible categories, but I'd like to filter that down based on a 3rd "CompanyID" value.

It seems that no matter how I configure the FK column, the underlying data source only ever has the ID/Text values so any attempt at filtering it down based on the CompanyID column doesn't work. Even if my bound values/remote data source returns objects with the required fields for filtering, they get dropped when the FK dropdown list's data source is created.

Is something this even possible to achieve with the grid? If so any pointers would be much appreciated.

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 18 May 2021, 02:40 PM

Hi Lee,

 

Thank you for writing to us.

If you try to change the data of the FK column's dropdown in edit mode, it would be better if you use a Custom Editor column instead of a ForeignKey column:
https://demos.telerik.com/aspnet-mvc/grid/editing-custom

And then you can use additional data for the Read method to bind the dropdown:
https://www.telerik.com/forums/pass-additional-parameters-to-read-ajax-datasource-method---mvc

Feel free to give this approach a try and let me know how it goes for you.

 

Regards,
Eyup
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Grid
Asked by
Lee
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or