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

dynamic multiple column filter

2 Answers 55 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Christian
Top achievements
Rank 1
Christian asked on 04 Jul 2012, 04:35 PM
Hi,

in the following test project I'm trying to set 2 filters one after the other. But as soon as one is set the other doesnt apply anymore!
Is there a way to have them both apply?

Thanks in advance.
Christian

Public Class MyCustomBoundColumn
    Inherits GridBoundColumn
 
    Public dsDataSource As DataTable
 
    Public Function GetDataTable(ByVal strColumnName As String) As DataTable
        Dim disctinctValues As DataTable = Nothing
        If TypeOf (dsDataSource) Is DataTable Then
            Dim View As New DataView(dsDataSource)
            disctinctValues = View.ToTable(True, strColumnName)
        End If
 
        Return disctinctValues
    End Function
 
    Protected Overrides Sub SetupFilterControls(ByVal cell As TableCell)
        Dim rcBox As New RadComboBox()
        rcBox.ID = "cboFilter" & Me.DataField
        rcBox.DataTextField = Me.DataField
        rcBox.DataValueField = Me.DataField
        rcBox.AutoPostBack = False
        AddHandler rcBox.SelectedIndexChanged, AddressOf rcBox_SelectedIndexChanged
        Dim table As DataTable = GetDataTable(Me.DataField)
        Dim row As DataRow = table.NewRow()
        row(Me.DataField) = ""
        table.Rows.InsertAt(row, 0)
        rcBox.DataSource = table
        cell.Controls.Add(rcBox)
    End Sub
 
    Protected Overrides Sub SetCurrentFilterValueToControl(ByVal cell As TableCell)
        If Not (Me.CurrentFilterValue = "") Then
            DirectCast(cell.Controls(0), RadComboBox).Items.FindItemByText(Me.CurrentFilterValue).Selected = True
        End If
    End Sub
 
    Protected Overrides Function GetCurrentFilterValueFromControl(ByVal cell As TableCell) As String
        Dim currentValue As String = DirectCast(cell.Controls(0), RadComboBox).SelectedItem.Value
        Me.CurrentFilterFunction = If((currentValue <> ""), GridKnownFunction.EqualTo, GridKnownFunction.NoFilter)
        Return currentValue
    End Function
 
    Private Sub rcBox_SelectedIndexChanged(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs)
        DirectCast(DirectCast(sender, RadComboBox).Parent.Parent, GridFilteringItem).FireCommandEvent("Filter", New Pair())
    End Sub
End Class

Imports Telerik.Web.UI
Imports System.Data
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Data.SqlClient
Imports System.Configuration
 
Public Class _Default
    Inherits System.Web.UI.Page
 
    Public myDataTable As DataTable
 
    Private Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        GetDataTable()
 
        Dim myColumn As MyCustomBoundColumn
 
        myColumn = New MyCustomBoundColumn
        myColumn.DataField = "name"
        myColumn.HeaderText = "name"
        myColumn.dsDataSource = myDataTable
        gvDataTable.MasterTableView.Columns.Add(myColumn)
 
        myColumn = New MyCustomBoundColumn
        myColumn.DataField = "mandant_name"
        myColumn.HeaderText = "mandant_name"
        myColumn.dsDataSource = myDataTable
        gvDataTable.MasterTableView.Columns.Add(myColumn)
    End Sub
 
    Private Sub GetDataTable()
        Dim ConnString As String = ConfigurationManager.ConnectionStrings("MyConnectionString").ConnectionString
        Dim MySqlConnection As New SqlConnection(ConnString)
        Dim MySqlDataAdapter As New SqlDataAdapter()
        MySqlDataAdapter.SelectCommand = New SqlCommand("SELECT * FROM getUser", MySqlConnection)
        MySqlConnection.Open()
        Try
            myDataTable = New DataTable
            MySqlDataAdapter.Fill(myDataTable)
        Finally
            MySqlConnection.Close()
        End Try
 
    End Sub
 
    Private Sub gvDataTable_NeedDataSource(sender As Object, e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles gvDataTable.NeedDataSource
            gvDataTable.DataSource = myDataTable
    End Sub
 
End Class

<form id="form1" runat="server" style="height:100%; width:100%;margin: 0px;padding: 0px;">
    <asp:ToolkitScriptManager ID="ToolkitScriptManager1" ScriptMode="Release" EnableScriptLocalization="true" EnableScriptGlobalization="true"
     CombineScripts="false" runat="server" EnablePartialRendering="true">
    </asp:ToolkitScriptManager>
 
    <asp:UpdatePanel runat="server" ID="upaDT" UpdateMode="Conditional" ChildrenAsTriggers="true">
        <ContentTemplate>
            <telerik:RadButton ID="RadButton1" runat="server" Text="set filter" AutoPostBack="true">
            </telerik:RadButton>
        <telerik:RadGrid ID="gvDataTable" runat="server" AutoGenerateColumns="false" Height="600px" AllowSorting="true" AllowFilteringByColumn="true"
        EnableLinqExpressions="false">
        <MasterTableView DataKeyNames="guid" ClientDataKeyNames="guid" AllowFilteringByColumn="true" EnableColumnsViewState="false">
        </MasterTableView>
        <ClientSettings EnableRowHoverStyle="true" >
            <ClientEvents/>
            <Scrolling AllowScroll="true" UseStaticHeaders="true" />
        </ClientSettings>
        </telerik:RadGrid>
        </ContentTemplate>
    </asp:UpdatePanel>
</form>

2 Answers, 1 is accepted

Sort by
0
Christian
Top achievements
Rank 1
answered on 04 Jul 2012, 04:42 PM
Note: the AutoPostBack of the ComboBox is actually set to TRUE!
0
Maria Ilieva
Telerik team
answered on 09 Jul 2012, 11:53 AM
Hello Christian,

I reviewed your code and it looks correct to me. There is nothing obvious that may cause the problematic beahvior.  Please review the following online demo and verify if the issue could be replicated in it.
http://demos.telerik.com/aspnet-ajax/grid/examples/programming/filteringtemplatecolumns/defaultcs.aspx

All the best,
Maria Ilieva
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
Christian
Top achievements
Rank 1
Answers by
Christian
Top achievements
Rank 1
Maria Ilieva
Telerik team
Share this question
or