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

[Solved] Auto Generated Numeric Columns Not Filtering First Time When ShowFilterIcon = False

1 Answer 232 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Scott
Top achievements
Rank 1
Scott asked on 01 Mar 2013, 09:33 PM
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

Markup:

<%@ Page Language="vb" AutoEventWireup="false" Inherits="acctrpt.acctrpt._Default2"
    validateRequest="false" Codebehind="Default2.aspx.vb" Trace="false" %>
 
 
<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 On
Imports Microsoft.VisualBasic
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web
Imports System.Web.HttpContext
Imports System.Web.UI
Imports System.Web.UI.HTMLControls
Imports System.Web.UI.WebControls
Imports System.Text.RegularExpressions
Imports System.IO
Imports Telerik.Web.UI
 
Namespace 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 Class
End Namespace

1 Answer, 1 is accepted

Sort by
0
Scott
Top achievements
Rank 1
answered on 05 Mar 2013, 06:59 PM
Eyup from Telerik support found the answer for me. I basically need to check the column type and if it is a GridNumericColumn, then I will set CurrentFilterFunction = EqualTo. Full Telerik response below.

Hi Scott,

Thank you for contacting us.

When AutoPostBackOnFilter is True, the column assumes a default filter function of Contains for string types or EqualTo for numeric types.

The issue probably arises because you are trying to set an illegal filter function for the corresponding DateField type. Namely, you are not allowed to set Contains for numeric types. Change the function to EqualTo and the issue should be resolved.

If you want to use the Contains function to filter a numeric field, you can try setting the column DataType to System.String. However, plase keep in mind that the reliability of this approach is not fully tested.

Hope this helps. Please give it a try and let me know about the result.

All the best,
Eyup
the Telerik team
Tags
Grid
Asked by
Scott
Top achievements
Rank 1
Answers by
Scott
Top achievements
Rank 1
Share this question
or