Skip to main content

GridViewSettings.HeaderFilterFillItems Property

Allows you to populate a filter dropdown with custom filter items.

Namespace: DevExpress.Web.Mvc

Assembly: DevExpress.Web.Mvc5.v24.1.dll

NuGet Package: DevExpress.Web.Mvc5

Declaration

public ASPxGridViewHeaderFilterEventHandler HeaderFilterFillItems { get; set; }

Property Value

Type Description
ASPxGridViewHeaderFilterEventHandler

A ASPxGridViewHeaderFilterEventHandler delegate method allowing you to implement custom processing.

Remarks

Example

Full example - GridView - Header Filter

@Html.DevExpress().GridView(settings => {
    settings.Name = "gvFiltering";

    settings.Settings.ShowHeaderFilterButton = true;
    settings.SettingsPopup.HeaderFilter.Height = 200;
    settings.SettingsPopup.HeaderFilter.SettingsAdaptivity.MinHeight = 300;

    settings.HeaderFilterFillItems = (sender, e) => {
        ASPxGridView grid = (ASPxGridView)sender;
        if(e.Column.FieldName == "Total") {
            e.Values.Clear();
            if(e.Column.SettingsHeaderFilter.Mode == GridHeaderFilterMode.List)
            e.AddShowAll();
            int step = 100;
            for(int i = 0; i < 10; i++) {
                double start = step * i;
                double end = start + step - 0.01;
                e.AddValue(string.Format("from {0:c} to {1:c}", start, end), string.Empty, string.Format("[Total] >= {0} and [Total] <= {1}", start, end));
            }
            e.AddValue(string.Format("> {0:c}", 1000), string.Empty, "[Total] > 1000");
        } else if(e.Column.FieldName == "Quantity") {
            int max = 0;
            for(int i = 0; i < e.Values.Count; i++) {
                int value;
                if(!int.TryParse(e.Values[i].Value, out value))
                    continue;
                if(value > max)
                    max = value;
            }
            e.Values.Clear();
            if(e.Column.SettingsHeaderFilter.Mode == GridHeaderFilterMode.List)
            e.AddShowAll();
            int step = 10;
            for(int i = 0; i < max / step + 1; i++) {
                int start = step * i;
                int end = start + step - 1;
                e.AddValue(string.Format("from {0} to {1}", start, end), string.Empty, string.Format("[Quantity] >= {0} and [Quantity] <= {1}", start, end));
            }
        }
    };
    ...
}).Bind(Model).GetHtml()

Online Demo

GridView - Header Filter

See Also