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

Is there a way to persist the initial CurrentFilterFunction?

6 Answers 130 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jerry T.
Top achievements
Rank 1
Jerry T. asked on 27 Sep 2010, 08:27 PM
In our web app, we are setting CurrentFilterFunction values for each column that will be able to be filtered.

However, once one column has some criteria entered in and the user presses <Enter>, that column's filter is properly applied but every remaining column now has a CurrentFilterFunction of "NoFilter"...even after the original criteria is blanked out, essentially setting the grid back to its original state.

Is this something that can be done via the markup/client-side only or are we going to have to set CurrentFilterFunction for each column after every postback?

Or, is there some other method for setting filtering options that persist after postbacks for a page?  In our case, we want only one filtering option to be available for each column and no filter icon to be shown.

Thanks.

Jerry

6 Answers, 1 is accepted

Sort by
0
Marin
Telerik team
answered on 30 Sep 2010, 03:59 PM
Hi Jerry T.,

You can set the filter for each column in the following way (you do not need additional code in the code-behind):

<telerik:GridBoundColumn DataField="ShipName" HeaderText="ShipName" 
UniqueName="ShipName" AutoPostBackOnFilter="true" 
CurrentFilterFunction="whatever function you choose" ShowFilterIcon="false">
</telerik:GridBoundColumn>

The key things here are that you need to set the AutopostBackOnFilter=true; and ShowFilterIcon="false" for the enter key to work and the filter icon not to be shown.
Normally the filter persists its settings across postbacks as shown in this demo.
Hope this helps.

Best wishes,
Marin
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
Jerry T.
Top achievements
Rank 1
answered on 30 Sep 2010, 04:06 PM
Hello, Marin.

That's actually exactly how I'm doing it.  Here is some sample code:

<telerik:RadGrid ID="radgrdPrograms" runat="server" Width="100%" DataSourceID="odsHotelPrograms" EnableLinqExpressions="false"
    EnableEmbeddedSkins="false" Skin="DMCpro" ShowStatusBar="true"
    AutoGenerateColumns="false" AllowFilteringByColumn="true" AllowPaging="true" AllowSorting="true" PageSize="20" >
    <ClientSettings EnableRowHoverStyle="true" Selecting-AllowRowSelect="true" Scrolling-AllowScroll="true" Scrolling-ScrollHeight="550px" Scrolling-UseStaticHeaders="true" />
    <GroupingSettings CaseSensitive="false" />
    <MasterTableView TableLayout="Fixed" DataKeyNames="ProgramNumber,ProgramName,Status">
        <ItemStyle Font-Size="Small" Wrap="false" />
        <AlternatingItemStyle Font-Size="Small" Wrap="false" />
        <Columns>
            <telerik:GridHyperLinkColumn HeaderText="Program #" DataTextField="ProgramNumber" SortExpression="ProgramNumber" UniqueName="ProgramNumber" 
                HeaderStyle-CssClass="radGridViewHeader" HeaderStyle-Width="80px" HeaderStyle-HorizontalAlign="Left"
                AllowFiltering="false" />
            <telerik:GridBoundColumn HeaderText="Program" DataField="ProgramName" SortExpression="ProgramName"
                HeaderStyle-CssClass="radGridViewHeader" HeaderStyle-Width="150px" HeaderStyle-HorizontalAlign="Left" FilterControlWidth="100%"
                CurrentFilterFunction="Contains" AutoPostBackOnFilter="true" ShowFilterIcon="false" />
            <telerik:GridBoundColumn HeaderText="Primary Contact" DataField="PrimaryContact" SortExpression="PrimaryContact" 
                HeaderStyle-CssClass="radGridViewHeader" HeaderStyle-Width="130px" HeaderStyle-HorizontalAlign="Left"
                AllowFiltering="false" />
            <telerik:GridBoundColumn HeaderText="Start Date" DataField="StartDate" SortExpression="StartDate"  
                HeaderStyle-CssClass="radGridViewHeader" HeaderStyle-Width="75px" HeaderStyle-HorizontalAlign="Left" DataFormatString="{0:MM/dd/yyyy}" DataType="System.String"
                CurrentFilterFunction="GreaterThanOrEqualTo" AutoPostBackOnFilter="true" ShowFilterIcon="false" FilterControlWidth="65px" />
            <telerik:GridBoundColumn HeaderText="End Date" DataField="EndDate" SortExpression="EndDate"
                HeaderStyle-CssClass="radGridViewHeader" HeaderStyle-Width="75px" HeaderStyle-HorizontalAlign="Left" DataFormatString="{0:MM/dd/yyyy}" DataType="System.String" 
                CurrentFilterFunction="LessThanOrEqualTo" AutoPostBackOnFilter="true" ShowFilterIcon="false" FilterControlWidth="65px" />
            <telerik:GridBoundColumn HeaderText="Status" DataField="Status" SortExpression="Status"
                HeaderStyle-CssClass="radGridViewHeader" HeaderStyle-Width="40px" HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Center" 
                CurrentFilterFunction="EqualTo" AutoPostBackOnFilter="true" ShowFilterIcon="false" />
            <telerik:GridBoundColumn HeaderText="Prob" DataField="ProbToClose" SortExpression="ProbToClose" DataFormatString="{0:0%}" 
                HeaderStyle-CssClass="radGridViewHeader" HeaderStyle-Width="40px" HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Right" 
                CurrentFilterFunction="EqualTo" AutoPostBackOnFilter="true" ShowFilterIcon="false" />
            <telerik:GridBoundColumn HeaderText="Revenue" DataField="TotalRev" SortExpression="TotalRev" DataFormatString="{0:c}" 
                HeaderStyle-CssClass="radGridViewHeader" HeaderStyle-Width="110px" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Right"
                CurrentFilterFunction="GreaterThanOrEqualTo" AutoPostBackOnFilter="true" ShowFilterIcon="false" FilterControlWidth="90px" />
            <telerik:GridBoundColumn HeaderText="Pax" DataField="NumberOfGuest" SortExpression="NumberOfGuest"
                HeaderStyle-CssClass="radGridViewHeader" HeaderStyle-Width="45px" HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Right" 
                AllowFiltering="false" />
            <telerik:GridHyperLinkColumn HeaderText="AE" DataTextField="AEName" SortExpression="AEName"
                HeaderStyle-CssClass="radGridViewHeader" HeaderStyle-Width="35px" 
                CurrentFilterFunction="EqualTo" AutoPostBackOnFilter="true" ShowFilterIcon="false" FilterControlWidth="35px" />
            <telerik:GridBoundColumn HeaderText="Hotel" DataField="Hotel" SortExpression="Hotel" 
                HeaderStyle-CssClass="radGridViewHeader" HeaderStyle-Width="150px" HeaderStyle-HorizontalAlign="Left" 
                CurrentFilterFunction="Contains" AutoPostBackOnFilter="true" ShowFilterIcon="false" FilterControlWidth="125px" />
            <telerik:GridBoundColumn HeaderText="Client" DataField="ClientName" SortExpression="ClientName" 
                HeaderStyle-CssClass="radGridViewHeader" HeaderStyle-Width="150px" HeaderStyle-HorizontalAlign="Left"
                AllowFiltering="false" />
            <telerik:GridBoundColumn HeaderText="Parent" DataField="ParentName" SortExpression="ParentName" 
                HeaderStyle-CssClass="radGridViewHeader" HeaderStyle-Width="175px" HeaderStyle-HorizontalAlign="Left"
                AllowFiltering="false" />
        </Columns>
    </MasterTableView>
</telerik:RadGrid>


And the code-behind:

Private Sub radgrdPrograms_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles radgrdPrograms.ItemDataBound
    If (TypeOf e.Item Is GridDataItem) Then
        Dim gdi As GridDataItem = DirectCast(e.Item, GridDataItem)
        Dim hlc As HyperLink = DirectCast(gdi.Item("ProgramNumber").Controls(0), HyperLink)
        hlc.NavigateUrl = "~/Programs/Programs.aspx?PNO=" + radgrdPrograms.MasterTableView.DataKeyValues(e.Item.ItemIndex)("ProgramNumber").ToString + "&PName=" + Replace(Server.UrlEncode(radgrdPrograms.MasterTableView.DataKeyValues(e.Item.ItemIndex)("ProgramName")), "'", "")
        hlc.CssClass = "info"
        If (gdi.GetDataKeyValue("Status") = "C") Or (gdi.GetDataKeyValue("Status") = "CD") Then
            gdi.Cells(7).Attributes.Add("Style", "background-image: url('../Images/BackHighlightRed.png');background-repeat:no-repeat;background-position:center;")
            gdi.Cells(7).Font.Bold = True
        ElseIf (gdi.GetDataKeyValue("Status") = "SC") Or (gdi.GetDataKeyValue("Status") = "SI") Or (gdi.GetDataKeyValue("Status") = "SO") Then
            gdi.Cells(7).Attributes.Add("Style", "background-image: url('../Images/BackHighlightGray.png');background-repeat:no-repeat;background-position:center;")
            gdi.Cells(7).Font.Bold = True
        ElseIf (gdi.GetDataKeyValue("Status") = "P") Then
            gdi.Cells(7).Attributes.Add("Style", "background-image: url('../Images/BackHighlightGreen.png');background-repeat:no-repeat;background-position:center;")
            gdi.Cells(7).Font.Bold = True
        End If
    ElseIf (TypeOf e.Item Is GridFilteringItem) Then
        Dim fi As GridFilteringItem = DirectCast(e.Item, GridFilteringItem)
        For i = 0 To radgrdPrograms.Columns.Count - 1
            fi.Cells(i + 2).ToolTip = radgrdPrograms.Columns(i).CurrentFilterFunction.ToString
        Next
    End If
End Sub


This works fine until the first column is filtered.  After that, all non-filtered columns have a tooltip set to NoFilter and typing anything in and pressing <Enter> results in no action.  The CurrentFilterFunction is not being persisted on each column.
0
Marin
Telerik team
answered on 01 Oct 2010, 01:09 PM
Hi Jerry T.,

Thanks very much for the code sample.
You can try setting the FilterControlToolTip of the GridColumn to the desired text in the markup file instead of doing it in code-behind:

<telerik:GridBoundColumn HeaderText="Program" DataField="ProgramName" 
SortExpression="ProgramName"
HeaderStyle-CssClass="radGridViewHeader" HeaderStyle-Width="150px" 
HeaderStyle-HorizontalAlign="Left" FilterControlWidth="100%"
CurrentFilterFunction="Contains" AutoPostBackOnFilter="true" 
ShowFilterIcon="false" FilterControlToolTip="some text here" />

This way it should be preserved across postbacks.

Hope this helps. Feel free to ask if you have any other questions.


Best wishes,
Marin
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
Jerry T.
Top achievements
Rank 1
answered on 01 Oct 2010, 01:34 PM
Not sure how I missed that attribute but thanks.

However, that still doesn't solve the problem of the filter setting being reset to "NoFilter" for every column that isn't filtered once I do set a filter.

For example, if I enter a Start Date value that filters for that date and later, every other column is now set to "NoFilter" after postback.  Is there not a way to have the initial CurrentFilterFunction value persist for every column (whether criteria is entered or not) after a postback?
0
Marin
Telerik team
answered on 04 Oct 2010, 04:10 PM
Hi Jerry T.,

The default behavor for the grid is not to persist the CurrentFilterFunction on postback for columns that do not have value entered in the filter. You can try manually saving this setting. One approach is to set the CurrentFilterFunction property in the Page_PreRender event for the page, however if you still need to use the setting in the ItemDataBound event, Rebind has to be called for the gird like this:
protected override void OnPreRender(EventArgs e)
{
   base.OnPreRender(e);
   RadGrid1.Columns[0].CurrentFilterFunction = GridKnownFunction.Contains;
   RadGrid1.Columns[1].CurrentFilterFunction = GridKnownFunction.GreaterThan;
   RadGrid1.Columns[2].CurrentFilterFunction =
       GridKnownFunction.LessThanOrEqualTo;
   RadGrid1.Rebind();
}

Thus on the second pass through ItemDataBound the current filter function is set correctly.

Another standart approach for persisting the Grid setting is to use the GridSettingsPersister class and store in it the relevant settings, passing as parameter an instance of the grid as shown in this help topic and live demo. Then later you can load those settings but additional rebinding of the grid is required again for the changes to take effect.
The concrete use depeneds on what you need the CurrentFilterFunction property for. If it is only to display a tooltip the better choice is to use FilterControlToolTip property as mentioned before.

Greetings,

Marin
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
Jerry T.
Top achievements
Rank 1
answered on 04 Oct 2010, 06:14 PM
Hi, Marin.

The hope was to avoid using server-side code as much as possible but it appears we'll have to use it a little bit. I'll take a look at that demo and the help.

Thanks!

Jerry
Tags
Grid
Asked by
Jerry T.
Top achievements
Rank 1
Answers by
Marin
Telerik team
Jerry T.
Top achievements
Rank 1
Share this question
or