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
};
}
}
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.
|
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
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
};
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:
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
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.
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