[CLOSED] FilterHeader plugin : override Operator of Parameters["filterheader"]

  1. #1

    [CLOSED] FilterHeader plugin : override Operator of Parameters["filterheader"]

    In example Operator automatically set for different data type ,but what if I want to change may be I want to pass * for all data types .
    Last edited by Daniil; Apr 21, 2015 at 12:32 PM. Reason: [CLOSED]
  2. #2
    Hi @matrixwebtech,

    Yes, the * operator is available for strings only.

    This example demonstrates how to define a custom operator.
    https://examples2.ext.net/#/GridPane...stom_Behaviour

    Here you can investigate how the * operator is defined for strings. Please search for op: "*":
    http://svn.ext.net/premium/trunk/Ext...eader-debug.js
  3. #3
    Hi Daniil
    Thakns for reply,I will study your suggestion today but yesterday before post I do this with server side code and working as I want please check and tell me this approach is correct or not .

    public Paging<object> RemotePagingAndFilter(int start, int limit, string sort, SortDirection dir, string filter)
            {
    
                var data = this.GetData();
    
    
                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 = data.Count > 0 && data[0].GetType().GetProperty(dataIndex).PropertyType == typeof(int);
                            bool isInt64 = data.Count > 0 && data[0].GetType().GetProperty(dataIndex).PropertyType == typeof(Int64);
                            switch (condition.Operator)
                            {
                                case "=":
                                    if (isInt)
                                    {
                                        value = condition.Value<int>();
                                    }
                                        else if(isInt64)
                                    {
                                        value = condition.Value<Int64>();
                                    }
                                    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();
                    }
    
                    data.RemoveAll(item =>
                    {
                        object oValue = item.GetType().GetProperty(dataIndex).GetValue(item, null);
                        string matchValue = null;
                        string itemValue = null;
    
                        if (type == FilterType.String)
                        {
                            matchValue = (string)value.ToString().ToLower();
                            itemValue = oValue.ToString().ToLower() as string;
                        }
    
                        if(type==FilterType.Numeric)
                        {
                            matchValue = (string)value.ToString().ToLower();
                            itemValue =Convert.ToString(oValue);
                        }
                        switch (type)
                        {
                            case FilterType.String:
                                return itemValue == null || itemValue.IndexOf(matchValue) < 0;
                                
                            case FilterType.Numeric:
                               
                                return itemValue == null || !itemValue.StartsWith(matchValue);
                            default:
                                throw new Exception("Not supported operator"); 
                        }
                       
                        
                    });
                }
                //-- end filtering ------------------------------------------------------------
    
    
                
    
                if ((start + limit) > data.Count)
                {
                    limit = data.Count - start;
                }
    
                List<tbl_SysMenuMaster> rangePlants = (start < 0 || limit < 0) ? data : data.GetRange(start, limit);
    
                return new Paging<object>(rangePlants, data.Count);
            }
  4. #4
    At the first glance I don't see anything wrong in your solution. If it works as you need, it is definitely a way to go.

Similar Threads

  1. [CLOSED] FilterHeader : FilterHeader for specific columns in gridpanel
    By matrixwebtech in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: Mar 29, 2015, 12:20 PM
  2. [CLOSED] Default operator for FilterHeader fields
    By metci in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: Aug 20, 2014, 12:02 PM
  3. Hide/Show FilterHeader Plugin
    By ADV in forum 2.x Help
    Replies: 2
    Last Post: Dec 24, 2013, 1:46 AM
  4. Replies: 4
    Last Post: Nov 19, 2013, 1:11 PM
  5. Replies: 1
    Last Post: Oct 21, 2011, 6:15 PM

Posting Permissions