Application crashes when filter is enabled on an ENUM field


Here is a grid that shows a bunch of users

<SfGrid DataSource="@allUsers" AllowPaging="true" AllowSorting="true" AllowFiltering="true">
        <GridEvents CommandClicked="CommandClickHandler" TValue="User"></GridEvents>
        <GridPageSettings PageSize="10" />
        <GridColumns>
            <GridColumn HeaderText="Edit" Width="75">
                <GridCommandColumns>
                    <GridCommandColumn Type="CommandButtonType.Edit" Title="Edit User"
                                       ButtonOption="@(new CommandButtonOptions()
                                                   {
                                                       CssClass="e-success",
                                                       IconCss = "fa fa-pencil",
                                                   })" />
                </GridCommandColumns>
            </GridColumn>
            <GridColumn HeaderText="Delete" Width="75">
                <GridCommandColumns>
                    <GridCommandColumn Type="CommandButtonType.Delete" Title="Delete User"
                                       ButtonOption="@(new CommandButtonOptions()
                                                   {
                                                       CssClass="e-danger",
                                                       IconCss = "fa fa-trash",
                                                   })" />
                </GridCommandColumns>
            </GridColumn>

            <GridColumn Field="@nameof(User.Status)" HeaderText="Status" Width="100" />
            <GridColumn Field="@nameof(User.Id)" HeaderText="Id" TextAlign="TextAlign.Right" Width="100" />
            <GridColumn Field="@nameof(User.OrgId)" HeaderText="Org ID" Width="150" />
        </GridColumns>
    </SfGrid>

Here is the user object:

    public enum UserStatus
    {
        Active = 0,
        Disabled = -1
    }

    [Table("User")]
    public class User : BaseModel
    {
        
 // ....
        public UserStatus Status { get; set; } = UserStatus.Active;

 // ....
}

If I enter anything in the filter grid OTHER THAN "Active" or "Disabled", the application crashes.

E.g.  - see attached screenshot.

The Exception is: 

 
System.NullReferenceException
  HResult=0x80004003
  Message=Object reference not set to an instance of an object.
  Source=Syncfusion.Blazor
  StackTrace:
   at Syncfusion.Blazor.Data.EnumerableOperation.PredicateBuilder(IEnumerable dataSource, List`1 whereFilter, String condition, ParameterExpression paramExpression, Type type)
   at Syncfusion.Blazor.Data.EnumerableOperation.PredicateBuilder(IEnumerable dataSource, List`1 whereFilter, String condition, ParameterExpression paramExpression, Type type)
   at Syncfusion.Blazor.Data.EnumerableOperation.PerformFiltering(IEnumerable dataSource, List`1 whereFilter, String condition)
   at Syncfusion.Blazor.Data.BlazorAdaptor.DataOperationInvoke[T](IEnumerable DataSource, DataManagerRequest queries)
   at Syncfusion.Blazor.Data.BlazorAdaptor.<>c__DisplayClass4_0`1.<PerformDataOperation>b__0()
   at System.Threading.Tasks.Task`1.InnerInvoke()
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Syncfusion.Blazor.Data.BlazorAdaptor.<PerformDataOperation>d__4`1.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Syncfusion.Blazor.DataManager.<ExecuteQuery>d__147`1.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()

  This exception was originally thrown at this call stack:
    Syncfusion.Blazor.Data.EnumerableOperation.PredicateBuilder(System.Collections.IEnumerable, System.Collections.Generic.List<Syncfusion.Blazor.Data.WhereFilter>, string, System.Linq.Expressions.ParameterExpression, System.Type)
    Syncfusion.Blazor.Data.EnumerableOperation.PredicateBuilder(System.Collections.IEnumerable, System.Collections.Generic.List<Syncfusion.Blazor.Data.WhereFilter>, string, System.Linq.Expressions.ParameterExpression, System.Type)
    Syncfusion.Blazor.Data.EnumerableOperation.PerformFiltering(System.Collections.IEnumerable, System.Collections.Generic.List<Syncfusion.Blazor.Data.WhereFilter>, string)
    Syncfusion.Blazor.Data.BlazorAdaptor.DataOperationInvoke<T>(System.Collections.IEnumerable, Syncfusion.Blazor.DataManagerRequest)
    Syncfusion.Blazor.Data.BlazorAdaptor.PerformDataOperation.AnonymousMethod__0()
    System.Threading.Tasks.Task<TResult>.InnerInvoke()
    System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(System.Threading.Thread, System.Threading.ExecutionContext, System.Threading.ContextCallback, object)
    System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    System.Threading.Tasks.Task.ExecuteWithThreadLocal(ref System.Threading.Tasks.Task, System.Threading.Thread)
    System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    ...
    [Call Stack Truncated]

Attachment: sfgrid_crash_45e3bb21.7z

6 Replies 1 reply marked as answer

JT Joseph Tan July 20, 2020 10:03 AM UTC

<PackageReference Include="Syncfusion.Blazor" Version="18.2.0.44" />


RN Rahul Narayanasamy Syncfusion Team July 21, 2020 02:55 PM UTC

Hi Joseph, 

Greetings from Syncfusion. 

Query: Application crashes when filter is enabled on an ENUM field 

We have validated your query with the provided information. We suggest you to render a dropdown in FilterTemplate and perform the filtering operation using the dropdown. It is recommended way to perform filtering operation for Enum columns. Find the below code snippets and sample for your reference. 

<SfGrid @ref="@Grid" DataSource="@Orders" AllowFiltering="true"> 
        <GridColumns> 
            <GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" TextAlign="TextAlign.Right" Width="120"></GridColumn> 
            . . . 
            <GridColumn Field=@nameof(Order.Type) HeaderText="Type" Type="ColumnType.String" Width="130">  //Enum column 
                <FilterTemplate> 
                    <SfDropDownList Placeholder="Type" ID="Type" Value="@((string)(context as PredicateModel).Value)" DataSource="@FilterDropData" TValue="string" TItem="Data"> 
                        <DropDownListEvents ValueChange="@Change" TValue="string"></DropDownListEvents> 
                        <DropDownListFieldSettings Value="Type" Text="Type"></DropDownListFieldSettings> 
                    </SfDropDownList> 
                </FilterTemplate> 
            </GridColumn> 
        </GridColumns> 
    </SfGrid> 

@code{    SfGrid<Order> Grid;    . . .     public void Change(@Syncfusion.Blazor.DropDowns.ChangeEventArgs<string> args)    {        if (args.Value == "All")        {            Grid.ClearFiltering();        }        else        {            Grid.FilterByColumn("Type""contains", args.Value);        }    }}

Reference: 

Please let us know if you have any concerns. 

Regards, 
Rahul 



JT Joseph Tan July 23, 2020 12:55 AM UTC

Hi There,

OK - that worked.  
But really, the entire app should not crash when this happens (try catch ? ) 


Cheers


RN Rahul Narayanasamy Syncfusion Team July 23, 2020 12:24 PM UTC

Hi Joseph, 

Thanks for your suggestion. 

We are currently improving our various features and behaviors in our Grid and also we have also logged a documentation topic for this content. It will be included in our any of our upcoming release.  

Until then we suggest you to use the above suggested solution to achieve your requirement. 

Regards, 
Rahul 



RC Rogerio C Mauri March 3, 2021 07:25 PM UTC

I reproduced the example, but it showed errors.

1) DropDownListEvents requires TItem, so I informed TItem = "Data"
2) ChangeEventArgs from Change requires two parameters, TValue and TItem, so I entered .

Even so, it presents the following error.

blazor.server.js:19 [2021-03-03T19:20:33.520Z] Error: System.NullReferenceException: Object reference not set to an instance of an object.
   at GMPlusB.Pages.Tabelas.Cadastro.GridCadastro.<>c__DisplayClass0_1.b__13(RenderTreeBuilder __builder4)
   at Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder.AddContent(Int32 sequence, RenderFragment fragment)
   at Syncfusion.Blazor.Grids.Internal.FilterMenuRenderer`1.b__0_2(RenderTreeBuilder __builder3)
   at Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder.AddContent(Int32 sequence, RenderFragment fragment)
   at Syncfusion.Blazor.Popups.Internal.DialogContent.BuildRenderTree(RenderTreeBuilder __builder)
   at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.RenderInExistingBatch(RenderQueueEntry renderQueueEntry)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.ProcessRenderQueue()


Grid:


Code:
    private class Data
    {
        public string Sexo { get; set; }
    }
    List FilterDropData = new List
    {
        new Data() { Sexo = "Todos" },
        new Data() { Sexo = "Masculino" },
        new Data() { Sexo = "Feminino" }
    };

    private void ChangeValueSexo(@Syncfusion.Blazor.DropDowns.ChangeEventArgs args)
    {
        if (args.Value == "Todos")
            defaultGrid.ClearFiltering();
        else
            defaultGrid.FilterByColumn("Sexo", "contais", args.Value);
    }


RN Rahul Narayanasamy Syncfusion Team March 4, 2021 02:00 PM UTC

Hi Rogerio, 

Greetings from Sncfusion support. 

We have validated your query and if you are using Menu filtering then we suggest you to use @bind-Value in the SfDropDownList component(Component rendered in Filter Template) to resolve the issue you are facing. Please find the below code snippet, sample and the documentation for your reference. 

        <GridColumn Field=@nameof(Order.CustomerID) HeaderText="Customer Name" Width="150"> 
            <FilterTemplate> 
                <SfDropDownList Placeholder="Customer Name" ID="CustomerID" @bind-Value="@((context as PredicateModel<string>).Value)" DataSource="@Dropdown" TValue="string" TItem="Data"> 
                    <DropDownListFieldSettings Value="CustomerID" Text="CustomerID"></DropDownListFieldSettings> 
                </SfDropDownList> 
            </FilterTemplate> 
        </GridColumn> 



Please get back to us if you have any other queries. 

Regards, 
Rahul 


Marked as answer
Loader.
Up arrow icon