Wednesday, August 28, 2013
Monday, August 26, 2013
Saturday, November 14, 2009
You can reduce the filter menu options to display only a subset of the available filter functions. There are two possible approaches - client-side and server-side.
To limit the filter options displayed for a given column on the client, you need to intercept the OnFilterMenuShowing client event of RadGrid and hide some of the possibles choices from within the body of the respective handler. This solution is suitable when you would like to customize the filter options on a per column basis and still have some of them displayed for particular columns despite they are hidden for others.
Below is a sample code implementation for the OnFilterMenuShowing event:
The following steps describe how to accomplish the same functionality server-side:
Filtering in RadGrid is not case sensitive, however that is not the case when binding to an arraylist, for example. To make sure it does not depend on the case of the underlying datasource, try setting:
GroupingSettings CaseSensitive="false" />
To limit the filter options displayed for a given column on the client, you need to intercept the OnFilterMenuShowing client event of RadGrid and hide some of the possibles choices from within the body of the respective handler. This solution is suitable when you would like to customize the filter options on a per column basis and still have some of them displayed for particular columns despite they are hidden for others.
Below is a sample code implementation for the OnFilterMenuShowing event:
Javascript
ClientSettings>
ClientEvents OnFilterMenuShowing="FilterMenuShowing" />
/ClientSettings>
................
style type="text/css">
.hideFilterOption
{
display: none !important;
}
/style>
................
script type="text/javascript" language="javascript">
var oldFilterStyle = "";
function FilterMenuShowing(sender, eventArgs) {
var menu = eventArgs.get_menu();
var items = menu.get_items();
if (eventArgs.get_column().get_dataType() == "System.String") {
var i = 0;
while (i items.get_count()) {
if (items.getItem(i).get_value() != "StartsWith" && items.getItem(i).get_value() != "Contains") {
var item = items.getItem(i);
if (item != null)
{
if (item.get_element().className != "hideFilterOption")
{
oldFilterStyle = item.get_element().className;
}
item.get_element().className = "hideFilterOption";
}
}
i++;
}
}
else {
var i = 0;
while (i items.get_count()) {
var item = items.getItem(i);
if (item != null)
if(oldFilterStyle != "" && item.get_element().className == "hideFilterOption")
item.get_element().className = oldFilterStyle;
i++;
}
}
}
/script>
The following steps describe how to accomplish the same functionality server-side:
- Provide a handler for the grid's Init event.
- In the Init event handler, use the grid's FilterMenu property to access the filtering menu. There is a single filtering menu server-side, which is cloned for each of the separate filter menus that appear client-side.
- Traverse the items in the filtering menu and determine which of them should be removed by checking their Text property.
- Remove any items that you do not want included in the filter menus using the RemoveAt(index) method of the filtering menu's Items collection.
There is a single filtering menu object server-side. Not all of its items appear in every filter menu client-side. This way of implementation has been chosen to speed up the grid performance by merely creating one menu instance server side and cloning the instance for different columns.
The filtering menu is independent for each column in RadGrid - this means that the filtering menu options vary by the DataType of the corresponding column. Hence integer column will have one set of filter menu options (EqualTo, NotEqualTo, GreaterThan, LessThan, etc.), string column will have additional options (Contains, StartsWith. etc.) and so on. However, if you remove some of the options from the menu on the server, this will affect all grid columns and they will be stripped from each column filter menu options (if available by default for that type of column).
The filtering menu is independent for each column in RadGrid - this means that the filtering menu options vary by the DataType of the corresponding column. Hence integer column will have one set of filter menu options (EqualTo, NotEqualTo, GreaterThan, LessThan, etc.), string column will have additional options (Contains, StartsWith. etc.) and so on. However, if you remove some of the options from the menu on the server, this will affect all grid columns and they will be stripped from each column filter menu options (if available by default for that type of column).
protected void RadGrid1_Init(object sender, System.EventArgs e)
{
GridFilterMenu menu = RadGrid1.FilterMenu;
int i = 0;
while(i < menu.Items.Count)
{
if(menu.Items[i].Text == "NoFilter" ||
menu.Items[i].Text == "Contains" ||
menu.Items[i].Text == "EqualTo" ||
menu.Items[i].Text == "GreaterThan" ||
menu.Items[i].Text == "LessThan")
{
i++;
}
else
{
menu.Items.RemoveAt(i);
}
}
{
GridFilterMenu menu = RadGrid1.FilterMenu;
int i = 0;
while(i < menu.Items.Count)
{
if(menu.Items[i].Text == "NoFilter" ||
menu.Items[i].Text == "Contains" ||
menu.Items[i].Text == "EqualTo" ||
menu.Items[i].Text == "GreaterThan" ||
menu.Items[i].Text == "LessThan")
{
i++;
}
else
{
menu.Items.RemoveAt(i);
}
}
Filtering in RadGrid is not case sensitive, however that is not the case when binding to an arraylist, for example. To make sure it does not depend on the case of the underlying datasource, try setting:
GroupingSettings CaseSensitive="false" />
Subscribe to:
Posts (Atom)