DataGrid dynamic column filter

Hello,

I referenced this demo to add a filter in the dynamic column. The solution is to use the LoadData function to send the filter argument to the back-end and re-built the dataset.
It makes sense, but I want to use the front-end function to deal with it. I try to initial the data in the OnInitializedAsync function and remove the LoadData function, and it throws the following error when I filter the EmployeeID column.
Could you please tell me how I can fix it? Thank you.

crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
      Unhandled exception rendering component: The binary operator Equal is not defined for the types 'System.Object' and 'System.Int32'.
System.InvalidOperationException: The binary operator Equal is not defined for the types 'System.Object' and 'System.Int32'.
  at System.Linq.Expressions.Expression.GetEqualityComparisonOperator (System.Linq.Expressions.ExpressionType binaryType, System.String opName, System.Linq.Expressions.Expression left, System.Linq.Expressions.Expression right, System.Boolean liftToNull) <0x38c8840 + 0x001ae> in <filename unknown>:0 
  at System.Linq.Expressions.Expression.Equal (System.Linq.Expressions.Expression left, System.Linq.Expressions.Expression right, System.Boolean liftToNull, System.Reflection.MethodInfo method) <0x38c81a0 + 0x00040> in <filename unknown>:0 
  at System.Linq.Expressions.Expression.Equal (System.Linq.Expressions.Expression left, System.Linq.Expressions.Expression right) <0x38c8040 + 0x0000c> in <filename unknown>:0 
  at System.Linq.Dynamic.Core.Parser.ExpressionHelper.GenerateEqual (System.Linq.Expressions.Expression left, System.Linq.Expressions.Expression right) <0x38c7d48 + 0x00028> in <filename unknown>:0 
  at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseComparisonOperator () <0x38b0b60 + 0x0084c> in <filename unknown>:0 
  at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseLogicalAndOrOperator () <0x38aff10 + 0x00004> in <filename unknown>:0 
  at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseIn () <0x38af690 + 0x00004> in <filename unknown>:0 
  at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseAndOperator () <0x38a6ab8 + 0x00004> in <filename unknown>:0 
  at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseOrOperator () <0x38a68d8 + 0x00004> in <filename unknown>:0 
  at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseLambdaOperator () <0x38a6638 + 0x00004> in <filename unknown>:0 
  at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseNullCoalescingOperator () <0x38a6528 + 0x00004> in <filename unknown>:0 
  at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseConditionalOperator () <0x38a6340 + 0x00018> in <filename unknown>:0 
  at System.Linq.Dynamic.Core.Parser.ExpressionParser.Parse (System.Type resultType, System.Boolean createParameterCtor) <0x38a6088 + 0x0002c> in <filename unknown>:0 
  at System.Linq.Dynamic.Core.DynamicExpressionParser.ParseLambda (System.Type delegateType, System.Linq.Dynamic.Core.ParsingConfig parsingConfig, System.Boolean createParameterCtor, System.Linq.Expressions.ParameterExpression[] parameters, System.Type resultType, System.String expression, System.Object[] values) <0x379bfe8 + 0x00064> in <filename unknown>:0 
  at System.Linq.Dynamic.Core.DynamicExpressionParser.ParseLambda (System.Linq.Dynamic.Core.ParsingConfig parsingConfig, System.Boolean createParameterCtor, System.Linq.Expressions.ParameterExpression[] parameters, System.Type resultType, System.String expression, System.Object[] values) <0x379ba10 + 0x0001a> in <filename unknown>:0 
  at System.Linq.Dynamic.Core.DynamicExpressionParser.ParseLambda (System.Linq.Dynamic.Core.ParsingConfig parsingConfig, System.Boolean createParameterCtor, System.Type itType, System.Type resultType, System.String expression, System.Object[] values) <0x379b690 + 0x0006a> in <filename unknown>:0 
  at System.Linq.Dynamic.Core.DynamicQueryableExtensions.Where (System.Linq.IQueryable source, System.Linq.Dynamic.Core.ParsingConfig config, System.String predicate, System.Object[] args) <0x379a888 + 0x00064> in <filename unknown>:0 
  at System.Linq.Dynamic.Core.DynamicQueryableExtensions.Where[TSource] (System.Linq.IQueryable`1[T] source, System.Linq.Dynamic.Core.ParsingConfig config, System.String predicate, System.Object[] args) <0x378f9e0 + 0x00010> in <filename unknown>:0 
  at System.Linq.Dynamic.Core.DynamicQueryableExtensions.Where[TSource] (System.Linq.IQueryable`1[T] source, System.String predicate, System.Object[] args) <0x378f3f8 + 0x00012> in <filename unknown>:0 
  at Radzen.QueryableExtension.Where[T] (System.Linq.IQueryable`1[T] source, System.Collections.Generic.IEnumerable`1[T] columns) <0x3581938 + 0x007e4> in <filename unknown>:0 
  at Radzen.Blazor.RadzenDataGrid`1[TItem].get_View () <0x3580828 + 0x00040> in <filename unknown>:0 
  at Radzen.PagedDataBoundComponent`1[T].get_PagedView () <0x3580240 + 0x00056> in <filename unknown>:0 
  at Radzen.Blazor.RadzenDataGrid`1[TItem].DrawGroupOrDataRows (Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder builder, System.Collections.Generic.IList`1[T] visibleColumns) <0x3573e60 + 0x000fe> in <filename unknown>:0 
  at Radzen.Blazor.RadzenDataGrid`1+<>c__DisplayClass1_0[TItem].<DrawRows>b__0 (Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder builder) <0x3573950 + 0x00010> in <filename unknown>:0 
  at Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder.AddContent (System.Int32 sequence, Microsoft.AspNetCore.Components.RenderFragment fragment) <0x2f35960 + 0x0001e> in <filename unknown>:0 
  at Radzen.Blazor.RadzenDataGrid`1[TItem].BuildRenderTree (Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder) <0x3186f50 + 0x040d8> in <filename unknown>:0 
  at Microsoft.AspNetCore.Components.ComponentBase.<.ctor>b__6_0 (Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder builder) <0x2d84430 + 0x0001a> in <filename unknown>:0 
  at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch (Microsoft.AspNetCore.Components.Rendering.RenderBatchBuilder batchBuilder, Microsoft.AspNetCore.Components.RenderFragment renderFragment) <0x2d83d88 + 0x00062> in <filename unknown>:0 
  at Microsoft.AspNetCore.Components.RenderTree.Renderer.RenderInExistingBatch (Microsoft.AspNetCore.Components.Rendering.RenderQueueEntry renderQueueEntry) <0x2d83788 + 0x0004c> in <filename unknown>:0 
  at Microsoft.AspNetCore.Components.RenderTree.Renderer.ProcessRenderQueue () <0x2d80c90 + 0x00098> in <filename unknown>:0

This is my code.
Testcheckbox.zip (2.2 KB)

The exception says it all. The column type is integer while the actual value is object.

Yes, that's true, but the demo set the column and filter type like this. Could you please tell me how to fix it? Thank you so much.

@enchev
Looking forward to your guidance. Thank you.

The DataGrid cannot sort dynamic data in-memory. The only option is to bind the DataGrid using LoadData where you can manually sort the data according to provided sort info in the event argument. From LoadDataArgs you can get Sort, Filter, etc. expression in three different formats, OData, Dynamic LINQ and strongly typed (Sorts and Filters collections). In this demo for example you can apply sort, filter and page to IQueryable using Dynamic LINQ expressions:

Hi @blu,

I've reworked our dynamic data demo to illustrate you how you can sort, filter and page in-memory dynamic data:

Hi @enchev ,

Thank you so much for your hard work in preparing the demo.
It would definitely save us a huge amount of implementation time. I tried to run the code in my environment (.NET 3), but the sort and filter feature did not work well for the int column. Here is the error.
image

Could you please tell me where I should revise? Thank you.

Attached my code.

code.zip (2.4 KB)

We can't reproduce such an exception just with the attached code. It works as expected in our tests. You can send us a runnable application to info@radzen.com.

@korchev

Thank you very much for the prompt reply. I already sent an email to info@radzen.com. Looking forward to the result. Thank you.

We haven't received any emails yet. Make sure the attachment size is less than 10MB or our email server will reject it. Delete any obj and bin directories from the attachment to maintain smaller size. Alternatively host the zip file in a cloud provider (OneDrive, GoogleDrive, Dropbox etc.) and share the link over email.

@korchev

Thank you for letting me know. I attached the application to GoogleDrive, and sent it again. Thank you.