Here is the scenario I am attempting to achieve:
Create a RadGrid set to AutoGenerateColumns. Events on the page can change the data source of this RadGrid. Programatically, I will look for various known possible column and turn on or off the filter for each column. Instead of forcing the user to use the Filter Icon Button, I want all filtering to utilize the "Contains" filter logic, so I am specifying this in the ColumnCreated event.
The problem that I am running into is that for numeric columns, the first time that I type a filter value into the filter textbox and hit enter or tab, the filter value is cleared out and the filter is not applied. The second time I type it, it works.
I am using Telerik.Web.UI.dll version 2013.1.220.40. the behavior is consistent in Chrome v 25.0.1364.97 and IE 9.0.8112.16421. A simplified page that exhibits this behavior is below. Any help will be appriciated. Thank you.
-Scott
Code Behind:
Create a RadGrid set to AutoGenerateColumns. Events on the page can change the data source of this RadGrid. Programatically, I will look for various known possible column and turn on or off the filter for each column. Instead of forcing the user to use the Filter Icon Button, I want all filtering to utilize the "Contains" filter logic, so I am specifying this in the ColumnCreated event.
The problem that I am running into is that for numeric columns, the first time that I type a filter value into the filter textbox and hit enter or tab, the filter value is cleared out and the filter is not applied. The second time I type it, it works.
I am using Telerik.Web.UI.dll version 2013.1.220.40. the behavior is consistent in Chrome v 25.0.1364.97 and IE 9.0.8112.16421. A simplified page that exhibits this behavior is below. Any help will be appriciated. Thank you.
-Scott
Markup:
<%@ Page Language="vb" AutoEventWireup="false" Inherits="acctrpt.acctrpt._Default2" validateRequest="false" Codebehind="Default2.aspx.vb" Trace="false" %><html xmlns="http://www.w3.org/1999/xhtml"><head id="Head1" runat="server"> <title></title></head> <body> <form runat="server"> <telerik:RadScriptManager ID="ScriptManager1" runat="server" /> <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server"> <script type="text/javascript"> function RequestStart(sender, args) { if (args.get_eventTarget().indexOf("ExportToCsvButton") >= 0) args.set_enableAjax(false); } </script> </telerik:RadCodeBlock> <telerik:RadCodeBlock ID="RadCodeBlock2" runat="server"> <style type="text/css"> a:hover {color: #444444; text-decoration: overline underline; background-color: #E1DDC9 !important;} </style> </telerik:RadCodeBlock> <telerik:RadAjaxManager ID="AjaxManager1" runat="server" > <ClientEvents OnRequestStart="RequestStart" ></ClientEvents> <AjaxSettings> <telerik:AjaxSetting AjaxControlID="rgValidate"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="rgValidate" /> </UpdatedControls> </telerik:AjaxSetting> </AjaxSettings> </telerik:RadAjaxManager> <table id="tblGrids" width="96%" align="center" runat="server" > <tr><td> <telerik:RadGrid ID="rgValidate" runat="server" AutoGenerateColumns="true" Width="100%" ItemStyle-Wrap="false" FilterItemStyle-Width="100%" AllowSorting="true" AllowPaging="true" AllowFilteringByColumn="true" Skin="Outlook" > <GroupingSettings CaseSensitive="false" /> <PagerStyle AlwaysVisible="true" /> <ExportSettings HideStructureColumns="true" OpenInNewWindow="false" IgnorePaging="true" ExportOnlyData="true" /> <MasterTableView CommandItemDisplay="Top" HierarchyLoadMode="Client" GroupLoadMode="Server" > <CommandItemSettings ShowExportToCsvButton="true" ShowAddNewRecordButton="false" ExportToCsvText="grid" /> </MasterTableView> </telerik:RadGrid> </td></tr> </table> <asp:Button runat="server" ID="btn1" Text="Data Source 1" UseSubmitBehavior="false" /> <asp:Button runat="server" ID="btn2" Text="Data Source 2" UseSubmitBehavior="false" /> </form> </body></html>Code Behind:
Option Strict OnImports Microsoft.VisualBasicImports SystemImports System.DataImports System.Data.SqlClientImports System.WebImports System.Web.HttpContextImports System.Web.UIImports System.Web.UI.HTMLControlsImports System.Web.UI.WebControlsImports System.Text.RegularExpressionsImports System.IOImports Telerik.Web.UINamespace acctrpt Partial Class _Default2 : Inherits page Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If Not IsPostBack Then Dim dt1 As New DataTable dt1.Columns.Add("Column1", GetType(Integer)) dt1.Columns.Add("Column2", GetType(Integer)) dt1.Columns.Add("Column3", GetType(Integer)) Dim dt2 As New DataTable dt2.Columns.Add("Field1", GetType(Integer)) dt2.Columns.Add("Field2", GetType(Integer)) dt2.Columns.Add("Field3", GetType(Integer)) For i As Integer = 1 to 20 Dim dr1 As DataRow = dt1.NewRow Dim dr2 As DataRow = dt2.NewRow dr1("Column1") = i dr1("Column2") = i + 100 dr1("Column3") = i + 1000 dr2("Field1") = i dr2("Field2") = i + 200 dr2("Field3") = i + 2000 dt1.Rows.Add(dr1) dt2.Rows.Add(dr2) Next Session("DS1") = dt1.DefaultView Session("DS2") = dt2.DefaultView Session("ActiveDataSource") = "1" End If End Sub Private Sub rgValidate_NeedDataSource(sender As Object, e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles rgValidate.NeedDataSource Select Case Session("ActiveDataSource").ToString() Case "1" rgValidate.DataSource = Session("DS1") Case "2" rgValidate.DataSource = Session("DS2") Case Else rgValidate.DataSource = Nothing End Select rgValidate.ExportSettings.FileName = "Export" & Session("ActiveDataSource").ToString() End Sub Private Sub btn1_Click(sender As Object, e As System.EventArgs) Handles btn1.Click Session("ActiveDataSource") = "1" If rgValidate.MasterTableView isnot Nothing then rgValidate.MasterTableView.SortExpressions.Clear() rgValidate.MasterTableView.FilterExpression = "" rgValidate.MasterTableView.GroupByExpressions.Clear() End If rgValidate.Rebind() End Sub Private Sub btn2_Click(sender As Object, e As System.EventArgs) Handles btn2.Click Session("ActiveDataSource") = "2" If rgValidate.MasterTableView isnot Nothing then rgValidate.MasterTableView.SortExpressions.Clear() rgValidate.MasterTableView.FilterExpression = "" rgValidate.MasterTableView.GroupByExpressions.Clear() End If rgValidate.Rebind() End Sub Private Sub rgValidate_ColumnCreated(sender As Object, e As Telerik.Web.UI.GridColumnCreatedEventArgs) Handles rgValidate.ColumnCreated If TypeOf e.Column is GridBoundColumn Then Dim col As GridBoundColumn = DirectCast(e.Column, GridBoundColumn) Select Case True Case col.UniqueName.ToLower.Contains("1") col.AllowFiltering = False Case col.UniqueName.ToLower.Contains("2") col.CurrentFilterFunction = GridKnownFunction.Contains col.ShowFilterIcon = False col.AutoPostBackOnFilter = True col.FilterControlWidth = New Unit (110, UnitType.Pixel) col.FilterControlToolTip = "Filter Data" Case col.UniqueName.ToLower.Contains("3") col.CurrentFilterFunction = GridKnownFunction.Contains col.ShowFilterIcon = False col.FilterControlToolTip = "Filter Data" col.AutoPostBackOnFilter = True col.ItemStyle.Width = New Unit(110) col.FilterControlWidth = New Unit(85, UnitType.Percentage) End Select End If End Sub End ClassEnd Namespace