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
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.
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.
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.
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.
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
M.R.