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

AllowFilteringByColumn property always false for RadGrid during life cycle prior to databinding

3 Answers 170 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bryan
Top achievements
Rank 1
Bryan asked on 01 Sep 2016, 05:09 AM

Seems that in code behind the AllowFilteringByColumn property is always set to false at all phases of life cycle prior to the data binding stages. Code example like below for example is always returning me false.:

 

protected void Page_Load(sender se, EventArgs evt) // Master Page event
{
 
var grid = ControlHelper.FindControlByCIDRecursive<RadGrid>(Request["__EVENTTARGET"], ContentPlaceHolder1); // Iterate content page to find all RadGrid
                if (grid != null)
                {
                    bool rebind = false;
                    if(grid.AllowFilteringByColumn)
                    foreach (GridColumn column in grid.MasterTableView.Columns)
                        if (column.CurrentFilterFunction!=GridKnownFunction.NoFilter) {
                        column.CurrentFilterFunction = GridKnownFunction.NoFilter;
                        column.CurrentFilterValue = string.Empty;
                            rebind = true;
                    }
                    if (rebind)
                    {
                        grid.MasterTableView.FilterExpression = string.Empty;
                        grid.MasterTableView.Rebind();
                    }
                }
}

 

Our requirement is to apply a certain DOM class to all grids site-wise. If AllowFilteringByColumn is not propertly populated before databinding is there another way to determine whether filtering is enabled?

3 Answers, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 02 Sep 2016, 01:43 PM
Hi Bryan,

If you need to execute custom logic based on the AllowFilteringByColumn property you can use the Page_PreRender event. At that stage the property will indicate whether filtering is enabled for RadGrid.

Regards,
Viktor Tachev
Telerik by Progress
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
0
Bryan
Top achievements
Rank 1
answered on 06 Sep 2016, 04:54 AM

Thanks. Thought about this before but my downfall was the properties of the grid and its underlying masterview were different...

If only that of the mastertableview is set to true then it would still return false during PreRender for the grid.

Wonder if there's any specific reason/purpose for this behavior?

0
Viktor Tachev
Telerik team
answered on 07 Sep 2016, 01:40 PM
Hello Bryan,

The behavior you describe is expected. Note that the AllowFilteringByColumn is available for the RadGrid and for each GridTableView. This enables you to have hierarchical RadGrid where only some of the nested tables allow filtering. When you set the AllowFilteringByColumn property for the RadGrid this will be the default value for all GridTableViews that the grid contains.

By default the filtering is disabled and this is why you are seeing false when checking the AllowFilteringByColumn for RadGrid.

In case you are enabling filtering only for the MasterTableView you would need to check the AllowFilteringByColumn property for it.


protected void Page_PreRender(object sender, EventArgs e)
{
    if (RadGrid1.MasterTableView.AllowFilteringByColumn == true)
    {
        //do stuff
    }
}


Regards,
Viktor Tachev
Telerik by Progress
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
Grid
Asked by
Bryan
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Bryan
Top achievements
Rank 1
Share this question
or