Hi!
How can i use custom- and basic filtering combinded ?
There is a customFilterRow example, but it does not contains the basic filter row either.
I have a textBox, and on the textChanged-event i refresh the masterTemplate and the customFiltering-event is fired.
Then i do my filterSearch. Everything works fine, like in the customFiltering-example.
But after that, i want to use the basicGridFilter, but it doesn't work. if i clear the textBox i set the enableCustomFiltering to false,
and then the grid is empty. i only get basic or customFiltering to work, not both.
Thx !
The textBox (customFilter) is used for a search on the whole grid.
The FilterRow should be used to filter each row.
How can i use custom- and basic filtering combinded ?
There is a customFilterRow example, but it does not contains the basic filter row either.
I have a textBox, and on the textChanged-event i refresh the masterTemplate and the customFiltering-event is fired.
Then i do my filterSearch. Everything works fine, like in the customFiltering-example.
But after that, i want to use the basicGridFilter, but it doesn't work. if i clear the textBox i set the enableCustomFiltering to false,
and then the grid is empty. i only get basic or customFiltering to work, not both.
Thx !
The textBox (customFilter) is used for a search on the whole grid.
The FilterRow should be used to filter each row.
6 Answers, 1 is accepted
0
Holger
Top achievements
Rank 1
answered on 02 Aug 2011, 08:31 PM
Ok, i solved the problem.
0
Hello Holger,
Julian Benkov
the Telerik team
I am glad to hear that you have solved your issue.
Do not hesitate to contact us if you have further questions or issues.
Julian Benkov
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>
0
Mohamed
Top achievements
Rank 1
answered on 04 Dec 2012, 08:46 PM
please can you told us how you solve this problem , because i have the same
0
Hello Mohamed,
You can combine custom filtering with default filtering using the Handled property of the CustomFiltering event handler. To use the default filtering you must set the Handled event argument to false. Here is a example for this scenario:
I hope this helps.
Regards,
Julian Benkov
the Telerik team
You can combine custom filtering with default filtering using the Handled property of the CustomFiltering event handler. To use the default filtering you must set the Handled event argument to false. Here is a example for this scenario:
using System;using System.Data;using System.Windows.Forms;using Telerik.WinControls.UI;namespace Lab.Grid{ public partial class GridCustomFilteringForm : Form { private RadGridView gridView = new RadGridView(); public GridCustomFilteringForm() { InitializeComponent(); gridView.Dock = DockStyle.Fill; gridView.Parent = this; gridView.BringToFront(); gridView.EnableFiltering = true; DataTable table = new DataTable(); table.Columns.Add("Id", typeof(int)); table.Columns.Add("Name"); table.Columns.Add("Number", typeof(DateTime)); table.Rows.Add(1, "Ivan", DateTime.Now); table.Rows.Add(2, null, DateTime.Now.AddDays(-1)); table.Rows.Add(null, "Peter", DateTime.Now); table.Rows.Add(4, "George", null); table.Rows.Add(5, "", null); table.Rows.Add(null, "George", null); table.Rows.Add(7, "", DateTime.Now.AddDays(-3)); table.Rows.Add(8, "Enzo", DateTime.Now.AddDays(5)); table.Rows.Add(null, DBNull.Value, null); table.Rows.Add(10, "Enzo", DateTime.Now.AddDays(-1)); gridView.DataSource = table; gridView.EnableFiltering = true; gridView.EnableCustomFiltering = true; gridView.CustomFiltering += new GridViewCustomFilteringEventHandler(gridView_CustomFiltering); } void gridView_CustomFiltering(object sender, GridViewCustomFilteringEventArgs e) { if (gridView.FilterDescriptors.Count == 0) { return; } foreach (var item in gridView.FilterDescriptors) { object val = e.Row.Cells[item.PropertyName].Value; if (item.Operator == Telerik.WinControls.Data.FilterOperator.IsNull) { e.Visible = ((val == null) || (val == DBNull.Value) || (val.ToString() == "")); } else if(item.Operator == Telerik.WinControls.Data.FilterOperator.IsNotNull) { e.Visible = !((val == null) || (val == DBNull.Value) || (val.ToString() == "")); } } if (e.Visible) { e.Handled = false; } } }}I hope this helps.
Regards,
Julian Benkov
the Telerik team
0
Mohamed
Top achievements
Rank 1
answered on 07 Dec 2012, 06:38 PM
hello
i use vb and i use the converter to convert it to vb
and the result as following
but i have 2 error :
1 For Each item As var In gridView.FilterDescriptors
var not defined
2 gridView.CustomFiltering += New GridViewCustomFilteringEventHandler(gridView_CustomFiltering)
this is event and can't call directly
i use vb and i use the converter to convert it to vb
and the result as following
Imports SystemImports System.DataImports System.Windows.FormsImports Telerik.WinControls.UINamespace Lab.Grid Partial Public Class GridCustomFilteringForm Inherits Form Private gridView As New RadGridView() Public Sub New() InitializeComponent() gridView.Dock = DockStyle.Fill gridView.Parent = Me gridView.BringToFront() gridView.EnableFiltering = True Dim table As New DataTable() table.Columns.Add("Id", GetType(Integer)) table.Columns.Add("Name") table.Columns.Add("Number", GetType(DateTime)) table.Rows.Add(1, "Ivan", DateTime.Now) table.Rows.Add(2, Nothing, DateTime.Now.AddDays(-1)) table.Rows.Add(Nothing, "Peter", DateTime.Now) table.Rows.Add(4, "George", Nothing) table.Rows.Add(5, "", Nothing) table.Rows.Add(Nothing, "George", Nothing) table.Rows.Add(7, "", DateTime.Now.AddDays(-3)) table.Rows.Add(8, "Enzo", DateTime.Now.AddDays(5)) table.Rows.Add(Nothing, DBNull.Value, Nothing) table.Rows.Add(10, "Enzo", DateTime.Now.AddDays(-1)) gridView.DataSource = table gridView.EnableFiltering = True gridView.EnableCustomFiltering = True gridView.CustomFiltering += New GridViewCustomFilteringEventHandler(gridView_CustomFiltering) End Sub Private Sub gridView_CustomFiltering(ByVal sender As Object, ByVal e As GridViewCustomFilteringEventArgs) If gridView.FilterDescriptors.Count = 0 Then Return End If For Each item As var In gridView.FilterDescriptors Dim val As Object = e.Row.Cells(item.PropertyName).Value If item.[Operator] = Telerik.WinControls.Data.FilterOperator.IsNull Then e.Visible = ((val Is Nothing) OrElse (val = DBNull.Value) OrElse (val.ToString() = "")) ElseIf item.[Operator] = Telerik.WinControls.Data.FilterOperator.IsNotNull Then e.Visible = Not ((val Is Nothing) OrElse (val = DBNull.Value) OrElse (val.ToString() = "")) End If Next If e.Visible Then e.Handled = False End If End Sub Friend WithEvents RadGridView1 As Telerik.WinControls.UI.RadGridView Private Sub InitializeComponent() Me.RadGridView1 = New Telerik.WinControls.UI.RadGridView() CType(Me.RadGridView1, System.ComponentModel.ISupportInitialize).BeginInit() CType(Me.RadGridView1.MasterTemplate, System.ComponentModel.ISupportInitialize).BeginInit() Me.SuspendLayout() ' 'RadGridView1 ' Me.RadGridView1.Location = New System.Drawing.Point(72, 63) Me.RadGridView1.Name = "RadGridView1" Me.RadGridView1.Size = New System.Drawing.Size(180, 79) Me.RadGridView1.TabIndex = 0 Me.RadGridView1.Text = "RadGridView1" ' 'GridCustomFilteringForm ' Me.ClientSize = New System.Drawing.Size(284, 261) Me.Controls.Add(Me.RadGridView1) Me.Name = "GridCustomFilteringForm" CType(Me.RadGridView1.MasterTemplate, System.ComponentModel.ISupportInitialize).EndInit() CType(Me.RadGridView1, System.ComponentModel.ISupportInitialize).EndInit() Me.ResumeLayout(False) End Sub Private Sub GridCustomFilteringForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub End ClassEnd Namespace'======================================================='Service provided by Telerik (www.telerik.com)'Conversion powered by NRefactory.'Twitter: @telerik, @toddanglin'Facebook: facebook.com/telerik'=======================================================
but i have 2 error :
1 For Each item As var In gridView.FilterDescriptors
var not defined
2 gridView.CustomFiltering += New GridViewCustomFilteringEventHandler(gridView_CustomFiltering)
this is event and can't call directly
0
Hi Mohamed,
I hope this helps.
All the best,
Julian Benkov
the Telerik team
I made changes to the converted code snippets. Here is a valid and working VB code snippet:
Imports SystemImports System.DataImports System.Windows.FormsImports Telerik.WinControls.UIImports Telerik.WinControls.DataNamespace Lab.Grid Partial Public Class GridCustomFilteringForm Inherits Form Private gridView As New RadGridView() Public Sub New() InitializeComponent() gridView.Dock = DockStyle.Fill gridView.Parent = Me gridView.BringToFront() gridView.EnableFiltering = True Dim table As New DataTable() table.Columns.Add("Id", GetType(Integer)) table.Columns.Add("Name") table.Columns.Add("Number", GetType(DateTime)) table.Rows.Add(1, "Ivan", DateTime.Now) table.Rows.Add(2, Nothing, DateTime.Now.AddDays(-1)) table.Rows.Add(Nothing, "Peter", DateTime.Now) table.Rows.Add(4, "George", Nothing) table.Rows.Add(5, "", Nothing) table.Rows.Add(Nothing, "George", Nothing) table.Rows.Add(7, "", DateTime.Now.AddDays(-3)) table.Rows.Add(8, "Enzo", DateTime.Now.AddDays(5)) table.Rows.Add(Nothing, DBNull.Value, Nothing) table.Rows.Add(10, "Enzo", DateTime.Now.AddDays(-1)) gridView.DataSource = table gridView.EnableFiltering = True gridView.EnableCustomFiltering = True End Sub Friend WithEvents RadGridView1 As Telerik.WinControls.UI.RadGridView Private Sub InitializeComponent() Me.RadGridView1 = New Telerik.WinControls.UI.RadGridView() CType(Me.RadGridView1, System.ComponentModel.ISupportInitialize).BeginInit() CType(Me.RadGridView1.MasterTemplate, System.ComponentModel.ISupportInitialize).BeginInit() Me.SuspendLayout() ' 'RadGridView1 ' Me.RadGridView1.Location = New System.Drawing.Point(72, 63) Me.RadGridView1.Name = "RadGridView1" Me.RadGridView1.Size = New System.Drawing.Size(180, 79) Me.RadGridView1.TabIndex = 0 Me.RadGridView1.Text = "RadGridView1" ' 'GridCustomFilteringForm ' Me.ClientSize = New System.Drawing.Size(284, 261) Me.Controls.Add(Me.RadGridView1) Me.Name = "GridCustomFilteringForm" CType(Me.RadGridView1.MasterTemplate, System.ComponentModel.ISupportInitialize).EndInit() CType(Me.RadGridView1, System.ComponentModel.ISupportInitialize).EndInit() Me.ResumeLayout(False) End Sub Private Sub GridCustomFilteringForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Private Sub RadGridView1_CustomFiltering(sender As Object, e As GridViewCustomFilteringEventArgs) Handles RadGridView1.CustomFiltering If gridView.FilterDescriptors.Count = 0 Then Return End If For Each item In gridView.FilterDescriptors Dim val As Object = e.Row.Cells(item.PropertyName).Value If item.[Operator] = Telerik.WinControls.Data.FilterOperator.IsNull Then e.Visible = ((val Is Nothing) OrElse (val = DBNull.Value) OrElse (val.ToString() = "")) ElseIf item.[Operator] = Telerik.WinControls.Data.FilterOperator.IsNotNull Then e.Visible = Not ((val Is Nothing) OrElse (val = DBNull.Value) OrElse (val.ToString() = "")) End If Next If e.Visible Then e.Handled = False End If End Sub End ClassEnd NamespaceI hope this helps.
All the best,
Julian Benkov
the Telerik team