This is a migrated thread and some comments may be shown as answers.

prevent FilterDescriptor from instantly filterin after adding it to the grid

2 Answers 44 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Danilo
Top achievements
Rank 1
Danilo asked on 14 Feb 2019, 04:16 PM

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 Answers, 1 is accepted

Sort by
0
Accepted
Dimitar
Telerik team
answered on 18 Feb 2019, 02:03 PM
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.
0
Danilo
Top achievements
Rank 1
answered on 19 Feb 2019, 08:37 AM
Hello Dimitar,

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

Regards,
Danilo
Tags
GridView
Asked by
Danilo
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Danilo
Top achievements
Rank 1
Share this question
or