SfGrid - Issues restoring grid data when filtering and state persistence are both enabled

Hello, I am using the DataGrid control and I am having a lot of trouble when enabling state persistence on the grid while also using filters. I am using version 18.4.0.43 of the SyncFusion components nuget package.

The code to reproduce is straightfoward - I just used the example code from the State Management documentation and I added one line to set the GridFilterSettings Type to the appropriate setting for each scenario below. I have supplied the full code towards the end of this post.

There are several issues I have found, please see below:

Issue #1: Using the "Menu" FilterType for text or date filters, navigating away from the page (or refreshing the page) and attempting to filter again on the same column leads to an unhandled error at runtime, and filter dialog does not open.
  1. Run the app using the code provided below
  2. Click on the "Customer Name" filter
  3. Filter using any of the options (for example, starts with = an)
  4. Navigate to another page and then return back to page with grid (or just refresh the page)
  5. Click on the customer name filter
  6. Observe that the filter dialog doesn't open, and there is a runtime error in the console (System.InvalidCastException: Specified cast is not valid)
  7. You can repeat the same steps above with the "Order Date" filter and see that the same error occurs with dates
Issue #2: Using the "Menu" FilterType for numeric filters, the user is required to execute the filter again when returning to the page (the grid doesn't present the filtered data by default - instead the contents are empty)
  1. Run the app using the code provided below
  2. Click on the Order ID filter
  3. Filter using any of the options (for example, greater than 1003)
  4. Navigate to another page and then return back to page with grid (or just refresh the page)
  5. Observe that the grid contents are empty
  6. You can click on the Order ID filter again and then click "Filter" to display the contents again - however this is not user friendly.
  7. The same issue applies to the Freight column (so it appears this can affect both integers and doubles)
Issue #3: Using the "Excel" or "CheckBox" FilterType for numeric or date filters, the grid doesn't present the filtered data after returning to the page, instead it is empty and an error occurs when attempting to re-open the filter dialog
  1. Run the app using the code provided below (but change the FilterType to Excel or CheckBox)
  2. Click on the Order ID filter
  3. Filter using any of the options (for example set a checkbox next to 1002 and 1003, or for Excel filter you can try to use the advanced options like greater than 1003)
  4. Navigate to another page and then return back to page with grid (or just refresh the page)
  5. Observe that the grid contents are empty
  6. Click on the Order ID filter
  7. Observe that the filter dialog doesn't open, and there is a runtime error in the console (System.ArgumentException: Argument types do not match)
  8. The same issue applies to the Freight and also the Order Date column (so it appears this can affect integers, doubles, and dates)
Issue #4: Using the "FilterBar" FilterType for numeric filters, the grid doesn't present the filtered data after returning to the page, instead it is empty
  1. Run the app using the code provided below (and either change the FilterType to FilterBar or remove the GridFilterSettings completely)
  2. Set a value on the Order ID filter
  3. Navigate to another page and then return back to page with grid (or just refresh the page)
  4. Observe that the grid contents are empty
  5. Set focus on the Order ID filter bar and hit enter
  6. Notice that the filter is now cleared completely (expectation was it would retain the correct filter state based on value supplied)
  7. The same issue applies to the Freight column (so it appears this can affect both integers and doubles)
#Issue #5: Using the "FilterBar" FilterType for date filters, navigating away from the page and returing (or refreshing the page) leads to an unhandled error at runtime.
  1. Run the app using the code provided below (and either change the FilterType to FilterBar or remove the GridFilterSettings completely)
  2. Set a value on the Order Date filter
  3. Navigate to another page and then return back to page with grid (or just refresh the page)
  4. Observe that immediately there is a runtime error in the console (System.InvalidCastException: Specified cast is not valid)
It seems there is currently no good way to use the state persistence features while also using filters. Issues #4 and #5 above can be reproduced using exactly your code from the Blazor DataGrid State Management documentation without any modifications. Please advise if I have done something incorrectly or if there is any workaround. Thank you.

Full example code is below (code is taken directly from your documentation except for highlighted change):

@using Syncfusion.Blazor.Grids

<SfGrid ID="Grid" DataSource="@Orders" Height="315" EnablePersistence="true" AllowPaging="true" AllowFiltering="true" AllowGrouping="true" AllowSorting="true">
    <GridFilterSettings Type="FilterType.Menu" />
    <GridColumns>
        <GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" TextAlign="TextAlign.Right" Width="120"></GridColumn>
        <GridColumn Field=@nameof(Order.CustomerID) HeaderText="Customer Name" Width="150"></GridColumn>
        <GridColumn Field=@nameof(Order.OrderDate) HeaderText="Order Date" Format="d" Type="ColumnType.Date" TextAlign="TextAlign.Right" Width="130"></GridColumn>
        <GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Format="C2" TextAlign="TextAlign.Right" Width="120"></GridColumn>
    </GridColumns>
</SfGrid>

@code {
    public List<Order> Orders { get; set; }

    protected override void OnInitialized()
    {
        Orders = Enumerable.Range(1, 75).Select(x => new Order()
        {
            OrderID = 1000 + x,
            CustomerID = (new string[] { "ALFKI", "ANANTR", "ANTON", "BLONP", "BOLID" })[new Random().Next(5)],
            Freight = 2.1 * x,
            OrderDate = DateTime.Now.AddDays(-x),
        }).ToList();
    }

    public class Order
    {
        public int? OrderID { get; set; }
        public string CustomerID { get; set; }
        public DateTime? OrderDate { get; set; }
        public double? Freight { get; set; }
    }
}

1 Reply 1 reply marked as answer

VN Vignesh Natarajan Syncfusion Team February 22, 2021 12:25 PM UTC

Hi Mashuk,  
 
Thanks for contacting Syncfusion support.  
 
Query: “I am using the DataGrid control and I am having a lot of trouble when enabling state persistence on the grid while also using filters 
 
We have analyzed the reported query and we are also able to reproduce the reported issue at our end. We have confirmed it as a bug and logged the defect report “Issues with Grid Filtering and State maintainence” for the same. Thank you for taking the time to report this issue and helping us improve our product. At Syncfusion, we are committed to fixing all validated defects (subject to technological feasibility and Product Development Life Cycle ) and including the defect fix in our weekly release which is expected to be rolled out by end of March, 2021. We will update you once the release is rolled out.    
       
You can now track the current status of your request, review the proposed resolution timeline, and contact us for any further inquiries through this link.       
   
  
Till then we appreciate your patience.  
 
Regards, 
Vignesh Natarajan 
 


Marked as answer
Loader.
Up arrow icon