CreateFilterExpression cannot work on dynamically created types.

8 posts, 0 answers
  1. Jitin
    Jitin avatar
    9 posts
    Member since:
    Jun 2009

    Posted 27 Jul 2009 Link to this post

    Hi,

    In Q1 version, for filtering the grid on text (search as you type) - I was following the FilterDescription derived class with overridden method bool SatisfiesFilter(object dataItem); It uses the UniqueName on columns as property for search. This version was apprently using the getting the property information emitted through reflection on these dynamic types. It was working just fine. But in Q2 version, FilterDescription has become obsolete. I used the latest code provided in Telerik example using FieldDescriptor. The method CreateFilterExpression(ParameterExpression parameterExpression) throws argument exception (Invalid property or field) on the same set of data loaded on the grid.
    Am I supposed to not use CreateFilterExpression method and provide my own implementation, or is there something I am not doing right?

    Thanks in advance,
    Jitin
  2. Stefan Dobrev
    Admin
    Stefan Dobrev avatar
    790 posts

    Posted 27 Jul 2009 Link to this post

    Hi Jitin,

    You can still use your own FilterDescription, but you should add it to the FilterDescriptors collection of RadGridView:
    this.GridView.FilterDescriptors.Add(new MyFilterDescription()); 

    If want to use FilterDescriptor you should set the Member property of FilterDescriptor to name of a valid property of your business object. For example if you want to filter by Name property of a Customer object you can add a FilterDescriptor like this:
    this.CustomersGridView.FilterDescriptors.Add(new FilterDescriptor("Name", FilterOperator.Contains, "John")); 


    Regards,
    Stefan Dobrev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Jitin
    Jitin avatar
    9 posts
    Member since:
    Jun 2009

    Posted 27 Jul 2009 Link to this post

    Thanks for your reply.

    My situation is little bit more complicated than that. Let's assume my object had composite key IDs -say ID1 and ID2 beside other properties. Now I want to filter the grid for these two conditions:
    Either:  ID1 == "A" AND ID2 == "X"
    OR       ID1 == "B" AND ID2 == "Y"
    OR       ID1 ==  "C" AND ID2 == "Z"

    How can apply this filter? A code like this would remove all items in the grid:

    this.radSourceGridNodes.FilterDescriptors.Add(new FilterDescriptor("ID1", FilterOperator.Contains, "A"));
    this.radSourceGridNodes.FilterDescriptors.Add(new FilterDescriptor("ID1", FilterOperator.Contains, "B"));

    Thanks,
    Jitin
  4. Jitin
    Jitin avatar
    9 posts
    Member since:
    Jun 2009

    Posted 27 Jul 2009 Link to this post

    I found the way to do this.
    I realized that I can use CompositeFilterDescriptor at multiple levels. I created two or more instances of CompositeFilterDescriptor - one for the grid and one for the actual condition. The instance for the grid contains the other ones.

    Here is an example if anyone else need similar usage:

    CompositeFilterDescriptor compositeFilterDescriptor = new CompositeFilterDescriptor();
    CompositeFilterDescriptor compositeFilterDescriptorID1 = new CompositeFilterDescriptor();
    compositeFilterDescriptorID1.LogicalOperator = FilterCompositionLogicalOperator.And;

    CompositeFilterDescriptor compositeFilterDescriptorID2 = new CompositeFilterDescriptor();
    compositeFilterDescriptorID2.LogicalOperator = FilterCompositionLogicalOperator.And;

    compositeFilterDescriptorID1.FilterDescriptors.Add(new FilterDescriptor("ID1", FilterOperator.Contains, "A"));
    compositeFilterDescriptorID1.FilterDescriptors.Add(new FilterDescriptor("ID2", FilterOperator.Contains, "X"));

    compositeFilterDescriptorID2.FilterDescriptors.Add(new FilterDescriptor("ID1", FilterOperator.Contains, "B"));
    compositeFilterDescriptorID2.FilterDescriptors.Add(new FilterDescriptor("ID2", FilterOperator.Contains, "Y"));

    compositeFilterDescriptor.FilterDescriptors.Add(compositeFilterDescriptorID1);
    compositeFilterDescriptor.FilterDescriptors.Add(compositeFilterDescriptorID2);
    this.radGrid.FilterDescriptors.Add(compositeFilterDescriptor);

    Thanks,
    Jitin
  5. Sheraz Naseeb
    Sheraz Naseeb avatar
    22 posts
    Member since:
    Mar 2010

    Posted 02 Sep 2010 Link to this post

    Hi Telerik Team,

    I am using Q1 2009 and this code does not work on my end. Infact I am unable to find FilterDescriptor I am using FilterExpression instead but seems it doesnt work either. Following is the code snippet I am using please help me how can I filter the grid without using its own filtering row.

    Dim filter As New Telerik.WinControls.Data.FilterExpression()
     
            grd.MasterGridViewTemplate.FilterExpressions.Clear()
     
            filter.Predicates.Add(Telerik.WinControls.Data.FilterExpression.BinaryOperation.AND, GridKnownFunction.StartsWith, GridFilterCellElement.ParameterName)
            filter.Parameters.Add(GridFilterCellElement.ParameterName, grd.Columns("ColumnName").ToString)
            filter.Parameters.Add("ColumnName Like ", txt.Text)
            grd.MasterGridViewTemplate.FilterExpressions.Add(filter)

    Please help,
    Many thanks,
    Sheraz
  6. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 02 Sep 2010 Link to this post

    Hello,

     This code is not related to our Silverlight grid. As far as I can see this is related to our Winforms grid.

    Sincerely yours,
    Vlad
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  7. Avag
    Avag avatar
    1 posts
    Member since:
    Apr 2018

    Posted 25 Jun in reply to Stefan Dobrev Link to this post

    I have a problem with filtering dynamic types too. 
    I have a datarow of custom type and add properties to it during runtime. 
    However in the CreateFilterExpression method i get en error.

    Instance property 'name' is not defined for type 'DataRow'.

    how can i make Expression.Property to resolve dynamic properties?
  8. Vladimir Stoyanov
    Admin
    Vladimir Stoyanov avatar
    217 posts

    Posted 28 Jun Link to this post

    Hello Avag,

    Can you check out the Filter a Custom Type article in our documentation? If that does not prove helpful, may I ask you to open a new support ticket and ideally provide a sample project demonstrating your scenario? If that is not possible, you can elaborate a bit on how you are setting up the RadGridView and the DataTable as well as how you are attempting to filter it. Providing some code snippets would also be of help.This way we will be able to investigate this on our side.

    I hope you find this helpful.

    Regards,
    Vladimir Stoyanov
    Progress Telerik
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top