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

How to recognize applied IsNull filter on a column

9 Answers 139 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jakub Sterba
Top achievements
Rank 1
Jakub Sterba asked on 02 Sep 2010, 11:06 AM
Greetings,

is it possible to recognize, whether there is filter applied on a column in case of using IsNull or NotIsNull conditions? I did not succeed to apply background color to filter cell, where filter was on. Or is there another way to differentiate filter cell when filter is used for the column?

Thank you very much.

9 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 08 Sep 2010, 10:04 AM
Hello Jakub,

Please try the following approach:
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.FilterCommandName)
    {
        Pair pair = e.CommandArgument as Pair;
        string filterType = pair.First.ToString();
        GridColumn filterCol = RadGrid1.MasterTableView.GetColumn(pair.Second.ToString());
 
        if (filterType.Contains("IsNull"))
            filterCol.HeaderStyle.CssClass = "myCssClass";
        else
            filterCol.HeaderStyle.CssClass = "rgHeader";
    }
}

Let me know whether this helps.

Regards,
Daniel
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Jakub Sterba
Top achievements
Rank 1
answered on 08 Sep 2010, 11:01 AM
Hi,

well, it was a nice try, but there are a few problems. I don't want to change style of header cell, because of style applied, when the column is sorted, but I would like to change style of filter cell, when filtering is applied, because when sorting is applied to the column, the style of the filter cell is not changed. Please, can you navigate me, how to achieve this? I think, there is a problem with prerender event, because it is not fired on the table cell with filter...

Thank you
0
Accepted
Daniel
Telerik team
answered on 10 Sep 2010, 04:32 PM
Hello Jakub,

I believe the most suitable place to implement that will be the ItemCreated event:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
    if (e.Item is GridFilteringItem)
        foreach (GridColumn col in RadGrid1.MasterTableView.RenderColumns)
            if (col.SupportsFiltering() && (col.CurrentFilterFunction == GridKnownFunction.IsNull || col.CurrentFilterFunction == GridKnownFunction.NotIsNull))
                (e.Item as GridFilteringItem)[col.UniqueName].BackColor = System.Drawing.Color.Red;
}

Regards,
Daniel
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Jakub Sterba
Top achievements
Rank 1
answered on 29 Sep 2010, 10:30 AM
Hi,

works like a charm now. First of all, it was one postback behind. Then I found, it was my fault, because I use my own datasourceviews and Rebind() was to be called. Now it's all ok.

Thank you very much.
0
Igor
Top achievements
Rank 1
answered on 31 Jan 2011, 01:58 PM
Hi Daniel, your solution works, but not on all columns. If a column is also sorted, the background is not set red. Ist something missed here?

Thank you,

Igor
0
Daniel
Telerik team
answered on 03 Feb 2011, 01:22 PM
Hello Igor,

It is hard to guess what is wrong in your scenario. Could you please test the attached demo where I tried to reproduce the problem? Let me know if I'm leaving out something.

Kind regards,
Daniel
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.
0
Igor
Top achievements
Rank 1
answered on 03 Feb 2011, 03:04 PM
Hi Daniel,

thank you, with your example I can reproduce my scenario. I want to set the background color below the column header when a filter is active. I have done  a little modification of your code, here:

<script type="text/C#" runat="server">
        protected void Page_Init(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                GridSortingSettings sortingSettings = RadGrid1.SortingSettings;
                sortingSettings.SortedBackColor = System.Drawing.Color.Transparent;
            }
        }
         
        protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridFilteringItem)
            {
                System.Drawing.Color markColor = System.Drawing.Color.BlanchedAlmond;
 
                foreach (GridColumn col in RadGrid1.MasterTableView.RenderColumns)
                {
                    if (col.SupportsFiltering() &&
                        col.CurrentFilterFunction != GridKnownFunction.NoFilter)
                    {
                        (e.Item as GridFilteringItem)[col.UniqueName].BackColor = markColor;
                    }
 
                }
            }
        }
 
    </script>

it seam that 
sortingSettings.SortedBackColor = System.Drawing.Color.Transparent;
make the custom filter background color disappear when the column is sorted. I can remove the transparent color to the  SortedBackColor property, but the sorted grid column background is to strong. Do you know another way to mark the filtered column without changing the transparent sorted background color?

Best regards,
Igor     
 
0
Daniel
Telerik team
answered on 09 Feb 2011, 12:21 PM
Hello Igor,

Of course it is not possible to have two background colors on a single cell. Instead of setting the background color in code-behind, I recommend that you use a css rule:
<style type="text/css">
    .RadGrid table.rgMasterTable td.rgSorted
    {
        background-color: blue;
    }
</style>

Regards,
Daniel
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.
0
Igor
Top achievements
Rank 1
answered on 15 Feb 2011, 01:51 PM
perfect, it works like a charm.
Thank you, Igor
Tags
Grid
Asked by
Jakub Sterba
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Jakub Sterba
Top achievements
Rank 1
Igor
Top achievements
Rank 1
Share this question
or