I have an query that how can i customize Rad grid view custom filter dialog box.
Like mun text and all.
Thanks & regards
Pulkit Jain
13 Answers, 1 is accepted
Currently it is not possible to replace this dialog. However you can add your own dialog by handling ContextMenuOpening event and adding a new menu item. We plan to extend the filtering functionality and the feature will be available in one of our upcoming releases.
Jack
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.
Can we remove the menuitem for custom filtering?
Can we only cusomize the name of the custom filter dialogbox?
Thanks & regards
Pulkit Jain
Regarding your questions:
1. Yes, you can remove it by handling ContextMenuOpening event. Here is a sample:
void
radGridView1_ContextMenuOpening(
object
sender, ContextMenuOpeningEventArgs e)
{
if
(e.ContextMenuProvider ==
null
)
{
e.ContextMenu.Items.RemoveAt(e.ContextMenu.Items.Count - 1);
}
}
2. You have to create a custom cell element to rename the custom filtering form. Please consider the code below:
void
radGridView1_CreateCell(
object
sender, GridViewCreateCellEventArgs e)
{
if
(e.CellType ==
typeof
(GridFilterCellElement))
{
e.CellType =
typeof
(MyFilterCell);
}
}
public
class
MyFilterCell : GridFilterCellElement
{
public
MyFilterCell(GridViewDataColumn column, GridRowElement row)
:
base
(column, row)
{
}
protected
override
Type ThemeEffectiveType
{
get
{
return
typeof
(GridFilterCellElement); }
}
protected
override
CompositeFilterForm CreateCompositeFilterForm()
{
CompositeFilterForm form =
base
.CreateCompositeFilterForm();
form.Text =
"My Filter form"
;
return
form;
}
}
I hope this helps.
Regards,
Jack
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.
Thank you for your report.
The method CreateCompositeFilterForm that my colleague uses to replace the default composite form is not public in the latest version. It will be available in the upcoming version Q3 2010 SP1.
Svett
the Telerik team
The problem is the CurrentColumn.Name of the RadGridview doesn't change unless the user physically selects the cell in the column below the filter row or the text box for the filter and in the instance of 'No Filter' this is not abundantly transparent to the user to click there, if they immediately select the filter button for a column without selecting a cell in the column -- it is set to whatever the last column was that they had clicked on regardless of what button for the filter they clicked on. In my example, I need to remove all but two of the menus on the context menu for the filter - not just the Custom option. Other columns on the grid (over 320 of them and various types) require the default menus provided my Telerik.
I have solved the problem by this block of code, but it seems like a hack and I know later on this could lead to additional problems:
// HACK: This will not work in all instances but it fixes the problem Design had with the menu
// having values that don't make sense based on the grid.
if (e.ContextMenu.Items.Count == 6)
{
string currentColumn = radGridView.CurrentColumn.Name; // sanity check to prove current column name is bogus
int minValue = e.ContextMenu.Items.Count - 5;
for (int x = e.ContextMenu.Items.Count - 1; x > minValue; x--)
e.ContextMenu.Items.RemoveAt(x);
}
I'm thinking there should be a better way other than what is coded? Eventually, I may hit a menu that has six items that I don't want to pull those items from, in other words it should be specific based on the column name that originally triggers this, code that had to be commented out:
// you would think it would work like this but unless the user actuall clicks
// on the column the button column does not calibrate to the column the filter
// button resides in - I'll turn in an error to telerik
/*
string currentColumnName = radGridView.CurrentColumn.Name;
if (currentColumnName == ColumnNameDictionary[BudgetColumnTypes.Annual])
{
int minValue = e.ContextMenu.Items.Count - 5;
for (int x = e.ContextMenu.Items.Count - 1; x > minValue; x--)
e.ContextMenu.Items.RemoveAt(x);
}
*/
Also, while on the subject of the filter row, is there a way to change the forecolor of the labels that appear in front of the textbox that appears on row. The light blue or cadet blue is really faint, hard to see, for a lot of our users and is creating an additional problem.
Thank you.
You can change the context menu of the filter cell by using the following code snippet:
void
radGridView1_ContextMenuOpening(
object
sender, Telerik.WinControls.UI.ContextMenuOpeningEventArgs e)
{
BaseGridBehavior gridBehavior =
this
.radGridView1.GridBehavior
as
BaseGridBehavior;
GridFilterCellElement filterCell = gridBehavior.CellAtPoint
as
GridFilterCellElement;
if
(e.ContextMenuProvider ==
null
&& filterCell !=
null
)
{
if
(filterCell.ColumnInfo.Name ==
"YourColumn"
)
{
// Remove the items from the context menu
}
}
}
If you want to change the color of the text in the GridFilterCellElement, you should use the ViewCellFormatting event:
void
radGridView1_ViewCellFormatting(
object
sender, CellFormattingEventArgs e)
{
GridFilterCellElement filterCell = e.CellElement
as
GridFilterCellElement;
if
(filterCell !=
null
)
{
filterCell.FilterOperatorText.ForeColor = Color.Red;
}
}
Notice that all code snippets above are for Q3 2010 SP1.
Greetings,Svett
the Telerik team
I too just want to change the text of the custom dialog form.
I tried the following code as suggested.
void
radGridView1_CreateCell(
object
sender, GridViewCreateCellEventArgs e)
{
if
(e.CellType ==
typeof
(GridFilterCellElement))
{
e.CellType =
typeof
(MyFilterCell);
}
}
public
class
MyFilterCell : GridFilterCellElement
{
public
MyFilterCell(GridViewDataColumn column, GridRowElement row)
:
base
(column, row)
{
}
protected
override
Type ThemeEffectiveType
{
get
{
return
typeof
(GridFilterCellElement); }
}
protected
override
CompositeFilterForm CreateCompositeFilterForm()
{
CompositeFilterForm form =
base
.CreateCompositeFilterForm();
form.Text =
"My Filter form"
;
return
form;
}
}
However the dialog text still default back to the default text.
See attached png
Am I doing something incorrectly?
I am using the laster version.
I can see the form.text is being changed as per above 9via debug) but the custom text gets overwritten again
Thanks
Andrew
In Q3 2010 SP1 (v2010.3 10.1215) you should create a custom filter form, where you should override the Initialize method:
public
class
CustomCompositeFilterForm : CompositeFilterForm
{
public
override
void
Initialize(GridViewDataColumn dataColumn, FilterDescriptor filterDescriptor,
bool
useTypedEditors)
{
base
.Initialize(dataColumn, filterDescriptor, useTypedEditors);
this
.Text =
"Your text Here"
;
}
}
Svett
the Telerik team
I will let you know if I have any problems.
Regards
Andrew
void
radGridView1_ContextMenuOpening(
object
sender, ContextMenuOpeningEventArgs e)
{
if
(e.ContextMenuProvider ==
null
)
//should be != null
{
e.ContextMenu.Items.RemoveAt(e.ContextMenu.Items.Count - 1);
}
}
In previous versions, the ContextMenuProvider property of the event arguments was null, when the event occurs for GridFilterCellElement.
However, we have changed this behavior and for recent versions of our suite, your suggestion is valid.
Greetings,
Svett
the Telerik team