Completed
Last Updated: 27 Mar 2020 09:26 by ADMIN
René
Created on: 06 Nov 2019 08:11
Category: Grid
Type: Feature Request
19
Ability to set filters programatically
This is needed to be able to create quick filter buttons or a custom search panel.
4 comments
ADMIN
Marin Bratanov
Posted on: 25 Mar 2020 10:44

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

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Nicola
Posted on: 25 Mar 2020 10:41

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();
    }

 

René
Posted on: 07 Nov 2019 07:44

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

}

 

ADMIN
Marin Bratanov
Posted on: 06 Nov 2019 19:07

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

 UI for Blazor