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

Filtering issue

5 Answers 89 Views
Grid
This is a migrated thread and some comments may be shown as answers.
M. R.
Top achievements
Rank 1
M. R. asked on 24 Jul 2012, 03:49 PM
Hello,

I have a grid with 28 column filters. My question is: once a filter is applied, is there a way for the user to know that a particular filter is active? As there is no change in the filter icon or color (or column background), then how can the user know there is filtering in the grid and on which column(s)?
Is there any grid built-in property that allows to achieve this functionality?

Regards,
M.R.

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 25 Jul 2012, 04:50 AM
Hi,

Please try the following code snippet to give the background color for filtered column.

C#:
protected void gridAgenda_ItemCommand(object sender, GridCommandEventArgs e)
{
   if (e.CommandName == RadGrid.FilterCommandName)
   {
      Pair pair = e.CommandArgument as Pair;
      GridColumn filterCol = gridAgenda.MasterTableView.GetColumn(pair.Second.ToString());
      filterCol.ItemStyle.CssClass = "myClass";
   }
}

CSS:
.myClass
{
    background-color:#829CBF !important;
}

Thanks,
Shinu.
0
M. R.
Top achievements
Rank 1
answered on 25 Jul 2012, 03:09 PM
Thank you Shinu for posting this code, works correctly on filtered columns.
However, I noticed that once you clear the filter, the background color for the (previously) filtered column remains the same... It should revert to the original color though.
Also, if I click on the filter button and choose "NoFilter" for a specific column, the code will also trigger and change the column background.

Regards,
M.R.
0
Accepted
Shinu
Top achievements
Rank 2
answered on 26 Jul 2012, 04:25 AM
Hi,

Please try the following code snippet to avoid background color when the filter option is "NoFilter".

C#:
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 = gridAgenda.MasterTableView.GetColumn(pair.Second.ToString());
        if (filterType != "NoFilter")
        {
            filterCol.ItemStyle.CssClass = "myClass";
        }
        else
        {
            filterCol.ItemStyle.CssClass = "noFilter";
        }
    }
}

CSS:
.myClass
{
    background-color:#829CBF !important;
}
.noFilter
{
    background-color:transparent !important;
}

Thanks,
Shinu.
0
M. R.
Top achievements
Rank 1
answered on 26 Jul 2012, 02:11 PM
Thank you very much for your help Shinu, again. It works much better, there are no problems filtering columns that have an associated filter button.
But...I have one column (the very first one, please see attached screenshot) that does not have a button. The user just types the filtering string (a number) in this column. This is the way I defined the column:

<telerik:GridBoundColumn DataField="SBSACT" FilterControlAltText="Filter SBSACT column"
            HeaderText="SBSACT" SortExpression="SBSACT" UniqueName="SBSACT" AutoPostBackOnFilter="true"
            CurrentFilterFunction="Contains" ShowFilterIcon="false">

As you can see, the default filter function is set to "Contains" (but it can be any other function, like "EqualTo") and the button is hidden.
This is the scenario that does not work:

1. Type a string in the filter text box
2. Press <ENTER>
3. The column is filtered and the background changes. This is correct.
4. Now delete the whole search string using backspace.
5. Press <ENTER>
6. The filter is cleared by the grid but the column background is not... Your code triggers but [filterType] variable is for some reason "Contains" even through the filter value is empty string...

Regards,
M.R.
0
M. R.
Top achievements
Rank 1
answered on 26 Jul 2012, 06:21 PM
Ok, I figured out, what about this:

 Private Sub RadGrid1_ItemCommand(sender As Object, e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.ItemCommand
    If e.CommandName = RadGrid.FilterCommandName Then
      Dim Pair As Pair = e.CommandArgument
      Dim filterCol As GridColumn = RadGrid1.MasterTableView.GetColumn(Pair.Second.ToString())
      Dim filterType As String = Pair.First.ToString

      If Trim(filterCol.CurrentFilterValue) = vbNullString Then
        filterCol.ItemStyle.CssClass = "noFilter"
      Else
        If filterType = "NoFilter" Then
          filterCol.ItemStyle.CssClass = "noFilter"
        Else
          filterCol.ItemStyle.CssClass = "filterClass"
        End If
      End If
    
      Pair = Nothing
      filterCol = Nothing
    End If
  End Sub


Regards,
M.R.
Tags
Grid
Asked by
M. R.
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
M. R.
Top achievements
Rank 1
Share this question
or