I work on blazor server side .asp.net core 7 . I face issue I can't return data after filter from list on Radzen data grid
First I create radzen data grid on razor page
second I create list that receive data after filter
private IEnumerable databaseData = Array.Empty();
public class CopyExcelDatabaseClass
{
public string databaseName { get; set; }
public int serverID { get; set; }
public string serverName { get; set; }
public string severity { get; set; }
}
third function is filter list based on dynamic condition get it from myDataGrid.Query.Filter
public void getListDataAfterFilter()
{
var query = myDataGrid.Query.Filter;
var filteredList = databaseData.Where(query).ToList();
}
this statement return condition Filter from radzen data grid after write filters
var query = myDataGrid.Query.Filter;
return below filter condition
(databaseName == null ? "" : databaseName).ToLower().Contains("Menna".ToLower()) and (serverity == null ? "" : serverity).ToLower().Contains("Mon".ToLower())
I try to get result from above and it worked fine
var filteredList = databaseData.Where(item => item.databaseName.Contains("DB_U")).ToList();
but issue it static and I need it dynamically meaning based on condition filter Query.Filter
Mohammad HussainPosted Jul 26, 2023, 9:31 AM
It seems like you are trying to filter the `databaseData` list dynamically based on the conditions provided in the `Query.Filter` of the RadzenDataGrid. The `Query.Filter` returns a filter condition in the form of a string, and you want to use this string to filter the `databaseData` list.
To achieve this, you can use a library like Dynamic Linq to parse and apply the filter condition as a dynamic predicate on the `databaseData` list. Here's how you can do it:
1. Install the Dynamic Linq library using NuGet. Open the NuGet Package Manager Console and run the following command:
```
Install-Package System.Linq.Dynamic.Core
```
2. Import the `System.Linq.Dynamic.Core` namespace in your code file.
3. Modify the `getListDataAfterFilter` method to dynamically filter the `databaseData` list using the `Query.Filter` condition:
By using `System.Linq.Dynamic.Core`, you can apply the filter condition in a dynamic and flexible way. Make sure to handle any potential errors that may arise due to incorrect filter conditions.
ahmed salahPosted Jul 28, 2023, 5:26 PM
solved success thanks