Using RadFilter and a RadGrid's Filter controls simultaneously

2 posts, 0 answers
  1. GP
    GP avatar
    58 posts
    Member since:
    Oct 2009

    Posted 31 Oct 2011 Link to this post

    I have a client who wants to be able to select more than one type of option when filtering against a particular column in a radgrid.  Say they want to see all accounts that are either High or Low Risk Levels.  However, they also want regular radgrid filtering for the other columns in this grid such as accountant name.  

    I created a listbox with a hidden radfilter to accommodate selecting multiple options for the risk level: Select say, "Low" and "High" at the same time.  However, if I want to also filter down to a specific accountant, the radfilter expression is no longer applied.

    Is there a way to use both the radfilter, AND the radgrid's filter controls?  Thanks!  I am attaching my code.  Thank you for your help.

    <script type="text/javascript">
            function onRequestStart(sender, args) {
                if (args.get_eventTarget().indexOf("ExportToExcelButton") >= 0) {
                else {
        <br />
        <br />
        <asp:Table runat="server" ID="table1" Width="873px">
                    <asp:TableHeaderCell ColumnSpan="2">Accounts By Risk Level</asp:TableHeaderCell>
                    <asp:TableCell ColumnSpan="2">
                         To narrow down the report by risk level, select an option in the box below.  To see more than one risk level, press and hold the "Ctrl" key on your keyboard while selecting the levels you wish to view.  To see all levels, click the "View All Risk Levels" button.
                    <asp:TableCell Width="20%">
                         <telerik:RadListBox ID="RadListBox1" runat="server" Skin="WebBlue" Width="100px"
                            SelectionMode="Multiple" AutoPostBack="true">
                             <telerik:RadListBoxItem runat="server" Text="Low" Value="Low" />
                             <telerik:RadListBoxItem runat="server" Text="Medium" Value="Medium" />
                             <telerik:RadListBoxItem runat="server" Text="High" Value="High" />
                             <telerik:RadListBoxItem runat="server" Text="Reimbursement" Value="Reimbursement" />
                             <telerik:RadListBoxItem runat="server" Text="Unassigned" Value="Unassigned" />
                         <br />
                         <telerik:RadButton ID="RadButton1" runat="server" Text="View All Risk Levels" Skin="WebBlue" >
                    <asp:TableCell ColumnSpan="2">
                    <br /><br />
                        <telerik:RadGrid ID="RadGrid1" runat="server" AllowFilteringByColumn="True"
                                       AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False"
                                       GridLines="None" Skin="WebBlue" width="100%"
                                        CellSpacing="0" PageSize="10">
                            <ExportSettings Excel-Format="ExcelML" ExportOnlyData="True" FileName="AccountsByRiskLevel"></ExportSettings>
                            <MasterTableView CommandItemDisplay="Top">
                            <CommandItemSettings ExportToPdfText="Export to PDF" ShowAddNewRecordButton="False" ShowRefreshButton="False" ShowExportToExcelButton="True"></CommandItemSettings>
                            <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column">
                            <HeaderStyle Width="20px"></HeaderStyle>
                            <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column">
                            <HeaderStyle Width="20px"></HeaderStyle>
                                    <telerik:GridBoundColumn DataField="name"
                                        FilterControlAltText="Filter Muni_Name column" HeaderText="Name"
                                    <telerik:GridBoundColumn DataField="Account" FilterControlAltText="Filter Account column"
                                        HeaderText="CID" UniqueName="Account">
                                    <telerik:GridBoundColumn DataField="Accountant"
                                        FilterControlAltText="Filter Accountant column"
                                        HeaderText="FEAD Accountant" UniqueName="Accountant">
                                   <telerik:GridDateTimeColumn DataField="end_date"
                                        FilterControlAltText="Filter end_date column" HeaderText="End Date"
                                        UniqueName="end_date" DataFormatString="{0:d}" PickerType="DatePicker" FilterControlWidth="125px">
                                        <HeaderStyle Width="160px" />
                                        <ItemStyle Width="160px" />
                                    <telerik:GridBoundColumn DataField="risk_level"
                                        FilterControlAltText="Filter risk column" HeaderText="Risk Level"
                            <EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn>
                            <FilterMenu EnableImageSprites="False"></FilterMenu>
                            <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_WebBlue"></HeaderContextMenu>
                        <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Skin="WebBlue" width="873px">
            <br />
        <asp:Panel ID="Panel1" runat="server" Visible = "false">
                <telerik:RadFilter ID="RadFilter1" runat="server" FilterContainerID="RadGrid1" Enabled="false" ShowApplyButton="false">
        <br />
        <telerik:RadAjaxManager runat="server">
        <ClientEvents OnRequestStart="onRequestStart" />
                <telerik:AjaxSetting AjaxControlID="RadListBox1">
                        <telerik:AjaxUpdatedControl ControlID="RadListBox1" />
                        <telerik:AjaxUpdatedControl ControlID="RadListFilter1" />
                        <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1"/>
                <telerik:AjaxSetting AjaxControlID="RadButton1">
                        <telerik:AjaxUpdatedControl ControlID="RadButton1" />
                        <telerik:AjaxUpdatedControl ControlID="RadListBox1" />
                        <telerik:AjaxUpdatedControl ControlID="RadListFilter1" />
                        <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1"/>
                <telerik:AjaxSetting AjaxControlID="RadGrid1">
                        <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1"/>

    Private Sub RadGrid1_NeedDataSource(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource
            connSql.ConnectionString = sqlConn.ToString()
            Dim poSqlCom As New SqlCommand("dbo.AccountRiskLevel", connSql)
            poSqlCom.CommandType = CommandType.StoredProcedure
            Dim adapter As New SqlDataAdapter(poSqlCom)
            Catch ex As Exception
                'lblResult.Text = ex.Message
                If connSql.State = ConnectionState.Open Then
                End If
            End Try
            RadGrid1.DataSource = dtRisk
        End Sub
        Protected Sub RadGrid1_ItemDataBound(sender As Object, e As GridItemEventArgs) Handles RadGrid1.ItemDataBound
            If TypeOf e.Item Is GridFilteringItem Then
                Dim filteringItem As GridFilteringItem = TryCast(e.Item, GridFilteringItem)
                filteringItem.Cells(8).Controls(0).Visible = False
                filteringItem.Cells(8).Controls(1).Visible = False
            End If
        End Sub
    Private Sub RadListBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadListBox1.SelectedIndexChanged
            RadFilter1.RootGroup.GroupOperation = RadFilterGroupOperation.Or
            Dim count As Integer = 0
            For Each item In RadListBox1.SelectedItems
                If count = 0 Then
                    Dim expr1 As New RadFilterEqualToFilterExpression(Of String)("risk_level")
                    expr1.Value = item.Value
                ElseIf count = 1 Then
                    Dim expr2 As New RadFilterEqualToFilterExpression(Of String)("risk_level")
                    expr2.Value = item.Value
                ElseIf count = 2 Then
                    Dim expr3 As New RadFilterEqualToFilterExpression(Of String)("risk_level")
                    expr3.Value = item.Value
                ElseIf count = 3 Then
                    Dim expr4 As New RadFilterEqualToFilterExpression(Of String)("risk_level")
                    expr4.Value = item.Value
                ElseIf count = 4 Then
                    Dim expr5 As New RadFilterEqualToFilterExpression(Of String)("risk_level")
                    expr5.Value = item.Value
                End If
                count = count + 1
        End Sub
        Private Sub RadButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadButton1.Click
        End Sub
    #End Region
  2. Marin
    Marin avatar
    1057 posts

    Posted 02 Nov 2011 Link to this post


    Combining filters from  different sources is not automatically supported by the grid. In order to achieve this you will have to manually combine the expressions coming from the filtering in the grid and the RadFilter then you will have to construct one common filter expressions and set it to the grid. You can refer to the following links for more information on how to operate manually with the different filter expressions:

    Operating with the FilterExpression of Telerik RadGrid Manually
    Working with Expressions in RadFilter

    Best wishes,
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Back to Top