Remove/disable a column filter for a removed column

8 posts, 0 answers
  1. Johnathan
    Johnathan avatar
    31 posts
    Member since:
    Sep 2012

    Posted 16 Oct 2015 Link to this post

    Hello all,

     I have a page created that allows our users to customize what data columns are available to them and also use a radfilter to apply & save filters for these columns. A common occurrence for our users is they remove a column & forget to remove the filter for that column, so when filter is loaded through the LoadSettings method, an error is produced. Is there a way for me to remove a column filter for the removed column after the LoadSettings is called but before the filter is applied?

  2. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 21 Oct 2015 Link to this post

    Hello Johnathan,

    In order to achieve this you would have to find the filter expression with a FieldName matching that of the column. This can be achieved by using this code snippet:
    for (int i = 0; i < RadFilter1.RootGroup.Expressions.Count; i++)
            {
                string filteredField = (RadFilter1.RootGroup.Expressions[i] as RadFilterNonGroupExpression).FieldName;
                int filterExpressionIndex = i;
            }

    Later you can remove the expression by index:
    //remove the filter expression
            RadFilter1.RootGroup.Expressions.Remove(RadFilter1.RootGroup.Expressions[filterExpressionIndex ]);
            RadFilter1.RecreateControl();

    I hope this helps.

    Regards,
    Maria Ilieva
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Johnathan
    Johnathan avatar
    31 posts
    Member since:
    Sep 2012

    Posted 21 Oct 2015 in reply to Maria Ilieva Link to this post

    Hi Maria,

     I appreciate the reply, but I'm getting an "Object reference not set to an instance of an object" error when I get to the Radfilter's RecreateControl call. Any ideas on what I'm doing wrong?

    Thanks,

     Johnathan

    Try
                                RadFilter1.LoadSettings(oData("FilterValue"))
     
                            Catch ex As Exception
     
                            End Try
     
                            Dim sFilterIndexes As String = ""
     
                            For i As Integer = 0 To RadFilter1.RootGroup.Expressions.Count - 1
                                Dim bExists As Boolean = False
                                Dim sAvailableColumnSplit As String() = sAvailableColumns.Split(";")
     
                                For k As Integer = 0 To sAvailableColumnSplit.Length - 1
                                    If sAvailableColumnSplit(k) = TryCast(RadFilter1.RootGroup.Expressions(i), RadFilterNonGroupExpression).FieldName Then
                                        bExists = True
                                    End If
                                Next
     
                                If Not (bExists) Then
                                    sFilterIndexes = i.ToString & ";"
                                End If
                            Next
     
                            If sFilterIndexes <> "" Then
                                Dim sFilterIndexSplit As String() = sFilterIndexes.Split(";")
     
                                For i As Integer = 0 To sFilterIndexSplit.Length - 1
                                    If sFilterIndexSplit(i) <> "" Then
                                        RadFilter1.RootGroup.Expressions.Remove(RadFilter1.RootGroup.Expressions(i))
                                        RadFilter1.RecreateControl()
                                    End If
                                Next

  5. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 26 Oct 2015 Link to this post

    Hi Johnathan,

    Can you please share your fill page markup as well as related code behind so that i can revise the code locally and advise you further?

    Regards,
    Maria Ilieva
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
  6. Johnathan
    Johnathan avatar
    31 posts
    Member since:
    Sep 2012

    Posted 09 Jun in reply to Maria Ilieva Link to this post

    Hi Maria,

    I apologize for the long reply. Here's the code I use to fill the radgrid:

    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
            Dim oConn As New Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("Conn1").ConnectionString)
            Dim oConn2 As New Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("Conn2").ConnectionString)
            Dim oCmd As New SqlCommand
            Dim oData As New SqlDataAdapter
            Dim iValue As Integer = 0
            Dim bFlagUpdate As Boolean = False
            Try
                If iWebID > 0 Then
                    'AllTasksToggle.SelectedValue = tSelectedAllTaskValue.Text
     
                    oConn.Open()
                    oConn2.Open()
     
                    If CInt(FlagID.Text) > 0 And CInt(TaskID.Text) > 0 Then
                        'the user wants to flag a task
                        With oCmd
                            .Parameters.Clear()
                            .Connection = oConn2
                            .CommandType = CommandType.StoredProcedure
                            .CommandText = "Flag_SP"
                            .Parameters.AddWithValue("@UserID", iWebID)
                            .Parameters.AddWithValue("@FlagID", FlagID.Text)
                            .Parameters.AddWithValue("@TaskID", TaskID.Text)
                            .ExecuteNonQuery()
                        End With
     
                        FlagID.Text = 0
                        TaskID.Text = 0
     
                        bFlagUpdate = True
                    End If
     
                    With oCmd
                        .Parameters.Clear()
                        .Connection = oConn2
                        .CommandType = CommandType.StoredProcedure
                        .CommandText = "Data_Pull_SP"
                        .Parameters.AddWithValue("UserID", iWebID)
                        .Parameters.AddWithValue("TaskTypeID", iTaskTypeID)
                        .Parameters.AddWithValue("AllTasks", IIf(AllTasksToggle.SelectedValue = "", 0, AllTasksToggle.SelectedValue))
                    End With
     
                    oData.SelectCommand = oCmd
     
                    Dim dt As New DataTable
     
                    oData.Fill(dt)
     
                    If dt.Columns.Count = 0 And iWebID > 0 Then
                        Response.Redirect("ManageViewPreferences.aspx?Tab=" & sTaskType, False)
                        Exit Sub
                    Else
                        For Each col As DataColumn In dt.Columns
                            sAvailableColumns &= col.ColumnName & ";"
                        Next
                    End If
     
                    RadGrid1.DataSource = dt
     
                    'Now, load the filter settings if a default filter is available & if not saving/deleting a filter
                    bDelete.Enabled = IIf(rcFilters.SelectedValue = 0, False, True)
                    If rcFilters.SelectedValue <> 0 And rcFilters.SelectedValue <> tPreviousFilter.Text And tDisableSettingsLoad.Text = "False" Then
                        tPreviousFilter.Text = rcFilters.SelectedValue
                        RadFilter1.RootGroup.Expressions.Clear()
                        RadFilter1.RecreateControl()
                        LoadFilterSettings(rcFilters.SelectedValue)
                    ElseIf rcFilters.SelectedValue = 0 And rcFilters.SelectedValue <> tPreviousFilter.Text Then
                        tPreviousFilter.Text = rcFilters.SelectedValue
                        RadFilter1.RootGroup.Expressions.Clear()
                        RadFilter1.RecreateControl()
                        RadFilter1.FireApplyCommand()
                        RadGrid1.Rebind()
                    ElseIf tSelectedAllTaskValue.Text = "" Or tSelectedAllTaskValue.Text <> AllTasksToggle.SelectedValue Then
                        tSelectedAllTaskValue.Text = AllTasksToggle.SelectedValue
                        If rcFilters.SelectedValue = 0 Then
                            RadFilter1.RootGroup.Expressions.Clear()
                            RadFilter1.RecreateControl()
                            RadFilter1.FireApplyCommand()
                            RadGrid1.Rebind()
                        Else
                            tPreviousFilter.Text = rcFilters.SelectedValue
                            RadFilter1.RootGroup.Expressions.Clear()
                            RadFilter1.RecreateControl()
                            LoadFilterSettings(rcFilters.SelectedValue)
                            If bFlagUpdate Then
                                RadGrid1.Rebind()
                            End If
                        End If
                    ElseIf bFlagUpdate Then
                        RadGrid1.Rebind()
                    End If
     
                    'Create filter hyperlink to be display
                    LinkSpan.InnerHtml = "<a href=" & Chr(34) & "CustomView.aspx?FilterID=" & rcFilters.SelectedValue & Chr(34) & " target=" & Chr(34) & "_blank" & Chr(34) & ">Link to selected filter</a>"
                End If
     
                If ExportType.Text <> "" Then
                    Call bExportTasksGrid_Click(sender, e)
                    ExportType.Text = ""
                End If
     
                If Reload.Text = "True" Then
                    Reload.Text = "False"
                    Call SaveFilter(sender, e)
                End If
     
            Catch ex As Exception
            Finally
                oConn.Dispose()
                oConn2.Dispose()
                oConn = Nothing
                oConn2 = Nothing
                oCmd = Nothing
                oData = Nothing
            End Try
        End Sub

  7. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 14 Jun Link to this post

    Hi Johnathan,

    I revise the provided code and noticed that you are using simple DataBinding for the RadGrid control. Note that the required functionality is only supported with advanced DataBinding. See the topic below for more information on that matter:
    http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/data-binding/understanding-data-binding/server-side-binding/advanced-data-binding-(using-needdatasource-event)

    Regards,
    Maria Ilieva
    Telerik
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
  8. Johnathan
    Johnathan avatar
    31 posts
    Member since:
    Sep 2012

    Posted 14 Jun in reply to Maria Ilieva Link to this post

    Hi Maria,

    I have moved the grid data pull to the NeedDataSource event, but I'm still getting an "Object reference not set to an instance of an object" error when I get to the Radfilter's RecreateControl call. Any additional help would be greatly appreciated.

    Thanks,

    Johnathan

  9. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 17 Jun Link to this post

    Hello Johnathan,

    In this case it will be best if you can open a regular support ticket and send us sample runnbale version of your application so that we can debug it locally and advise you further.

    Regards,
    Maria Ilieva
    Telerik
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017