[CLOSED] Custom FilterHeader

  1. #1

    [CLOSED] Custom FilterHeader

    I use FilterHeader and its by default search criteria is
    Search term%
    ,how I make enable search with filter header
    %Search term%
    .
    Last edited by Daniil; Aug 22, 2014 at 11:12 AM. Reason: [CLOSED]
  2. #2
    Hi @matrixwebtech,

    This override does the job.
    <script>
        Ext.net.FilterHeader.behaviour.string[0].match = function (recordValue, matchValue) {
            return (Ext.net.FilterHeader.behaviour.getStrValue(recordValue) || "").indexOf(matchValue) > -1;
        }
    </script>
  3. #3
    I just pest this code in head tag.but its not working?recordValue is always null
  4. #4
    It works for me in my test case.

    Please provide your test case.
  5. #5
    In my example there a record in 2nd page "'Common name" column "Marsh Marigold".from first page I search for this record
    my search conditions are

    1. Mar->yes
    2 .mar->no
    3 gold->No

    I am trying to do filter for all above mentioned case but only for 1st case data filter and display in grid.I post sample test case bellow.

    MODEL


    public class remotefilterpaging
        {
    
            public class Plant
            {
                public string Common
                {
                    get;
                    set;
                }
    
                public string Botanical
                {
                    get;
                    set;
                }
    
               
    
                public static Paging<Plant> PlantsPaging(StoreRequestParameters parameters, string filterheader)
                {
                    var data = Plant.GetPlants();
    
    
    
                    return Plant.PlantsPaging(parameters.Start, parameters.Limit, parameters.SimpleSort, parameters.SimpleSortDirection, filterheader);
                }
    
                public static Paging<Plant> PlantsPaging(int start, int limit, string sort, SortDirection dir, string filter)
                {
                    List<Plant> plants = Plant.GetPlants();
    
    
                    FilterHeaderConditions fhc = new FilterHeaderConditions(filter);
    
                    foreach (FilterHeaderCondition condition in fhc.Conditions)
                    {
                        string dataIndex = condition.DataIndex;
                        FilterType type = condition.Type;
                        string op = condition.Operator;
                        object value = null;
    
                        switch (condition.Type)
                        {
                            case FilterType.Boolean:
                                value = condition.Value<bool>();
                                break;
    
                            case FilterType.Date:
                                switch (condition.Operator)
                                {
                                    case "=":
                                        value = condition.Value<DateTime>();
                                        break;
    
                                    case "compare":
                                        value = FilterHeaderComparator<DateTime>.Parse(condition.JsonValue);
                                        break;
                                }
                                break;
    
                            case FilterType.Numeric:
                                bool isInt = plants.Count > 0 && plants[0].GetType().GetProperty(dataIndex).PropertyType == typeof(int);
                                switch (condition.Operator)
                                {
                                    case "=":
                                        if (isInt)
                                        {
                                            value = condition.Value<int>();
                                        }
                                        else
                                        {
                                            value = condition.Value<double>();
                                        }
                                        break;
    
                                    case "compare":
                                        if (isInt)
                                        {
                                            value = FilterHeaderComparator<int>.Parse(condition.JsonValue);
                                        }
                                        else
                                        {
                                            value = FilterHeaderComparator<double>.Parse(condition.JsonValue);
                                        }
    
                                        break;
                                }
    
                                break;
                            case FilterType.String:
                                value = condition.Value<string>();
                                break;
                            default:
                                throw new ArgumentOutOfRangeException();
                        }
    
                        plants.RemoveAll(item =>
                        {
                            object oValue = item.GetType().GetProperty(dataIndex).GetValue(item, null);
                            string matchValue = null;
                            string itemValue = null;
    
                            if (type == FilterType.String)
                            {
                                matchValue = (string)value;
                                itemValue = oValue as string;
                            }
    
                            switch (op)
                            {
                                case "=":
                                    return oValue == null || !oValue.Equals(value);
                                case "compare":
                                    return !((IEquatable<IComparable>)value).Equals((IComparable)oValue);
                                case "+":
                                    return itemValue == null || !itemValue.StartsWith(matchValue);
                                case "-":
                                    return itemValue == null || !itemValue.EndsWith(matchValue);
                                case "!":
                                    return itemValue == null || itemValue.IndexOf(matchValue) >= 0;
                                case "*":
                                    return itemValue == null || itemValue.IndexOf(matchValue) < 0;
                                default:
                                    throw new Exception("Not supported operator");
                            }
                        });
                    }
                    //-- end filtering ------------------------------------------------------------
    
    
                    
                    if ((start + limit) > plants.Count)
                    {
                        limit = plants.Count - start;
                    }
    
                    List<Plant> rangePlants = (start < 0 || limit < 0) ? plants : plants.GetRange(start, limit);
    
                    return new Paging<Plant>(rangePlants, plants.Count);
                }
    
                public static List<Plant> GetPlants()
                {
                    return new List<Plant> { 
                    new Plant 
                    {
                        Common = "Bloodroot",
                        Botanical = "Sanguinaria canadensis",
                       
                    }, 
     
                    new Plant 
                    {
                        Common = "Columbine",
                        Botanical = "Aquilegia canadensis",
                      
                    }, 
     
                    new Plant
                    {
                        Common = "Marsh Marigold",
                        Botanical = "Caltha palustris",
                      
                    }, 
                     
                    new Plant
                    {
                        Common = "Cowslip",
                        Botanical = "Caltha palustris",
                        
                    }, 
                     
                   
                };
                }
            }
        }


    View

    @using Ext.Net;
    @using Ext.Net.MVC;
    @{
        var X = Html.X();
        Layout = null;
    }
       
    <!DOCTYPE html>
       
    <html>
    <head>
        <script>
            Ext.net.FilterHeader.behaviour.string[0].match = function (recordValue, matchValue) {
                return (Ext.net.FilterHeader.behaviour.getStrValue(recordValue) || "").indexOf(matchValue) > -1;
            }
    </script>
        <meta name="viewport" content="width=device-width" />
        <title>Index</title>
    </head>
    <body>
        <div>
            @X.ResourceManager()
       
                 @(
        Html.X().GridPanel()
                .Title("Plants")
                .Frame(true)
                .Height(300)
                .Store(
                    Html.X().Store()
                      
                    .RemoteFilter(true)
                        .Proxy(Html.X().AjaxProxy()
                            .Url(Url.Action("Read"))
                            .Reader(Html.X().JsonReader().Root("data"))
                                                    
                             
                        )
                        
                        .PageSize(2)
                          .Model
                 (
                    X.Model()
                    .Fields
                    (
                       X.ModelField().Name("Common").Type(ModelFieldType.String),
                         X.ModelField().Name("Botanical").Type(ModelFieldType.String)
                          
                    )
                    
                 )
                )
                .ColumnModel(
                    Html.X().Column().DataIndex("Common").Text("Common Name").Flex(1),
                    Html.X().Column().DataIndex("Botanical").Text("Botanical").Width(230)
                 
                      
                )
                        .Plugins
                        (
                        Html.X().FilterHeader().Remote(true)
                              
                        )
                         
                        .BottomBar(
                            Html.X().PagingToolbar()
                                .DisplayInfo(true)
                                .DisplayMsg("Displaying plants {0} - {1} of {2}")
                                .EmptyMsg("No plants to display")
                        )
        )
                
        </div>
    </body>
    </html>
    CONTROLLER

    public ActionResult Index()
            {
                return View();
            }
    
            public ActionResult Read(StoreRequestParameters parameters, string filterheader)
            {
                return this.Store(remotefilterpaging.Plant.PlantsPaging(parameters, filterheader));
            }
    please investigate.
  6. #6
    The filtration happens here:
    case "+":
        return itemValue == null || !itemValue.StartsWith(matchValue);
    "+" is an operator ("op") by default.

    Possible operators are listed here:
    https://examples2.ext.net/#/GridPane...Header/Remote/

    For example, if you type "*gold", it will filter as you need.

    Though, "*mar" won't work still, because filtration is case-sensitive.

    Do you need operators? If no, you can just ignore it and compare "itemValue" and "matchValue" as it needs.
    Last edited by Daniil; Aug 13, 2014 at 1:59 PM.

Similar Threads

  1. [CLOSED] [#514] Print Grid With FilterHeader
    By snow_cap in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: Jun 29, 2014, 7:35 PM
  2. [CLOSED] Filterheader and getRowsValues
    By leonardm in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: May 26, 2014, 5:53 AM
  3. GridPanel : FilterHeader Bug
    By brunweb in forum 2.x Help
    Replies: 7
    Last Post: Apr 01, 2014, 3:08 AM
  4. hidden FilterHeader
    By maxdiable in forum 2.x Help
    Replies: 1
    Last Post: Dec 24, 2013, 1:49 AM
  5. Hide/Show FilterHeader Plugin
    By ADV in forum 2.x Help
    Replies: 2
    Last Post: Dec 24, 2013, 1:46 AM

Posting Permissions