Hello,
I'm attempting to find a solution for updating a RadGrid's filter when the user right clicks a grid cell and selects a filter option. For example, if the user right clicks the column "First Name", a context menu will appear with a list of valid filter options. Once a filter option has been selected, the filter text box will be filled with the value of the right-clicked cell and the selected filter will be applied.
I have done several searches and have not seen any examples similar to this. Are there any samples that exist with this type of functionality? Is this possible with the RadGrid? I have a few potential ideas for a work around, but I wanted to see if this was possible.
Thanks,
Jerry
I'm attempting to find a solution for updating a RadGrid's filter when the user right clicks a grid cell and selects a filter option. For example, if the user right clicks the column "First Name", a context menu will appear with a list of valid filter options. Once a filter option has been selected, the filter text box will be filled with the value of the right-clicked cell and the selected filter will be applied.
I have done several searches and have not seen any examples similar to this. Are there any samples that exist with this type of functionality? Is this possible with the RadGrid? I have a few potential ideas for a work around, but I wanted to see if this was possible.
Thanks,
Jerry
9 Answers, 1 is accepted
0
Hello Jerry,
You can take the main logic from this help article showing how to use a RadContextMenu for column operations. You would only need to add the filtering logic, which would generally consist of firing a filter command with the relevant arguments. You can take a look at this help topic for more details on firing commands from code behind.
All the best,
Tsvetina
the Telerik team
You can take the main logic from this help article showing how to use a RadContextMenu for column operations. You would only need to add the filtering logic, which would generally consist of firing a filter command with the relevant arguments. You can take a look at this help topic for more details on firing commands from code behind.
All the best,
Tsvetina
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
amonte
Top achievements
Rank 1
answered on 22 Nov 2010, 10:17 PM
Hi Tsvetina ,
Thank you for the reply. After reviewing these examples and trying to apply similar concepts in my code, I am still having issues.
When I right click a cell in the RadGrid, I am able to determine which row was right-clicked, but not which column or cell was clicked. Without knowing which column or cell was clicked, I have no way of knowing which column the filter should be applied to (or what value should be applied).
I was trying to get around this by writing code which can detect the cell value and column the user left clicked. I was able to accomplish this by adding logic ColumnCreated (to capture the column names and indexes) and RowCreated (to capture the cell values) functions, but I was unable to force the display of the ContextMenu on a left click. Displaying the menu on left click isn't really that great of an option, but if this is the only way to determine the source column and cell value that triggered the filter request, I might not have another option.
Or am I missing something? Is there another way to make this work?
Thanks,
Jerry
Thank you for the reply. After reviewing these examples and trying to apply similar concepts in my code, I am still having issues.
When I right click a cell in the RadGrid, I am able to determine which row was right-clicked, but not which column or cell was clicked. Without knowing which column or cell was clicked, I have no way of knowing which column the filter should be applied to (or what value should be applied).
I was trying to get around this by writing code which can detect the cell value and column the user left clicked. I was able to accomplish this by adding logic ColumnCreated (to capture the column names and indexes) and RowCreated (to capture the cell values) functions, but I was unable to force the display of the ContextMenu on a left click. Displaying the menu on left click isn't really that great of an option, but if this is the only way to determine the source column and cell value that triggered the filter request, I might not have another option.
Or am I missing something? Is there another way to make this work?
Thanks,
Jerry
0
amonte
Top achievements
Rank 1
answered on 24 Nov 2010, 10:15 PM
I am now using the left click to drive the Context Menu with the filtering choices (not my first choice, but an acceptable alternative), but I am having an issue getting the grid to actually apply the filter using this method.
I was able to sucessfully apply filters using this Javascript:
But I can't seem to find an equivalent to use in the code behind. The closest I came to having success was this:
But it requires me to build the FilterExpression each time and the syntax that the grid is returning doesn't seem as clear as what I'm finding in the Telerik documentation:
(it[\"DateDue\"].ToString().Contains(\"05/08/2010\")) AND (it[\"DateDocument\"].ToString().Contains(\"09/15/2010\"))
is there a way to do this from the code behind WITHOUT having to write the filter expression?
I was able to sucessfully apply filters using this Javascript:
masterTable.filter(columnName, cellValue, Telerik.Web.UI.GridFilterFunction.Contains)
But I can't seem to find an equivalent to use in the code behind. The closest I came to having success was this:
rgEOBs.MasterTableView.FilterExpression =
"([" + name + "] LIKE '%" + value + "%') ";
GridColumn column = rgEOBs.MasterTableView.GetColumnSafe(name);
column.CurrentFilterFunction =
GridKnownFunction.Contains;
column.CurrentFilterValue = value;
rgEOBs.Rebind();
But it requires me to build the FilterExpression each time and the syntax that the grid is returning doesn't seem as clear as what I'm finding in the Telerik documentation:
(it[\"DateDue\"].ToString().Contains(\"05/08/2010\")) AND (it[\"DateDocument\"].ToString().Contains(\"09/15/2010\"))
is there a way to do this from the code behind WITHOUT having to write the filter expression?
0
Hello Jerry,
Have you tried firing a filter command from code-behind using the FireCommandEvent() method. If not, please, take a look at this help article:
How to fire command events from code
Greetings,
Tsvetina
the Telerik team
Have you tried firing a filter command from code-behind using the FireCommandEvent() method. If not, please, take a look at this help article:
How to fire command events from code
Greetings,
Tsvetina
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
amonte
Top achievements
Rank 1
answered on 29 Nov 2010, 03:07 PM
Tsvetina,
This is the same article you linked in your first response. Yes, I tried it. It did not work. Part of the problem is that the FireCommandEvent for the filter only takes the "filter type" (contains, like, etc.) and the column name:
FireCommandEvent("Filter", new Pair(menuItem.Value,columnUniqueName))
The Javascript equivalent accepts the column name, the value and the filter type:
Is there a way to do something similar from the code behind?
Thanks,
Jerry
This is the same article you linked in your first response. Yes, I tried it. It did not work. Part of the problem is that the FireCommandEvent for the filter only takes the "filter type" (contains, like, etc.) and the column name:
FireCommandEvent("Filter", new Pair(menuItem.Value,columnUniqueName))
The Javascript equivalent accepts the column name, the value and the filter type:
filter(columnName, cellValue, Telerik.Web.UI.GridFilterFunction.Contains)
Is there a way to do something similar from the code behind?
Thanks,
Jerry
0
Hello Jerry,
You said that you managed to get a reference to the column that is to be filtered. So, it should be fine to first set its CurrentFilterValue property of the column and then use the FireCommandEvent method.
Additionally, the filter expression should look simpler if you set EnableLinqExpressions to false.
Best wishes,
Tsvetina
the Telerik team
You said that you managed to get a reference to the column that is to be filtered. So, it should be fine to first set its CurrentFilterValue property of the column and then use the FireCommandEvent method.
Additionally, the filter expression should look simpler if you set EnableLinqExpressions to false.
Best wishes,
Tsvetina
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
amonte
Top achievements
Rank 1
answered on 29 Nov 2010, 08:14 PM
protected void RadMenu1_ItemClick(object sender, RadMenuEventArgs e)
{
string name = Convert.ToString(Request.Form["filterColumnName"]);
string value = Convert.ToString(Request.Form["filterColumnValue"]);
GridColumn column = rgEOBs.MasterTableView.GetColumnSafe(name);
column.CurrentFilterValue = value;
GridFilteringItem filterItem = rgEOBs.MasterTableView.GetItems(GridItemType.FilteringItem)[0] as GridFilteringItem;
filterItem.FireCommandEvent("Filter", new Pair(e.Item.Text, name));
}
Hello Tsvetina,
Maybe I am missing something. I have pasted the code above. I don't get any errors, but the filter does not fire and the filter value does not appear above the column being filtered. The values of "name" and "value" are being updated via Javascript and the code updating these fields is working fine.
Thanks,
Jerry
0
amonte
Top achievements
Rank 1
answered on 29 Nov 2010, 09:14 PM
I also attempted to update the grid with the following code.
This also had the same result - no errors thrown, but the grid was not refreshed.
GridColumn column = rgEOBs.MasterTableView.GetColumnSafe(name);
column.CurrentFilterValue = value;
rgEOBs.MasterTableView.FilterExpression = "([" + name + "] LIKE \'%" + value + "%\') ";
column.CurrentFilterFunction = GridKnownFunction.Contains;
column.CurrentFilterValue = value;
rgEOBs.MasterTableView.Rebind();
This also had the same result - no errors thrown, but the grid was not refreshed.
0
amonte
Top achievements
Rank 1
answered on 30 Nov 2010, 04:19 PM
I found the issue - my grid was not correctly hooked up to the Ajax Panel, similar to the issue this user had.
http://www.telerik.com/community/forums/aspnet-ajax/grid/radgrid-not-refreshing.aspx#604059
http://www.telerik.com/community/forums/aspnet-ajax/grid/radgrid-not-refreshing.aspx#604059