CompositeFilterDescriptor To FilterDescriptor Conversion issues

3 posts, 0 answers
  1. Sairam
    Sairam avatar
    56 posts
    Member since:
    May 2013

    Posted 28 May 2015 Link to this post

    Hi support Team,

     In Kendo ui Grid ...I am Apply the Composite Filter ...But Problem with The ...Here in Filter ....I have some  "True" or "False"  Column ......Instead of Showing The "True"  ...."Y" and "False" ...."N"...So  I am Apply Following Logic For that 

     C# Code When User Gives  "Y" or "N"....based on That  .....setting True or False.

       private static void addFilter(XElement newFilter, FilterDescriptor firstFilter, string crmAttributeName, GetCrmColumnName getColumnInfo)
         {
                if (firstFilter.Member == "OnHold")
             {
                    if (firstFilter.Value.ToString().ToLower() == "y")
                    {
                        firstFilter.Value = true;
                    }
                    else if (firstFilter.Value.ToString().ToLower() == "n")
                    {
                        firstFilter.Value = false;
                    }
                }
                    newFilter.Add(new XElement("condition",
                        new XAttribute("attribute", crmAttributeName),
                        new XAttribute("operator", getOperator(firstFilter.Operator, crmAttributeName)),
                        new XAttribute("value", String.Format(getOperatorFormat(firstFilter.Operator), firstFilter.Value.ToString().Trim()))));           
            }

     After Result Came I Need To ..Assign Same "Y" or "N"

    So I Write The Following code

        foreach (var n in request.Filters)
                {           
                        if (((FilterDescriptor)(n)).Member == "OnHold")
                        {
                            if (((FilterDescriptor)(n)).Value.ToString().ToLower() == "true")
                            {
                                ((FilterDescriptor)(n)).Value = "y";
                            }
                            else
                            {
                                ((FilterDescriptor)(n)).Value = "n";
                            }
                        
                    }          
                }

     

    It Work Fine ....For Normal Filter ...When ...I suppose ....Use CompositeFilter Then  I got Problem....If ...Work with Composite Filter ..I need Display ...Not Empty or an error...

     

     

      foreach (var n in request.Filters)
                {
                    if (n is CompositeFilterDescriptor==true)
                    {
                        if (((CompositeFilterDescriptor)(n)).FilterDescriptors.Count() >= 2)
                        {
                         
                        }
                    }
                    else
                    {       
                        if (((FilterDescriptor)(n)).Member == "OnHold")
                        {
                            if (((FilterDescriptor)(n)).Value.ToString().ToLower() == "true")
                            {
                                ((FilterDescriptor)(n)).Value = "y";
                            }
                            else
                            {
                                ((FilterDescriptor)(n)).Value = "n";
                            }
                        }
                    }          
                }

    Currently.....It  Work For Composite Filter also..But when .....we Include Filter Of "Y" or "N".....I got ...Problem....When User Give even Though ..."Y" or "N"...Columns in the Composite Filter.....We need to Display....matched Columns.....

     

     

  2. Rosen
    Admin
    Rosen avatar
    3234 posts

    Posted 02 Jun 2015 Link to this post

    Hello Sairam,

    I'm afraid I'm not sure what your are trying to achieve nor what it the exact issue you are facing. However, if you want to extract only the member filter descriptors you can do this by recursively looping over the filter hierarchy. Using similar to the following extension method:

     

    public static class EnumerableExtensions
    {
        public static IEnumerable<FilterDescriptor> SelectMemberDescriptors(this IEnumerable<IFilterDescriptor> descriptors)
        {
            return descriptors.SelectRecursive(f => GetChildDescriptors(f)).OfType<FilterDescriptor>();
        }
      
        private static IEnumerable<IFilterDescriptor> GetChildDescriptors(IFilterDescriptor f)
        {
            if (f is CompositeFilterDescriptor)
            {
                return ((CompositeFilterDescriptor)f).FilterDescriptors;
            }
            return null;
        }
      
        public static IEnumerable<TSource> SelectRecursive<TSource>(this IEnumerable<TSource> source,
            Func<TSource, IEnumerable<TSource>> recursiveSelector)
        {
            Stack<IEnumerator<TSource>> stack = new Stack<IEnumerator<TSource>>();
            stack.Push(source.GetEnumerator());
      
            try
            {
                while (stack.Count > 0)
                {
                    if (stack.Peek().MoveNext())
                    {
                        TSource current = stack.Peek().Current;
      
                        yield return current;
      
                        IEnumerable<TSource> children = recursiveSelector(current);
                        if (children != null)
                        {
                            stack.Push(children.GetEnumerator());
                        }
                    }
                    else
                    {
                        stack.Pop().Dispose();
                    }
                }
            }
            finally
            {
                while (stack.Count > 0)
                {
                    stack.Pop().Dispose();
                }
            }
        }
    }


    and it usage:

    if (request.Filters.Any())
    {
        foreach (var filter in request.Filters.SelectMemberDescriptors())
        {
            if (filter.Member == "OnHold")
            {
             //...
            }
        }
    }

     

    Regards,
    Rosen
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Sairam
    Sairam avatar
    56 posts
    Member since:
    May 2013

    Posted 09 Jun 2015 in reply to Rosen Link to this post

    Thanks  Rosen u r help...I am try it Different ....Working fine ...Change The filter  Member 

        private void ModifyFilters(IEnumerable<IFilterDescriptor> filters)
            {
                if (filters.Any())
                {
                    foreach (var filter in filters)
                    {
                        var descriptor = filter as FilterDescriptor;

                                    if (descriptor != null && descriptor.Member == "PurchaseOrderDateTime")
                        {
                            descriptor.Member = "PurchaseOrderDate";
                        }

     else if (descriptor != null && descriptor.Member == "OnHold")
                        {
                            descriptor.Member = "OnHoldBool";
                        }

                       else if (filter is CompositeFilterDescriptor)
                        {
                            ModifyFilters(((CompositeFilterDescriptor)filter).FilterDescriptors);
                        }

    }

    }

    }

     

     

Back to Top