Indeed, using the grid state is the way to do this, you can read more about it here: https://docs.telerik.com/blazor-ui/components/grid/state
Regards,
Marin Bratanov
Progress Telerik
The following code is applied as ValueChanged="@((int v) => FilterGrid(v))" on a TelerikDropDownList
protected void FilterGrid(int value)
{
// this is the Value="@ImportStatusId" of DropDownList
ImportStatusId = value;
GridState<ImportRatesGridModel> gridState = theGrid.GetState();
foreach (var filterItem in gridState.FilterDescriptors)
{
FilterDescriptor descriptor = null;
if (filterItem is FilterDescriptor)
{
descriptor = filterItem as FilterDescriptor;
}
else
{
descriptor = (filterItem as CompositeFilterDescriptor).FilterDescriptors[0] as FilterDescriptor;
}
if (descriptor.Member.Equals("ImportStatusId"))
{
(gridState.FilterDescriptors as ICollection<FilterDescriptorBase>).Remove(filterItem);
break;
}
}
if (value > 0)
{
(gridState.FilterDescriptors as ICollection<FilterDescriptorBase>).Add(
new CompositeFilterDescriptor()
{
FilterDescriptors = new FilterDescriptorCollection()
{
new FilterDescriptor() {
Member = "ImportStatusId",
MemberType = typeof(int),
Operator = FilterOperator.IsEqualTo,
Value = value
}
}
});
}
theGrid.SetState(gridState);
StateHasChanged();
}
Hello Marin,
It should probably look something like this:
<TelerikGrid Data="@GridData" Filters="@MyFilters">...</TelerikGrid>
@code{
public List<TelerikGridFilter> MyFilters { get; set; }
}
public class TelerikGridFilter
{
public string Field { get; set; }
public TelerikGridFilterOperatorEnum Operator { get; set; }
public object Value { get; set; }
public TelerikGridFilterLogicEnum Logic {get; set; }
public List<TelerikGridFilter> Filters { get; set; }
}
Hello René,
If you have a suggestion or preference on how this should be exposed in the grid API, please post a comment.
Regards,
Marin Bratanov
Progress Telerik