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

Filtering problem

5 Answers 42 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jim
Top achievements
Rank 1
Jim asked on 17 May 2012, 02:27 PM
I've inherited a project using a RadGrid which uses session variables as filter arguments.  These arguments are then appended to a StringBuilder variable, which is used as the RowFilter argument for the Dataview.  This Dataview is the datasource for the grid.  This is in an .ascx control which is used on several pages.

The initial filter works fine.  It's when the user changes or removes the filter that I'm experiencing a problem - the grid won't display the updated results and the existing results won't expand if the user clicks on the expand arrow.

I tried to bypass the existing filter and use a RadFilter but when I click on the "add expression" button, nothing happens.  Following is the declarative.
<telerik:RadFilter ID="RadFilter1" runat="server" FilterContainerID="gvMission" >
    <fieldeditors>
        <telerik:RadFilterTextFieldEditor DisplayName="Lane" FieldName="Lane" 
            TextBoxWidth="120" />
    </fieldeditors>
</telerik:RadFilter>
Note: I had to manually add the FilterContainerID; When I expanded the RadFilter Tasks window, "gvMission" wasn't in the dropdown list.  Thanks very much.

5 Answers, 1 is accepted

Sort by
0
Jim
Top achievements
Rank 1
answered on 18 May 2012, 12:25 PM
Anyone?  Would prefer to have a solution for the dataview problem, but at this point, whatever will work.
0
Tsvetina
Telerik team
answered on 22 May 2012, 12:05 PM
Hello Jim,

Can you share your data-binding logic? Are you using NeedDataSource as advised when using features like filtering? Also, if you have AJAX in this scenario, confirm that when running the site with script debugging on you do not receive any javascript errors (that indicate server exceptions).

Kind regards,
Tsvetina
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.
0
Jim
Top achievements
Rank 1
answered on 22 May 2012, 12:43 PM
Here's what they've got for NeedDataSource which, as I step through the code, gets called when a new filter is applied.

Private Sub gvMission_NeedDataSource(ByVal source As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles gvMission.NeedDataSource
    Dim dv As DataView = BuildMissionProcedureDataView(_missionID)
    With gvMission
        .DataSource = dv
    End With
End Sub

Here is the code to initialize the filter:
Private Sub FilterInit()
    If DesignMode Then
        Return
    End If
    If Not Session("MajorMilestone") = Nothing Then
        cbMajorMilestone.Checked = Session("MajorMilestone").ToString
    End If
    If Not Session("Lane") = Nothing Then
        ddlLane.SelectedValue = Session("Lane").ToString
    End If
    If Not Session("Area") = Nothing Then
        ddlArea.SelectedValue = Session("Area").ToString
    End If
    If _statusID = 3 Then
        ddlCategory.Enabled = False
    Else
        If Not Session("Category") = Nothing Then
            ddlCategory.SelectedValue = Session("Category").ToString
        End If
    End If
    If Not Session("StartDate") = Nothing Then
        tbStartDate.Text = Session("StartDate").ToString
    End If
    If Not Session("EndDate") = Nothing Then
        tbEndDate.Text = Session("EndDate").ToString
    End If
    If cbMajorMilestone.Checked = False Then
        Session("MajorMilestone") = Nothing
    ElseIf cbMajorMilestone.Checked = True Then
        Session("MajorMilestone") = cbMajorMilestone.Checked
    End If
End Sub
Private Sub FilterSave()
    If cbMajorMilestone.Checked = False Then
        Session("MajorMilestone") = Nothing
    ElseIf cbMajorMilestone.Checked = True Then
        Session("MajorMilestone") = cbMajorMilestone.Checked
    End If
    If ddlCategory.SelectedIndex = 0 Then
        Session("Category") = Nothing
    Else
        Session("Category") = ddlCategory.SelectedValue
    End If
    If ddlLane.SelectedIndex = 0 Then
        Session("Lane") = Nothing
    Else
        Session("Lane") = ddlLane.SelectedValue
    End If
    If ddlArea.SelectedIndex = 0 Then
        Session("Area") = Nothing
    Else
        Session("Area") = ddlArea.SelectedValue
    End If
    If tbStartDate.Text = String.Empty Then
        Session("StartDate") = Nothing
    Else
        Session("StartDate") = tbStartDate.Text
    End If
    If tbEndDate.Text = String.Empty Then
        Session("EndDate") = Nothing
    Else
        Session("EndDate") = tbEndDate.Text
    End If
End Sub
Private Sub FilterApply()
    Dim filter As New StringBuilder
    Dim filtertext As New StringBuilder("Click to change filter... Showing: ")
    If Not Session("Category") = Nothing And _statusID <> "3" Then
        filter.AppendFormat("ColorRating='{0}'", Session("Category").ToString)
        filtertext.AppendFormat("Only '{0}' items ", ddlCategory.Items.FindByValue(Session("Category").ToString).Text)
    Else
        filtertext.Append("All ")
    End If
    If Not Session("MajorMilestone") = Nothing Then
        If Not filter.Length = 0 And Session("MajorMilestone") = "True" Then
            filter.Append(" AND ")
        End If
        filter.Append("(Critical = True OR MajorMilestone = True)")
        filtertext.AppendFormat("Critical Gates/Major Milestones ")
    Else
        filtertext.Append("items ")
    End If
    If Not Session("Lane") = Nothing Then
        If Not filter.Length = 0 Then
            filter.Append(" AND ")
        End If
        filter.AppendFormat("LaneID={0}", Session("Lane").ToString)
        filtertext.AppendFormat("within the {0} lane ", ddlLane.Items.FindByValue(Session("Lane").ToString))
    Else
        filtertext.Append("within all lanes ")
    End If
    If Not Session("Area") = Nothing Then
        If Not filter.Length = 0 Then
            filter.Append(" AND ")
        End If
        If Session("Area") = 2 Then
            filter.AppendFormat("(AreaID={0} OR AreaID=4)", Session("Area").ToString)
        ElseIf Session("Area") = 3 Then
            filter.AppendFormat("(AreaID={0} OR AreaID=4)", Session("Area").ToString)
        Else
            filter.AppendFormat("AreaID={0}", Session("Area").ToString)
        End If
        filtertext.AppendFormat("within the {0} area ", ddlArea.Items.FindByValue(Session("Area").ToString))
    Else
        filtertext.Append("within all areas ")
    End If
    If Not Session("StartDate") = Nothing Or Not Session("EndDate") = Nothing Then
        If Not filter.Length = 0 Then
            filter.Append(" AND ")
        End If
        If (Not Session("StartDate") = Nothing) And (Not Session("EndDate") = Nothing) Then
            filter.AppendFormat("((DueDate >='{0}' AND DueDate <='{1}'))", Session("StartDate").ToString, Session("EndDate").ToString)
            ' filter.AppendFormat("AND (DueDate <='{0})", Session("MissionDBEndDate").ToString)
            filtertext.AppendFormat("with a due date between {0} and {1}", Session("StartDate").ToString, Session("EndDate").ToString)
        ElseIf Not Session("StartDate") = Nothing Then
            filter.AppendFormat("DueDate >='{0}'", Session("StartDate").ToString)
            filtertext.AppendFormat("with a due date on or after {0} ", Session("StartDate").ToString)
        ElseIf Not Session("EndDate") = Nothing Then
            filter.AppendFormat("DueDate <='{0}'", Session("EndDate").ToString)
            filtertext.AppendFormat("with a due date on or before {0}", Session("EndDate").ToString)
        End If
    End If
     ViewState("filterexpression") = filter.ToString
    cpe.CollapsedText = filtertext.ToString
    gvMission.Rebind()
End Sub

The FilterInit function is called during PageLoad.  The others when the "Apply Filter" button is clicked.

Thanks again!
0
Tsvetina
Telerik team
answered on 28 May 2012, 07:41 AM
Hello Jim,

Where are you calling FilterApply() method? It is possible that you are mixing different syntaxes in the final FilterExpression or that the additional criteria does not get applied or errors out. Have you tried building RadFilterExpressions and adding them to the filter on Page_Load?

Kind regards,
Tsvetina
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.
0
Jim
Top achievements
Rank 1
answered on 30 May 2012, 01:32 PM
Problem was solved - I had to change "gvMission.ReBind()" to "gvMission.MasterTable.Rebind()".
Thank you for responding!
Tags
Grid
Asked by
Jim
Top achievements
Rank 1
Answers by
Jim
Top achievements
Rank 1
Tsvetina
Telerik team
Share this question
or