Grid Filtering => List objects in Object

1 Answer 187 Views
Filter Grid
MVDH
Top achievements
Rank 1
MVDH asked on 21 Mar 2023, 09:49 AM

Hi,

Is it possible to use filtering with List of child objects?

 

Example :

 

User

- Guid Id

- String Name

- List<PhoneNumber> PhoneNumbers

- Adress Adress

 

PhoneNumber

- Guid Id

- String PhoneNumber

 

Adress

- Guid Id

- String Street

 

If i filter on the street off a Adress and in the FilterDesriptor member is "Adres.Street" than it works correctly.

But how can you do it if it is a list? Like i want to filter on the PhoneNumbers?

I already tried "PhoneNumbers.PhoneNumber", but than i got the error :

System.ArgumentException: Invalid property or field - 'PhoneNumber' for type: ICollection`1

         at Kendo.Mvc.Infrastructure.Implementation.Expressions.MemberAccessTokenExtensions.CreateMemberAccessExpression(IMemberAccessToken token, Expression instance)
         at Kendo.Mvc.Infrastructure.Implementation.Expressions.ExpressionFactory.MakeMemberAccess(Expression instance, String memberName)
         at Kendo.Mvc.Infrastructure.Implementation.Expressions.ExpressionFactory.MakeMemberAccess(Expression instance, String memberName, Boolean liftMemberAccessToNull)
         at Kendo.Mvc.Infrastructure.Implementation.Expressions.PropertyAccessExpressionBuilder.CreateMemberAccessExpression()
         at Kendo.Mvc.Infrastructure.Implementation.Expressions.FilterDescriptorExpressionBuilder.CreateMemberExpression()
         at Kendo.Mvc.Infrastructure.Implementation.Expressions.FilterDescriptorExpressionBuilder.CreateBodyExpression()
         at Kendo.Mvc.FilterDescriptor.CreateFilterExpression(ParameterExpression parameterExpression)
         at Kendo.Mvc.FilterDescriptorBase.CreateFilterExpression(Expression instance)
         at Kendo.Mvc.Infrastructure.Implementation.Expressions.FilterDescriptorCollectionExpressionBuilder.CreateBodyExpression()
         at Kendo.Mvc.CompositeFilterDescriptor.CreateFilterExpression(ParameterExpression parameterExpression)
         at Kendo.Mvc.FilterDescriptorBase.CreateFilterExpression(Expression instance)
         at Kendo.Mvc.Infrastructure.Implementation.Expressions.FilterDescriptorCollectionExpressionBuilder.CreateBodyExpression()
         at Kendo.Mvc.CompositeFilterDescriptor.CreateFilterExpression(ParameterExpression parameterExpression)
         at Kendo.Mvc.FilterDescriptorBase.CreateFilterExpression(Expression instance)
         at Kendo.Mvc.Infrastructure.Implementation.Expressions.FilterDescriptorCollectionExpressionBuilder.CreateBodyExpression()
         at Kendo.Mvc.Infrastructure.Implementation.Expressions.FilterExpressionBuilder.CreateFilterExpression()
         at Kendo.Mvc.Extensions.QueryableExtensions.Where(IQueryable source, IEnumerable`1 filterDescriptors)
         at Kendo.Mvc.Extensions.QueryableExtensions.CreateDataSourceResult[TModel,TResult](IQueryable queryable, DataSourceRequest request, ModelStateDictionary modelState, Func`2 selector)
         at Kendo.Mvc.Extensions.QueryableExtensions.ToDataSourceResult(IQueryable queryable, DataSourceRequest request, ModelStateDictionary modelState)
         at Kendo.Mvc.Extensions.QueryableExtensions.ToDataSourceResult(IQueryable queryable, DataSourceRequest request)
         at Kendo.Mvc.Extensions.QueryableExtensions.<>c__DisplayClass9_0.<ToDataSourceResultAsync>b__0()

 

Greetings,

Maxime

 

1 Answer, 1 is accepted

Sort by
0
Anton Mironov
Telerik team
answered on 24 Mar 2023, 05:49 AM

Hello Maxime,

Thank you for the details provided.

Filtering of an object could be achieved as represented in the following article:

In order to apply this to a collection, I would recommend handling the filter button Click Event and implementing custom logic for the field.

Get the parameters from the filter input, and the collection/s, and apply the filtering to the dataSource of the Grid.

Here is an example of how to use a multiselect for filter:

I hope this information helps.

Kind Regards,
Anton Mironov
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
MVDH
Top achievements
Rank 1
Answers by
Anton Mironov
Telerik team
Share this question
or