I am currently using a ListBox
to select a bunch of long
values and then filtering a column based on this. Works a treat. No worries.
For another column, I'm trying to apply a filter that's a little more complicated than the FilterOperator
options that are available. It's more like a combination of what's on offer.
I have a list of words in a ListBox
that will build up an IEnumerable<string>
as they are selected, similar to the IEnumerable<long>
above.
I then need to filter based on whether my column value contains ANY or ALL (a selectable parameter) of these strings. Nothing seems to fit.
Looking at the Radzen code, I see that a filter declared with an operator of FilterOperator.Custom
just returns an empty string or is ignored. It doesn't build a filter string for you.
Does this mean that we can build our own custom filter string? And if so, how do we use it / where do we store our custom string?
Regards
Paul
Hi @Paul_Ruston,
FilterOperator.Custom
is really used at the moment. If you want to implement custom filtering check the Custom filtering with LoadData demo.
void LoadData(LoadDataArgs args)
{
var query = dbContext.Customers.AsQueryable();
if (!string.IsNullOrEmpty(args.Filter))
{
query = query.Where(c => c.CustomerID.ToLower().Contains(args.Filter.ToLower()) || c.ContactName.ToLower().Contains(args.Filter.ToLower()));
}
customers = query.ToList();
InvokeAsync(StateHasChanged);
}
Hi @korchev
That would work up to a point. But I may be including an option to output the grid to csv, sending the grids Query property to the Export method. It would mean having to remember to add whatever outside filtering as been applied.
How does this sound?
We create a string property on RadzenDataGridColumn
called CustomFilter
.
Then, in the method that builds the filter string in QueryableExtension.cs
public static string ToFilterString<T>(this IEnumerable<RadzenDataGridColumn<T>> columns)
we test and add to whereList the newly created CustomFilter property.
if (column.FilterOperator == FilterOperator.Custom)
{
whereList.Add(column.CustomFilter);
}
else if (PropertyAccess.IsDate(column.FilterPropertyType))
e.t.c...
If this sounds acceptable, I'll make the changes and create a PR.
Regards
Paul
EDIT MADE - Code Edited
Hi @korchev
Scratch the above. Turns out it's not as simple as that. I'll keep stepping through code and see what's occurring.
Paul