Hello, Joar,
RadGridView offers a flexible public API for custom filtering which allows you to fully control the filtering logic. Additional information is available in the following help article:
https://docs.telerik.com/devtools/winforms/controls/gridview/filtering/custom-filtering
You can also refer to our
Demo application >> GridView >> Filtering >> Custom Filtering example which is quite useful on this topic.
As to the question about adding a custom filter option in the filter menu, you can handle the
ContextMenuOpening event and add a new
RadMenuItem. When the item is clicked, you can add the desired
FilterDescriptor programmatically. A sample code snippet is illustrated below. Note that this is just a sample approach and it may not cover all possible cases. Feel free to modify it in a way which suits your requirement best:
public
RadForm1()
{
InitializeComponent();
this
.radGridView1.Columns.Add(
"Number"
);
this
.radGridView1.Columns.Add(
"TextColumn"
);
this
.radGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;
this
.radGridView1.EnableFiltering =
true
;
this
.radGridView1.ShowHeaderCellButtons =
true
;
this
.radGridView1.Rows.Add(1,
""
);
this
.radGridView1.Rows.Add(2,
" "
);
this
.radGridView1.Rows.Add(3,
null
);
this
.radGridView1.Rows.Add(4,
"test"
);
this
.radGridView1.ContextMenuOpening += radGridView1_ContextMenuOpening;
}
private
void
radGridView1_ContextMenuOpening(
object
sender, Telerik.WinControls.UI.ContextMenuOpeningEventArgs e)
{
GridFilterCellElement filterCell = e.ContextMenuProvider
as
GridFilterCellElement;
if
(filterCell !=
null
&& filterCell.ColumnInfo
is
GridViewTextBoxColumn)
{
RadMenuItem emptyItem =
new
RadMenuItem(
"IsEmpty"
);
emptyItem.Tag = filterCell.ColumnInfo.Name;
emptyItem.Click += emptyItem_Click;
e.ContextMenu.Items.Add(emptyItem);
}
}
private
void
emptyItem_Click(
object
sender, EventArgs e)
{
RadMenuItem item = sender
as
RadMenuItem;
string
propertyName = item.Tag +
""
;
FilterDescriptor fd =
new
FilterDescriptor();
fd.PropertyName = propertyName;
fd.Operator = FilterOperator.IsEqualTo;
fd.IsFilterEditor =
true
;
fd.Value =
""
;
this
.radGridView1.FilterDescriptors.Add(fd);
}
Note that you can also use the
Custom option in the filter menu to build a more complex filter expression.
I hope this information helps. If you need any further assistance please don't hesitate to contact me.
Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Get
quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers.
Learn More.