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

[Solved] Color filterItem doesn't work when one column is filtered with IsEmpty

1 Answer 83 Views
Grid
This is a migrated thread and some comments may be shown as answers.
guillaume.lebel
Top achievements
Rank 1
Iron
Iron
guillaume.lebel asked on 19 May 2011, 02:20 PM

Hi,

We are trying to change the color of the filterItem when there is a filter in the grid(dynamicaly created).  It all seems to work fine but when one of the grid columns is filtered with the "Is Empty" function the color does not apply.  The code works fine and if a column is using a filterTemplate this column has the color applied correctly but the color is ignored by the other columns.

Here is the code that we use to make the filterItem change color when filter is applied :

using System;
using System.Collections;
using System.IO;
using System.Web.UI;
using CommonTools;
using Telerik.Web.UI;
namespace CCO.Fortress.MainWebApplication.Library.Helpers
{
     private void OnPageLoadComplete(object sender, EventArgs e)
        {
            FortressGrid.MasterTableView.AllowMultiColumnSorting = true;
            GridItem[] gridFilteringItems = FortressGrid.MasterTableView.GetItems(GridItemType.FilteringItem);
            if (gridFilteringItems.Length > 0)
            {      
                GridFilteringItem filteringItem = (GridFilteringItem)gridFilteringItems[0];
                foreach (GridColumn column in FortressGrid.MasterTableView.Columns)
                {
                    if (column.CurrentFilterValue != string.Empty)
                    {
                        Control control = filteringItem[column.UniqueName].Controls[0];
                        if(control is WebControl)
                        {
                            ((WebControl)control).BackColor = Color.PaleTurquoise;
                        }
                    }
                }
            }
        }
}

Thx for your help,
Guillaume

1 Answer, 1 is accepted

Sort by
0
Pavel
Telerik team
answered on 24 May 2011, 12:29 PM
Hello Guillaume,

The problem is that you are checking the value of the filter control and if it is not empty string, you apply the color. However when you select the IsEmpty option, you do not need to type anything in the textbox, thus you do not recognize a filtering has been applied. In order to make it work try changing your code as follows:
foreach (GridColumn column in FortressGrid.MasterTableView.Columns)
{
    if (column.CurrentFilterFunction != GridKnownFunction.NoFilter)
    {
        Control control = filteringItem[column.UniqueName].Controls[0];
        if (control is WebControl)
        {
            ((WebControl)control).BackColor = Color.PaleTurquoise;
        }
    }
}

I hope this helps.

Best wishes,
Pavel
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Grid
Asked by
guillaume.lebel
Top achievements
Rank 1
Iron
Iron
Answers by
Pavel
Telerik team
Share this question
or