Radgrid Filtering onkeypress

2 posts, 0 answers
  1. Anthony
    Anthony avatar
    6 posts
    Member since:
    Aug 2010

    Posted 04 Mar 2011 Link to this post

    Requirements

    RadControls version

    V.2010.3.1215.35
    .NET version

    3.5
    Visual Studio version

    2008 SP1
    programming language

    VB.Net
    browser support

    all browsers supported by RadControls


    PROJECT DESCRIPTION
    [This projects shows major javascript adjustments to a radgrid. It shows how to filter a grid onkeypress so when the user types something into the filter, it will filter by a default filter type that you have set. If they want a specific filter type other than that one, then they must select it using the filter button (the conventional way). It also shows how to avoid javascript errors for columns without filters and for datecolumns so you wont filter an incorrect date.  Hope this is helpful.]



    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
     
    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <head runat="server">
        <title></title>
        <telerik:RadStyleSheetManager ID="RadStyleSheetManager1" runat="server" />
    </head>
    <body>
        <form id="form1" runat="server">
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
            <Scripts>
                <%--Needed for JavaScript IntelliSense in VS2010--%>
                <%--For VS2008 replace RadScriptManager with ScriptManager--%>
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
            </Scripts>
        </telerik:RadScriptManager>
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" DefaultLoadingPanelID="rlpProgress" ClientEvents-OnRequestStart="request">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="RadTabStrip1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadTabStrip1" />
                <telerik:AjaxUpdatedControl ControlID="rmp1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="rmp1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadTabStrip1" />
                <telerik:AjaxUpdatedControl ControlID="rmp1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
    </telerik:RadAjaxManager>
     
     
        <telerik:RadAjaxLoadingPanel ID="rlpProgress" runat="server" Skin="Default" BackgroundPosition="Center" />
        <telerik:RadTabStrip ID="RadTabStrip1" runat="server" MultiPageID="rmp1">
            <Tabs>
                <telerik:RadTab Text="tab 1" Value="1" PageViewID="rpv1" Selected="true">
                </telerik:RadTab>
                <telerik:RadTab Text="tab 2" Value="2" PageViewID="rpv2">
                </telerik:RadTab>
                <telerik:RadTab Text="tab 3" Value="3" PageViewID="rpv3">
                </telerik:RadTab>
                <telerik:RadTab Text="tab 4" Value="4" PageViewID="rpv4">
                </telerik:RadTab>
            </Tabs>
        </telerik:RadTabStrip>
        <telerik:RadMultiPage ID="rmp1" runat="server">
            <telerik:RadPageView ID="rpv1" runat="server" Selected="true">
                <h1>
                    Grid 1</h1>
                <telerik:RadGrid ID="grid1" runat="server" AllowFilteringByColumn="True" AllowPaging="True"
                    AllowSorting="True">
                    <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default">
                    </HeaderContextMenu>
                    <MasterTableView AutoGenerateColumns="False" DataKeyNames="ID">
                        <CommandItemSettings ExportToPdfText="Export to Pdf" />
                        <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column">
                            <HeaderStyle Width="20px" />
                        </RowIndicatorColumn>
                        <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column">
                            <HeaderStyle Width="20px" />
                        </ExpandCollapseColumn>
                        <Columns>
                            <telerik:GridBoundColumn DataField="ID" DataType="System.Int32" FilterListOptions="VaryByDataType"
                                FilterControlAltText="Filter ID column" HeaderText="ID" ReadOnly="True" SortExpression="ID"
                                UniqueName="ID">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="Name" FilterListOptions="VaryByDataType" FilterControlAltText="Filter Name column"
                                HeaderText="Name" SortExpression="Name" UniqueName="Name">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="Address" FilterListOptions="VaryByDataType" FilterControlAltText="Filter Address column"
                                HeaderText="Address" SortExpression="Address" UniqueName="Address">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="City" FilterListOptions="VaryByDataType" FilterControlAltText="Filter City column"
                                HeaderText="City" SortExpression="City" UniqueName="City">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="State" FilterListOptions="VaryByDataType" FilterControlAltText="Filter State column"
                                HeaderText="State" SortExpression="State" UniqueName="State">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="ZipCode" FilterListOptions="VaryByDataType" FilterControlAltText="Filter ZipCode column"
                                HeaderText="ZipCode" SortExpression="ZipCode" UniqueName="ZipCode">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="PhoneNo" FilterListOptions="VaryByDataType" FilterControlAltText="Filter PhoneNo column"
                                HeaderText="PhoneNo" SortExpression="PhoneNo" UniqueName="PhoneNo">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="Email" FilterListOptions="VaryByDataType" FilterControlAltText="Filter Email column"
                                HeaderText="Email" SortExpression="Email" UniqueName="Email">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="Comments" FilterListOptions="VaryByDataType"
                                FilterControlAltText="Filter Comments column" HeaderText="Comments" SortExpression="Comments"
                                UniqueName="Comments">
                            </telerik:GridBoundColumn>
                            <telerik:GridDateTimeColumn DataField="DateEntered" FilterListOptions="VaryByDataType"
                                FilterControlAltText="Filter DateEntered column" HeaderText="DateEntered" ReadOnly="True"
                                SortExpression="DateEntered" UniqueName="DateEntered" DataType="System.DateTime"
                                DataFormatString="{0:MM/dd/yyyy}">
                            </telerik:GridDateTimeColumn>
                        </Columns>
                        <EditFormSettings>
                            <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                            </EditColumn>
                        </EditFormSettings>
                    </MasterTableView>
                    <GroupingSettings CaseSensitive="false" />
                    <FilterMenu EnableImageSprites="False">
                    </FilterMenu>
                </telerik:RadGrid>
            </telerik:RadPageView>
            <telerik:RadPageView ID="rpv2" runat="server">
                <h1>
                    Grid 2</h1>
                <telerik:RadGrid ID="grid2" runat="server" AllowFilteringByColumn="True" AllowPaging="True"
                    AllowSorting="True">
                    <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default">
                    </HeaderContextMenu>
                    <MasterTableView AutoGenerateColumns="False" DataKeyNames="ID">
                        <CommandItemSettings ExportToPdfText="Export to Pdf" />
                        <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column">
                            <HeaderStyle Width="20px" />
                        </RowIndicatorColumn>
                        <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column">
                            <HeaderStyle Width="20px" />
                        </ExpandCollapseColumn>
                        <Columns>
                            <telerik:GridBoundColumn DataField="ID" DataType="System.Int32" FilterListOptions="VaryByDataType"
                                FilterControlAltText="Filter ID column" HeaderText="ID" ReadOnly="True" SortExpression="ID"
                                UniqueName="ID">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="Name" FilterListOptions="VaryByDataType" FilterControlAltText="Filter Name column"
                                HeaderText="Name" SortExpression="Name" UniqueName="Name">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="Address" FilterListOptions="VaryByDataType" FilterControlAltText="Filter Address column"
                                HeaderText="Address" SortExpression="Address" UniqueName="Address">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="City" FilterListOptions="VaryByDataType" FilterControlAltText="Filter City column"
                                HeaderText="City" SortExpression="City" UniqueName="City">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="State" FilterListOptions="VaryByDataType" FilterControlAltText="Filter State column"
                                HeaderText="State" SortExpression="State" UniqueName="State">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="ZipCode" FilterListOptions="VaryByDataType" FilterControlAltText="Filter ZipCode column"
                                HeaderText="ZipCode" SortExpression="ZipCode" UniqueName="ZipCode">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="PhoneNo" FilterListOptions="VaryByDataType" FilterControlAltText="Filter PhoneNo column"
                                HeaderText="PhoneNo" SortExpression="PhoneNo" UniqueName="PhoneNo">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="Email" FilterListOptions="VaryByDataType" FilterControlAltText="Filter Email column"
                                HeaderText="Email" SortExpression="Email" UniqueName="Email">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="Comments" FilterListOptions="VaryByDataType"
                                FilterControlAltText="Filter Comments column" HeaderText="Comments" SortExpression="Comments"
                                UniqueName="Comments">
                            </telerik:GridBoundColumn>
                            <telerik:GridDateTimeColumn DataField="DateEntered" FilterListOptions="VaryByDataType"
                                FilterControlAltText="Filter DateEntered column" HeaderText="DateEntered" ReadOnly="True"
                                SortExpression="DateEntered" UniqueName="DateEntered" DataType="System.DateTime"
                                DataFormatString="{0:MM/dd/yyyy}">
                            </telerik:GridDateTimeColumn>
                        </Columns>
                        <EditFormSettings>
                            <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                            </EditColumn>
                        </EditFormSettings>
                    </MasterTableView>
                    <GroupingSettings CaseSensitive="false" />
                    <FilterMenu EnableImageSprites="False">
                    </FilterMenu>
                </telerik:RadGrid>
            </telerik:RadPageView>
            <telerik:RadPageView ID="rpv3" runat="server">
                <h1>
                    Grid 3</h1>
                <telerik:RadGrid ID="grid3" runat="server" AllowFilteringByColumn="True" AllowPaging="True"
                    AllowSorting="True">
                    <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default">
                    </HeaderContextMenu>
                    <MasterTableView AutoGenerateColumns="False" DataKeyNames="ID">
                        <CommandItemSettings ExportToPdfText="Export to Pdf" />
                        <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column">
                            <HeaderStyle Width="20px" />
                        </RowIndicatorColumn>
                        <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column">
                            <HeaderStyle Width="20px" />
                        </ExpandCollapseColumn>
                        <Columns>
                            <telerik:GridBoundColumn DataField="ID" DataType="System.Int32" FilterListOptions="VaryByDataType"
                                FilterControlAltText="Filter ID column" HeaderText="ID" ReadOnly="True" SortExpression="ID"
                                UniqueName="ID">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="Name" FilterListOptions="VaryByDataType" FilterControlAltText="Filter Name column"
                                HeaderText="Name" SortExpression="Name" UniqueName="Name">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="Address" FilterListOptions="VaryByDataType" FilterControlAltText="Filter Address column"
                                HeaderText="Address" SortExpression="Address" UniqueName="Address">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="City" FilterListOptions="VaryByDataType" FilterControlAltText="Filter City column"
                                HeaderText="City" SortExpression="City" UniqueName="City">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="State" FilterListOptions="VaryByDataType" FilterControlAltText="Filter State column"
                                HeaderText="State" SortExpression="State" UniqueName="State">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="ZipCode" FilterListOptions="VaryByDataType" FilterControlAltText="Filter ZipCode column"
                                HeaderText="ZipCode" SortExpression="ZipCode" UniqueName="ZipCode">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="PhoneNo" FilterListOptions="VaryByDataType" FilterControlAltText="Filter PhoneNo column"
                                HeaderText="PhoneNo" SortExpression="PhoneNo" UniqueName="PhoneNo">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="Email" FilterListOptions="VaryByDataType" FilterControlAltText="Filter Email column"
                                HeaderText="Email" SortExpression="Email" UniqueName="Email">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="Comments" FilterListOptions="VaryByDataType"
                                FilterControlAltText="Filter Comments column" HeaderText="Comments" SortExpression="Comments"
                                UniqueName="Comments">
                            </telerik:GridBoundColumn>
                            <telerik:GridDateTimeColumn DataField="DateEntered" FilterListOptions="VaryByDataType"
                                FilterControlAltText="Filter DateEntered column" HeaderText="DateEntered" ReadOnly="True"
                                SortExpression="DateEntered" UniqueName="DateEntered" DataType="System.DateTime"
                                DataFormatString="{0:MM/dd/yyyy}">
                            </telerik:GridDateTimeColumn>
                        </Columns>
                        <EditFormSettings>
                            <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                            </EditColumn>
                        </EditFormSettings>
                    </MasterTableView>
                    <GroupingSettings CaseSensitive="false" />
                    <FilterMenu EnableImageSprites="False">
                    </FilterMenu>
                </telerik:RadGrid>
            </telerik:RadPageView>
            <telerik:RadPageView ID="rpv4" runat="server">
                <h1>
                    Grid 4</h1>
                <telerik:RadGrid ID="grid4" runat="server" AllowFilteringByColumn="True" AllowPaging="True"
                    AllowSorting="True">
                    <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default">
                    </HeaderContextMenu>
                    <MasterTableView AutoGenerateColumns="False" DataKeyNames="ID">
                        <CommandItemSettings ExportToPdfText="Export to Pdf" />
                        <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column">
                            <HeaderStyle Width="20px" />
                        </RowIndicatorColumn>
                        <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column">
                            <HeaderStyle Width="20px" />
                        </ExpandCollapseColumn>
                        <Columns>
                            <telerik:GridBoundColumn DataField="ID" DataType="System.Int32" FilterListOptions="VaryByDataType"
                                FilterControlAltText="Filter ID column" HeaderText="ID" ReadOnly="True" SortExpression="ID"
                                UniqueName="ID">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="Name" FilterListOptions="VaryByDataType" FilterControlAltText="Filter Name column"
                                HeaderText="Name" SortExpression="Name" UniqueName="Name">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="Address" FilterListOptions="VaryByDataType" FilterControlAltText="Filter Address column"
                                HeaderText="Address" SortExpression="Address" UniqueName="Address">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="City" FilterListOptions="VaryByDataType" FilterControlAltText="Filter City column"
                                HeaderText="City" SortExpression="City" UniqueName="City">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="State" FilterControlAltText="Filter State column"
                                HeaderText="State" SortExpression="State" UniqueName="State">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="ZipCode" FilterListOptions="VaryByDataType" FilterControlAltText="Filter ZipCode column"
                                HeaderText="ZipCode" SortExpression="ZipCode" UniqueName="ZipCode">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="PhoneNo" FilterListOptions="VaryByDataType" FilterControlAltText="Filter PhoneNo column"
                                HeaderText="PhoneNo" SortExpression="PhoneNo" UniqueName="PhoneNo">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="Email" FilterListOptions="VaryByDataType" FilterControlAltText="Filter Email column"
                                HeaderText="Email" SortExpression="Email" UniqueName="Email">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="Comments" FilterListOptions="VaryByDataType"
                                FilterControlAltText="Filter Comments column" HeaderText="Comments" SortExpression="Comments"
                                UniqueName="Comments">
                            </telerik:GridBoundColumn>
                            <telerik:GridDateTimeColumn DataField="DateEntered" FilterListOptions="VaryByDataType"
                                FilterControlAltText="Filter DateEntered column" HeaderText="DateEntered" ReadOnly="True"
                                SortExpression="DateEntered" UniqueName="DateEntered" DataType="System.DateTime"
                                DataFormatString="{0:MM/dd/yyyy}">
                            </telerik:GridDateTimeColumn>
                        </Columns>
                        <EditFormSettings>
                            <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                            </EditColumn>
                        </EditFormSettings>
                    </MasterTableView>
                    <GroupingSettings CaseSensitive="false" />
                    <FilterMenu EnableImageSprites="False">
                    </FilterMenu>
                </telerik:RadGrid>
            </telerik:RadPageView>
        </telerik:RadMultiPage>
        <telerik:RadButton ID="chkbox" runat="server" ButtonType="ToggleButton" Skin="Web20"
            Text="Checkbox" ToggleType="CheckBox" Font-Underline="false">
        </telerik:RadButton>
        <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
            <script type="text/javascript">
     
                function doFilter(sender, eventArgs, gvwName) {
                    if ((eventArgs.keyCode == 13 || eventArgs.keyCode == 9) && (sender.value != "")) {
                        eventArgs.cancelBubble = true;
                        eventArgs.returnValue = false;
                        if (eventArgs.stopPropagation) {
                            eventArgs.stopPropagation();
                            eventArgs.preventDefault();
                        }
                        var masterTableView = $find(gvwName).get_masterTableView();
                        var index = sender.parentNode.cellIndex;
                        var columns = masterTableView.get_columns();
                        var uniqueName = columns[index].get_uniqueName();
                        var filterFunction = columns[index].get_filterFunction();
                        masterTableView.filter(uniqueName, sender.value, filterFunction);
                    }
                }
     
                function doFilterDate(sender, eventArgs, gvwName, gvwColName) {
                    code = eventArgs.keyCode;
                    setTimeout(function () {
     
                        if (isValid) {
                            if ((code == 13 || code == 9) && (sender.value != "")) {
                                var masterTableView = $find(gvwName).get_masterTableView();
                                masterTableView.filter(gvwColName, sender.value, Telerik.Web.UI.GridFilterFunction.EqualTo);
                            }
                        };
                    }, 300);
                    isValid = true;
                }
     
                function FilterChanged(sender, eventArgs, gvwName) {
     
                    var active = document.activeElement;
     
                    if (sender.value == "") {
                        eventArgs.cancelBubble = true;
                        eventArgs.returnValue = false;
                        if (eventArgs.stopPropagation) {
                            eventArgs.stopPropagation();
                            eventArgs.preventDefault();
                        }
                        var masterTableView = $find(gvwName).get_masterTableView();
     
                        var index = sender.parentNode.cellIndex;
                        var columns = masterTableView.get_columns();
                        var uniqueName = columns[index].get_uniqueName();
                        masterTableView.filter(uniqueName, sender.value, Telerik.Web.UI.GridFilterFunction.NoFilter);
                    }
                }
     
                function FilterChangedDate(sender, eventArgs, gvwName, gvwColName) {
     
                    var active = document.activeElement;
     
                    if (sender.value == "") {
                        eventArgs.cancelBubble = true;
                        eventArgs.returnValue = false;
                        if (eventArgs.stopPropagation) {
                            eventArgs.stopPropagation();
                            eventArgs.preventDefault();
                        }
                        var masterTableView = $find(gvwName).get_masterTableView();
                        masterTableView.filter(gvwColName, sender.value, Telerik.Web.UI.GridFilterFunction.NoFilter);
                    }
                }
     
                function request(sender, eventArgs) {
                    //debugger;
                }
                var isValid = true;
                function Error(sender, eventArgs) {
                    //debugger;
                    isValid = false;
                }
            </script>
        </telerik:RadCodeBlock>
        </form>
    </body>
    </html>







    Imports Telerik.Web.UI
    Imports Telerik.Web
    Imports System.Data.OleDb
    Imports System.Data
    Imports System.Data.SqlClient
    Imports System.Data.Sql
     
    Partial Class _Default
        Inherits System.Web.UI.Page
     
        Public dbConn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("~/app_data/RadGridFilteringIssue.mdb") & ";User Id=admin;Password=;")
        Public strSQL As String = "SELECT People.ID, People.Name, People.Address, People.City, People.State, People.ZipCode, People.PhoneNo, People.Email, People.Comments, Date As DateEntered FROM People"
     
        Public Sub AddFilterOnKey(ByVal gvwName As String, ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs)
            Dim gvw As RadGrid = DirectCast(rmp1.FindControl(gvwName), RadGrid)
            Dim ctrl As Control
            If TypeOf e.Item Is GridFilteringItem Then
                Dim fltItem As GridFilteringItem = TryCast(e.Item, GridFilteringItem)
                For Each column As GridColumn In gvw.Columns
                    column.CurrentFilterFunction = GridKnownFunction.Contains
                    ctrl = fltItem(column.UniqueName).Controls(0)
                    If TypeOf ctrl Is TextBox Then
                        Dim box As TextBox = TryCast(ctrl, TextBox)
                        box.Attributes.Add("onkeydown", "doFilter(this,event,'" & gvw.ClientID & "')")
                        box.Attributes.Add("onchange", "FilterChanged(this,event,'" & gvw.ClientID & "')")
                    ElseIf TypeOf ctrl Is RadDatePicker Then
                        Dim datepick As RadDatePicker = TryCast(ctrl, RadDatePicker)
                        Dim dateinput As RadDateInput = TryCast(datepick.DateInput, RadDateInput)
                        dateinput.Attributes.Add("onkeypress", "doFilterDate(this,event,'" & gvw.ClientID & "','" & column.UniqueName & "')")
                        dateinput.Attributes.Add("onchange", "FilterChangedDate(this,event,'" & gvw.ClientID & "','" & column.UniqueName & "')")
                        dateinput.ClientEvents.OnError = "Error"
                    End If
                Next
            End If
        End Sub
     
        Protected Sub grid1_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles grid1.ItemCreated
            For Each column As GridColumn In grid1.Columns
                If column.CurrentFilterFunction = GridKnownFunction.NoFilter Then
                    If Not column.UniqueName = "Delete" Then
                        column.CurrentFilterFunction = GridKnownFunction.Contains
                    End If
                End If
            Next
            AddFilterOnKey("grid1", sender, e)
        End Sub
     
        Protected Sub grid2_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles grid2.ItemCreated
            For Each column As GridColumn In grid2.Columns
                If column.CurrentFilterFunction = GridKnownFunction.NoFilter Then
                    If Not column.UniqueName = "Delete" Then
                        column.CurrentFilterFunction = GridKnownFunction.Contains
                    End If
                End If
            Next
            AddFilterOnKey("grid2", sender, e)
        End Sub
     
     
        Protected Sub grid3_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles grid3.ItemCreated
            For Each column As GridColumn In grid3.Columns
                If column.CurrentFilterFunction = GridKnownFunction.NoFilter Then
                    If Not column.UniqueName = "Delete" Then
                        column.CurrentFilterFunction = GridKnownFunction.Contains
                    End If
                End If
            Next
            AddFilterOnKey("grid3", sender, e)
        End Sub
     
        Protected Sub grid4_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles grid4.ItemCreated
            For Each column As GridColumn In grid4.Columns
                If column.CurrentFilterFunction = GridKnownFunction.NoFilter Then
                    If Not column.UniqueName = "Delete" Then
                        column.CurrentFilterFunction = GridKnownFunction.Contains
                    End If
                End If
            Next
            AddFilterOnKey("grid4", sender, e)
        End Sub
     
        Protected Sub grid1_SortCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridSortCommandEventArgs) Handles grid1.SortCommand
            DataBindGrid("grid1")
        End Sub
     
        Protected Sub grid1_ItemCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles grid1.ItemCommand
            If e.CommandName = RadGrid.FilterCommandName Then
                DataBindGrid("grid1")
            End If
        End Sub
     
        Protected Sub grid2_SortCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridSortCommandEventArgs) Handles grid2.SortCommand
            DataBindGrid("grid2")
        End Sub
     
        Protected Sub grid2_ItemCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles grid2.ItemCommand
            If e.CommandName = RadGrid.FilterCommandName Then
                DataBindGrid("grid2")
            End If
        End Sub
     
        Protected Sub grid3_SortCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridSortCommandEventArgs) Handles grid3.SortCommand
            DataBindGrid("grid3")
        End Sub
     
        Protected Sub grid3_ItemCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles grid3.ItemCommand
            If e.CommandName = RadGrid.FilterCommandName Then
                DataBindGrid("grid3")
            End If
        End Sub
     
        Protected Sub grid4_SortCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridSortCommandEventArgs) Handles grid4.SortCommand
            DataBindGrid("grid4")
        End Sub
     
        Protected Sub grid4_ItemCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles grid4.ItemCommand
            If e.CommandName = RadGrid.FilterCommandName Then
                DataBindGrid("grid4")
            End If
        End Sub
     
        Public Sub DataBindGrid(ByVal gvwName As String)
            Dim gvw As RadGrid = DirectCast(rmp1.FindControl(gvwName), RadGrid)
     
            Dim reader As OleDbDataReader
            Dim cmd As New OleDbCommand(strSQL, dbConn)
     
            Dim dt As New DataTable
            dbConn.Open()
            Try
                reader = cmd.ExecuteReader
                If reader.HasRows Then
                    dt.Load(reader)
                End If
            Catch ex As Exception
            Finally
                If Not dbConn Is Nothing Then dbConn.Close()
            End Try
     
            gvw.DataSource = dt
            gvw.DataBind()
        End Sub
     
        Public Sub GetDataSource(ByVal gvwName As String)
            Dim gvw As RadGrid = DirectCast(rmp1.FindControl(gvwName), RadGrid)
     
            Dim reader As OleDbDataReader
            Dim cmd As New OleDbCommand(strSQL, dbConn)
     
            Dim dt As New DataTable
            dbConn.Open()
            Try
                reader = cmd.ExecuteReader
                If reader.HasRows Then
                    dt.Load(reader)
                End If
            Catch ex As Exception
            Finally
                If Not dbConn Is Nothing Then dbConn.Close()
            End Try
     
            gvw.DataSource = dt
        End Sub
     
        Protected Sub grid4_NeedDataSource(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles grid4.NeedDataSource
            GetDataSource("grid4")
        End Sub
     
        Protected Sub grid3_NeedDataSource(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles grid3.NeedDataSource
            GetDataSource("grid3")
        End Sub
     
     
        Protected Sub grid2_NeedDataSource(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles grid2.NeedDataSource
            GetDataSource("grid2")
        End Sub
     
        Protected Sub grid1_NeedDataSource(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles grid1.NeedDataSource
            GetDataSource("grid1")
        End Sub
    End Class
  2. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 07 Mar 2011 Link to this post

    Hi Anthony,

    Thank you for the submission, however filtering on enter key press is supported out-of-the-box by our AJAX web grid (see the configuration of the first two columns in this demo). Hence you do not need to code that explicitly with javascript.
     
    Nevertheless, your implementation can be helpful for Telerik community members, that is why I converted your thread to a forum post and updated your Telerik points for the involvement. 

    Best regards,
    Sebastian
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top