Filtering doesn't work with custom Adapter

Hello!

I have a grid implemented and just recently replaced it's data source with DataAdaptor.

After that I wanted to implement filtering since with data adaptor I need to do it manually. The problem is that even thou data is filtered correctly, and I can see that from ReadAsync method the data result is having filtered items, the table doesn't change and the filter menu window says "No records found".

Here's the configuration part of my grid:

<SfGrid @ref="Grid" TValue="UserDto" AllowPaging="true" ShowColumnChooser="true" Toolbar="@ToolbarItems"

        AllowFiltering="true" AllowSorting="true" AllowTextWrap="true" Query="@(new Query().AddParams("ShowClosed", showClosedUsers))">

    <SfDataManager Adaptor="Adaptors.CustomAdaptor" AdaptorInstance="@typeof(UserAdaptor)"></SfDataManager>

    <GridTextWrapSettings WrapMode="WrapMode.Content"></GridTextWrapSettings>

    <GridPageSettings PageSize="15" PageSizes="PagerDropdown"></GridPageSettings>

    <GridFilterSettings Type="FilterType.Menu"></GridFilterSettings>

    <GridEditSettings AllowDeleting="true" Mode="EditMode.Dialog">

    </GridEditSettings>

    <GridEvents CommandClicked="CommandClickHandler" OnActionBegin="ActionBegin" OnActionComplete="ActionComplete" TValue="UserDto"></GridEvents>

    <GridColumns>

        <GridColumn Field="@nameof(UserDto.Id)" Visible="false" IsPrimaryKey="true" ShowInColumnChooser="false"></GridColumn>

        <GridColumn Field="@nameof(UserDto.Email)" Width="150" HeaderText="Email" Type="ColumnType.String"></GridColumn>

And my adaptor:

public class UserAdaptor(IUserService userService) : DataAdaptor

{

    public override async Task<object> ReadAsync(DataManagerRequest dm, string additionalParam = null)

    {

        int skip = dm.Skip;

        int take = dm.Take;


        var showClosedPresent = dm.Params.TryGetValue("ShowClosed", out var showClosed);


        var result = await userService.GetUsers(skip, take, dm.Where, dm.Sorted, showClosed: showClosedPresent && (bool)showClosed);


        return new DataResult

        {

            Result = result.Items, // Here, if user applies filtering on Email e.g., records are correctly returned, with accurate Count as well, but filter still is not recognizing it.

            Count = result.TotalCount

        };

    }

}


5 Replies

SK Sanjay Kumar Suresh Syncfusion Team July 24, 2025 05:04 PM UTC

Hi John,

We reviewed your query, and it seems that filtering is not functioning as expected when using a custom adaptor. Upon checking the provided code, we’d like to inform you that in a custom adaptor, all data operations—including filtering, sorting, searching, and CRUD—must be handled manually. Please refer to the code snippet and the official documentation for further guidance.



UG : https://blazor.syncfusion.com/documentation/datagrid/connecting-to-adaptors/custom-adaptor#handling-filtering-operation

public class CustomAdaptor : DataAdaptor

    {

        // Performs the data read operation.

        public override object Read(DataManagerRequest dm, string key = null)

        {

            // Retrieves the data source.

            IEnumerable<Order> DataSource = Orders;

 

            if (dm.Search != null && dm.Search.Count > 0)

            {

                // Performs searching on the data source.

                DataSource = DataOperations.PerformSearching(DataSource, dm.Search);

            }

            if (dm.Sorted != null && dm.Sorted.Count > 0)

            {

                // Performs sorting on the data source.

                DataSource = DataOperations.PerformSorting(DataSource, dm.Sorted);

            }

            if (dm.Where != null && dm.Where.Count > 0)

            {

                // Performs filtering on the data source.

                DataSource = DataOperations.PerformFiltering(DataSource, dm.Where, dm.Where[0].Operator);

            }

 

            // Counts the total records.

            int count = DataSource.Cast<Order>().Count();

 


Regards,
Sanjay Kumar Suresh



JH John Hegrenes replied to Sanjay Kumar Suresh July 25, 2025 08:47 AM UTC

As I mentioned I'm doing the filtering manually, inside the GetUsers method. I checked with debugger, and, as pointed out in the comment, the return data result object has correctly filtered records, yet it still doesn't function correctly in the grid.

return new DataResult

        {

            Result = result.Items, // Here, if user applies filtering on Email e.g., records are correctly returned, with accurate Count as well, but filter still is not recognizing it.

            Count = result.TotalCount

        };



NP Naveen Palanivel Syncfusion Team July 28, 2025 02:52 PM UTC

Hi Rigoberto,

As per the provided code snippet, we created a sample using an external method to handle filtering and return the data. We tested the sample at our end, but the reported issue did not occur. To further investigate and validate the issue you're facing, we kindly request you to share the following details:


  1. Please share the code snippet used for filter handling on your end.
  2. Share us the video demonstration of the issue with elaborately, it will be more useful to us.
  3. Share us a simple issue replicating sample or try to modify the mentioned sample in previous update.


The above-requested details will be very helpful for us to validate the reported query at our end and provide the solution as early as possible.

Sample : https://blazorplayground.syncfusion.com/embed/BXVINGVPegVCvzcQ?appbar=true&editor=true&result=true&errorlist=true&theme=bootstrap5

Regards,
Naveen



BR Brad November 26, 2025 10:29 PM UTC


The sample solution you posted has the exact same issue mentioned by John Hegrenes. And I am having the same issue in my project. I would expect the Autocomplete in the filter menu to suggest any Customer Name starting with TOM. I did debugging in my project and confirmed the DataAdaptor ReadAsync method is properly returning filtered objects on every keystroke in the autocomplete. The results just don't get displayed.

 



NP Naveen Palanivel Syncfusion Team November 27, 2025 04:08 PM UTC

Hi Brad,

We reviewed your query and it seems that in the custom adaptor with the menu filter, typing a filter value in the textbox does not display suggestions.
The issue occurs because the previous code always returns a DataResult object, even when dm.RequiresCounts is false. Autocomplete expects only the items list in that case, so suggestions fail to display. Please refer to the following code snippet and update the sample accordingly:

Sample : https://blazorplayground.syncfusion.com/LXVosCBGfuhLeJjN

public override async Task<object> ReadAsync(Syncfusion.Blazor.DataManagerRequest dm, string key = null)

{

       var skip = dm.Skip;

     var take = dm.Take;

     var where = dm.Where ?? new List<WhereFilter>();

     var result = await orderService.GetOrdersAsync(skip, take, where);

     return dm.RequiresCounts ? new DataResult() { Result = result.Items, Count = result.TotalCount } : (object)result.Items;

     // return new DataResult

     // {

     //     Result = result.Items,

     //     Count = result.TotalCount

     // };

}


Regards,
Naveen


Loader.
Up arrow icon