prevent FilterDescriptor from instantly filterin after adding it to the grid

3 posts, 1 answers
  1. Danilo
    Danilo avatar
    47 posts
    Member since:
    Sep 2012

    Posted 14 Feb 2019 Link to this post

    Hi there,

    I'm using a RadGridView with a DateTime column. The property for this column is a nullable DateTime property. I read on a few forum posts that I need to add a FilterDescriptor for the nullable DateTime columns manually. So I added the descriptors the following way:

    FilterDescriptor desc = new FilterDescriptor();
    desc.Operator = FilterOperator.IsEqualTo;
    desc.Value = null;
    desc.IsFilterEditor = true;
    col.FilteringMode = GridViewTimeFilteringMode.Date;
    gv.Columns["WishDate"].FilterDescriptor = desc;

    When the data binding is complete, it instantly filters for null value in this column. But I don't want to filter right away. When I don't add the FilterDescriptor, the default FilterOperator for this column is "None".
    What I need on startup is this nullable DateTime column with "Equal To" filter and not already filtered data.

    I hope you know what I mean :)

    Regards,
    Danilo

     

  2. Answer
    Dimitar
    Admin
    Dimitar avatar
    2839 posts

    Posted 18 Feb 2019 Link to this post

    Hello Danilo,

    The solution for this will be to create a custom cell and set the operator without applying the filter. Here is the code:
    class MyGridFilterCell : GridFilterCellElement
    {
        public MyGridFilterCell(GridViewDataColumn column, GridRowElement row) : base(column, row)
        {
        }
     
        bool flag = true;
        protected override void UpdateInfoCore()
        {
            base.UpdateInfoCore();
     
            if (flag)
            {
                this.SetFilterOperator(FilterOperator.IsEqualTo);
                flag = false;
            }
        }
    }

    To use the above class you need to handle the CreateCell event:
    private void RadGridView1_CreateCell(object sender, GridViewCreateCellEventArgs e)
    {
        if (e.CellType == typeof(GridFilterCellElement))
        {
            e.CellElement = new MyGridFilterCell(e.Column as GridViewDataColumn, e.Row);
        }
     
    }

    I hope this will be useful. Let me know if you have additional questions.

    Regards,
    Dimitar
    Progress Telerik
    Get quickly onboard and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. Danilo
    Danilo avatar
    47 posts
    Member since:
    Sep 2012

    Posted 19 Feb 2019 in reply to Dimitar Link to this post

    Hello Dimitar,

    Thanks for the response. The solution you provided works great. Thank you very much :)

    Regards,
    Danilo
Back to Top