FilterExpression

2 posts, 0 answers
  1. Paulo
    Paulo avatar
    30 posts
    Member since:
    Mar 2013

    Posted 21 May 2014 Link to this post

    Hi I have a radgrid with a mastertableview. The grid has 4 columns. Two of them are RadCombobox and the other two are RadDatePicker. All filters are "EqualTo".  All filter works fine. On the CommandItem I have two radiobuttons that when clicked brings the last 15 and 30 days data. In this case in the commandItem on code behind I am recunstructing the filterexpression and replacing the "([UpdateDate] = '" per "([UpdateDate] >= '". I have tested and it works for some situations. The only time it is not working is when there are not data for that grater or equal date. Instead of bringing an empty grid it crashes saying out of range where I am calling the rebind() function.

    Thank you
  2. Eyup
    Admin
    Eyup avatar
    3005 posts

    Posted 26 May 2014 Link to this post

    Hi Paulo,

    Please note that modifying the FilterExpression is quite tricky and it can be error-prone, therefore, it is not recommended.

    Instead, you can use the FireCommandEvent method to achieve the requested functionality:
    http://www.telerik.com/help/aspnet-ajax/grid-fire-command-event-from-code.html
    For a client-side approach, the method is called fireCommand:
    http://www.telerik.com/help/aspnet-ajax/grid-gridtableview-firecommand.html

    For example, in case you want to apply an initial filter, you can use the following approach:
    Copy Code
    Copy Code
    protected void RadGrid1_PreRender(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            GridFilteringItem filterItem = RadGrid1.MasterTableView.GetItems(
                 GridItemType.FilteringItem)[0] as GridFilteringItem;
      
            GridColumn col = RadGrid1.MasterTableView.GetColumn("ShipName");
            col.CurrentFilterValue = "Success";
            filterItem.FireCommandEvent("Filter", new Pair("StartsWith", "ShipName"));
        }
    }

    In addition, I'm attaching a sample to demonstrate how you can build your custom filter expression in case you need to filter on multiple columns at once.

    Hope this helps.


    Regards,
    Eyup
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top