This is a migrated thread and some comments may be shown as answers.

FilterExpression

1 Answer 25 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Paulo
Top achievements
Rank 1
Paulo asked on 22 May 2014, 04:07 AM
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

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 26 May 2014, 08:09 AM
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.

 
Tags
Grid
Asked by
Paulo
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or