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

Grid Filter Issue

1 Answer 136 Views
This is a migrated thread and some comments may be shown as answers.
Julian Welby-Everard
Top achievements
Rank 1
Julian Welby-Everard asked on 21 Jan 2009, 02:12 PM

I am having an issue with RadGrid.

What I want to do.

Display a data grid allow paging and filtering, well that sounds easy but....

My recordset may have 100000’s of rows so I have implemented AJAX to load the data page at a time, and use VirtualItemCount to set the total number of rows.

This all works fine.

I have tried to add filtering to the grid and again this works sortof. The issue I have is as follows, when a user selects the filter value, this is done in the SQL backend as there is more that 1 possible column to be filtered and the total number of rows is returned and the first page of results therefore changing the total number of pages.

What I am seeing.

When the filter is applied it filters the result in the column first column even through the data set is already filtered.  What I want to do is just display the rows returned in the dataset.

Also I want to disable the filter type list and just have it as a click and go button.

Is there any way of stopping the grid filtering the data as I already do this in my SQL. I still want the filter box at the top of the screen.

Code below...

Mark up


<%@ Page Language="VB" MasterPageFile="~/CRM.master" AutoEventWireup="false" CodeFile="Default.aspx.vb" 
    Inherits="_Default" Title="Untitled Page" %> 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">  
<asp:Content ID="Content2" ContentPlaceHolderID="cph" runat="Server">  
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">  
            <telerik:AjaxSetting AjaxControlID="RadGrid1">  
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1" /> 
        ShowFooter="True" AllowFilteringByColumn="True">  
        <HeaderContextMenu EnableTheming="True">  
            <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> 
        <PagerStyle Mode="NextPrevNumericAndAdvanced" /> 
                <HeaderStyle Width="20px"></HeaderStyle> 
                <HeaderStyle Width="20px"></HeaderStyle> 
        <FilterMenu EnableTheming="True">  
            <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> 
    <br /> 

Code behind
Imports CRM.DAL  
Imports System.Data  
Imports Telerik.Web.UI  
Partial Class _Default  
    Inherits System.Web.UI.Page  
    Private dt As DataTable  
    Private Shared maxRows As Integer  
    Private Shared currentFilter As String  
    Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load  
        Dim gridColumn As GridBoundColumn = New GridBoundColumn()  
        gridColumn.AllowFiltering = True 
        gridColumn.DataField = "ContactSurname" 
        gridColumn.HeaderText = "Surname" 
        gridColumn.UniqueName = "ContactSurname" 
        gridColumn = New GridBoundColumn()  
        gridColumn.AllowFiltering = False 
        gridColumn.DataField = "ContactFirstForename" 
        gridColumn.HeaderText = "First Forename" 
        gridColumn.UniqueName = "ContactFirstForename" 
        gridColumn = New GridBoundColumn()  
        gridColumn.AllowFiltering = False 
        gridColumn.DataField = "ClientName" 
        gridColumn.HeaderText = "Client Name" 
        gridColumn.UniqueName = "ClientName" 
        RadGrid1.VirtualItemCount = maxRows 
        RadGrid1.GroupingSettings.CaseSensitive = False 
    End Sub  
    Protected Sub RadGrid1_NeedDataSource(ByVal source As Object, ByVal e As GridNeedDataSourceEventArgs)  
        dt = GetDataTable(currentFilter, RadGrid1.CurrentPageIndex, RadGrid1.PageSize)  
        Me.RadGrid1.DataSource = dt 
    End Sub  
    Protected Sub RadGrid1_ColumnCreating(ByVal sender As Object, ByVal e As GridColumnCreatingEventArgs)  
        If (e.ColumnType = GetType(GridBoundColumn).Name) Then  
            Dim gridColumn As GridBoundColumn = New GridBoundColumn()  
            gridColumn.DataField = CType(e.Column, GridBoundColumn).DataField  
            gridColumn.HeaderText = CType(e.Column, GridBoundColumn).HeaderText  
            gridColumn.UniqueName = CType(e.Column, GridBoundColumn).UniqueName  
            gridColumn.AllowFiltering = CType(e.Column, GridBoundColumn).AllowFiltering  
            e.Column = gridColumn 
        End If  
    End Sub  
    Protected Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As GridCommandEventArgs)  
        If (e.CommandName = RadGrid.FilterCommandName) Then  
            Dim column As GridBoundColumn = e.Item.OwnerTableView.Columns(0)  
            If column.AllowFiltering Then  
                dt = GetDataTable(column.CurrentFilterValue, RadGrid1.CurrentPageIndex, RadGrid1.PageSize)  
                currentFilter = column.CurrentFilterValue  
                column.CurrentFilterValue = String.Empty  
                column.CurrentFilterFunction = GridKnownFunction.NoFilter  
                RadGrid1.DataSource = dt 
                RadGrid1.MasterTableView.FilterExpression = String.Empty  
                RadGrid1.VirtualItemCount = maxRows 
                RadGrid1.GroupingSettings.CaseSensitive = False 
            End If  
        End If  
    End Sub  
    Public Shared Function GetDataTable(ByVal query As String, ByVal CurrentPageIndex As Integer, ByVal PageSize As Integer) As DataTable  
        Dim myDataTable As DataTable  
        If query = String.Empty Then  
            query = "%" 
        End If  
        Dim ds As DataSet = DAL.SelectContacts(query, CurrentPageIndex, PageSize)  
        myDataTable = ds.Tables(0)  
        maxRows = ds.Tables(1).Rows(0).Item("TotalRecords")  
        myDataTable.CaseSensitive = False 
        Return myDataTable  
    End Function  
End Class  

1 Answer, 1 is accepted

Sort by
Iana Tsolova
Telerik team
answered on 26 Jan 2009, 08:11 AM
Hi Julian,

I suggest that you define your custom FilterTemplate in order to achieve the desired functionality with the "go button". You can also canceling the default grid filtering functionality as below:

Protected Sub RadGrid1_ItemCommand(ByVal source As Object, _  
     ByVal e As GridCommandEventArgs) Handles RadGrid1.ItemCommand  
  If e.CommandName = RadGrid.FilterCommandName Then 
    e.Canceled = True 
  End If 
End Sub 

Find more about custom filtering with RadGrid in the following online resources:

I hope this helps.

the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Asked by
Julian Welby-Everard
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Share this question