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

Filtertemplate radcombox selectedindexchange doesnot rebind the grid on firecommand

1 Answer 80 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Swati
Top achievements
Rank 1
Swati asked on 07 May 2013, 07:03 AM

  Below is the code snippet used in a radgrid usercontrol

Protected Sub FilterCombo_SelectedIndexChanged(ByVal o As Object, ByVal e As RadComboBoxSelectedIndexChangedEventArgs)
                Dim filterItem As GridFilteringItem = CType(CType(o, RadComboBox).NamingContainer, GridFilteringItem)
                If e.Value = "NoFilter" Then
                    filterItem.FireCommandEvent("Filter", New Pair("NoFilter", Me.colname))
                Else
                    filterItem.FireCommandEvent("Filter", New Pair("EqualTo", Me.colname))
                End If

   End Sub


 

 

Protected Sub RadGridList_ItemCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGridList.ItemCommand

 

If

 

 

(e.CommandName = RadGrid.FilterCommandName) Then

 

 

 

If (TypeOf e.CommandArgument Is Pair) Then

 

 

 

Dim objpair As Pair = DirectCast(e.CommandArgument, Pair)

 

RadGridList.MasterTableView.FilterExpression = "([" & objpair.First.ToString & "] = '" & objpair.Second.ToString & "') "
RadGridList.MasterTableView.Rebind()

 

 

 

End If

 

 

 

Private Sub RadGridList_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadGridList.PreRender

 

 

 

Dim filterExpr As String

 

RadGridList.Skin = skinType

filterExpr =

 

"([" & FilterExpression.ToUpper & "] = '" & FilterValue.ToUpper & "') "

 

 

 

If (Not String.IsNullOrEmpty(filterVal) And (Not Page.IsPostBack)) Then

 

RadGridList.MasterTableView.FilterExpression = filterExpr

 

RadGridList.MasterTableView.Rebind()

filterExpr =

 

""

 

 

 

Else

 

 

 

If Not String.IsNullOrEmpty(RadGridList.MasterTableView.FilterExpression.ToString) Then

 

RadGridList.MasterTableView.FilterExpression = RadGridList.MasterTableView.FilterExpression

 

 

End If

 

RadGridList.MasterTableView.Rebind()

 

 

End If

 


We are dynamically creating all columns and filters in code behind in a common radgrid usercontrol. The RadComboBox is in a inner private Class implementing ITemplate for Filter Template. The columns and the filter applied are driven through configuration e.g. through configuration we can decide to use Combo Filter for Column X and not for Column Y but can change this in future.

We are firing event in  radcombox selectedindexchange which we able to capture in the itemCommand function in the user control but when rebind the grid with the filter expression the results are not filtered.

Additionally we would like to know,
a) if pair generated in the selectedindexchange method to fire command event should column name and column value  or Condition e.g. "EqualTo" and column name should be stored in the Pair object, because in debugging the typical filterexpression we saw was with  condition name and column name.

b) And how to ensure all other column filter are preserved in the filter expression in this scenario where we are seeing some Pair are with Filter Condition & Column Name and some are with Column Name & Column Value

c) multiple filter expresson is also not retaining the values and filter the results when we have multiple type of filters across the column e.g. one is based on date, one is based on radcombo, others are based text entered in textbox

Need your help to resolve this at the earliest

1 Answer, 1 is accepted

Sort by
0
Angel Petrov
Telerik team
answered on 10 May 2013, 10:49 AM
Hello Swati,

I am experiencing difficulties understanding the scenario but if I am correct you have a RadCombBox placed in the FilterTemplate of a column and you want to filter different columns when the index of the selected item in the combo is changed. Now when following this scenario and using FireCommandEvent you should be able to filter the grid properly. The problem however is how the filter expression is build. In order to make things work correctly you should modify the logic like demonstrated below:
Protected Sub RadGridList_ItemCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.ItemCommand
        If (e.CommandName = RadGrid.FilterCommandName) Then
            If (TypeOf e.CommandArgument Is Pair) Then
                Dim objpair As Pair = DirectCast(e.CommandArgument, Pair)
                RadGrid1.MasterTableView.FilterExpression = "([" & objpair.Second.ToString() & "] = '" & YourFilterValue & "') "
                RadGrid1.MasterTableView.Rebind()
            End If
        End If
    End Sub

Where you should replace YourFilterValue with the according value which will be used for filtering.

As for the other problems which you refer in the post.

a) You should store the FilterFunction(e.g StartsWith, Equals) and column name in the Pair object when firing the filter command.

b) Since in this scenario you are assigning a filter expression which will override the previous one. I suggest that you use the current filter expression and rebuild it so that the changes caused by the changed combo index can be applied without overriding the previous filters(please review this help article which explains hot to build filter expressions manually).

c) By following the approach suggested in the previous answer you should be able to resolve this problem also.

All the best,
Angel Petrov
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.
Tags
Grid
Asked by
Swati
Top achievements
Rank 1
Answers by
Angel Petrov
Telerik team
Share this question
or