Custom- and BasicFiltering

7 posts, 0 answers
  1. Holger
    Holger avatar
    2 posts
    Member since:
    Aug 2011

    Posted 01 Aug 2011 Link to this post

    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.
  2. Holger
    Holger avatar
    2 posts
    Member since:
    Aug 2011

    Posted 02 Aug 2011 Link to this post

    Ok, i solved the problem.
  3. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 04 Aug 2011 Link to this post

    Hello Holger,

    I am glad to hear that you have solved your issue.

    Do not hesitate to contact us if you have further questions or issues.

    Greetings,
    Julian Benkov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

  4. Mohamed
    Mohamed avatar
    2 posts
    Member since:
    Nov 2012

    Posted 04 Dec 2012 Link to this post

    please can you told us how you solve this problem , because i have the same
  5. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 07 Dec 2012 Link to this post

    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:
    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
    Q3’12 of RadControls for WinForms is available for download (see what's new). Get it today.
  6. Mohamed
    Mohamed avatar
    2 posts
    Member since:
    Nov 2012

    Posted 07 Dec 2012 Link to this post

    hello
    i use vb and i use the converter to convert it to vb
    and the result as following




    Imports System
    Imports System.Data
    Imports System.Windows.Forms
    Imports Telerik.WinControls.UI
     
    Namespace 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 ObjectByVal 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 NothingOrElse (val = DBNull.Value) OrElse (val.ToString() = ""))
                    ElseIf item.[Operator] = Telerik.WinControls.Data.FilterOperator.IsNotNull Then
                        e.Visible = Not ((val Is NothingOrElse (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.ObjectByVal As System.EventArgs) Handles MyBase.Load
     
            End Sub
        End Class
    End 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




  7. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 12 Dec 2012 Link to this post

    Hi Mohamed,

    I made changes to the converted code snippets. Here is a valid and working VB code snippet:

    Imports System
    Imports System.Data
    Imports System.Windows.Forms
    Imports Telerik.WinControls.UI
    Imports Telerik.WinControls.Data
     
    Namespace 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 Class
    End Namespace

    I hope this helps.

    All the best,
    Julian Benkov
    the Telerik team
    Q3’12 of RadControls for WinForms is available for download (see what's new). Get it today.
Back to Top