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

very slow for custom filtering in gridview

2 Answers 314 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Hengky
Top achievements
Rank 1
Veteran
Hengky asked on 01 Feb 2016, 09:46 AM

Hello all 

i have the problem about custom filtering ... 

why custom filtering in gridview is very slowly 

this the code i write 

 Imports System.Data.SqlClient

Public Class Form1
    Dim conn As SqlConnection
    Dim da As SqlDataAdapter
    Dim ds As DataSet

    Dim str As String = "Server=CHIP-PC;Initial Catalog=Kebun;uid=sa;pwd=351980"

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Using conn As New SqlConnection(str)

            conn.Open()

            da = New SqlDataAdapter("SELECT * FROM MstPekerja", conn)
            ds = New DataSet
            ds.Clear()
            da.Fill(ds, "TrPekerja")
            RadGridView1.DataSource = (ds.Tables("TrPekerja"))

            conn.Close()
        End Using
    End Sub
    Private Sub RadGridview1_CustomFiltering(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.GridViewCustomFilteringEventArgs) Handles RadGridView1.CustomFiltering
        If String.IsNullOrEmpty(Me.RadTextBox1.Text) Then
            e.Visible = True
            For i As Integer = 0 To Me.RadGridView1.ColumnCount - 1
                e.Row.Cells(i).Style.Reset()
                e.Row.InvalidateRow()
            Next i
            Return
        End If
        e.Visible = False
        For i As Integer = 0 To Me.RadGridView1.ColumnCount - 1
            Dim text As String = e.Row.Cells(i).Value.ToString()
            If text.IndexOf(Me.RadTextBox1.Text, 0, StringComparison.InvariantCultureIgnoreCase) >= 0 Then
                e.Visible = True
                e.Row.Cells(i).Style.CustomizeFill = True
                e.Row.Cells(i).Style.DrawFill = True
                e.Row.Cells(i).Style.BackColor = Color.FromArgb(201, 252, 254)
            Else
                e.Row.Cells(i).Style.Reset()
                e.Row.InvalidateRow()
            End If
        Next i
    End Sub

    Private Sub RadTextBox1_TextChanged(sender As System.Object, e As System.EventArgs) Handles RadTextBox1.TextChanged
        Me.RadGridView1.MasterTemplate.Refresh()
    End Sub
End Class

i just set enablecustomfiltering = true 

enable filtering = true 

 

 the data only 726 rows .... 

 

Thanks n best regards 

 

Hengky 

 

 

2 Answers, 1 is accepted

Sort by
0
Arun Kumar
Top achievements
Rank 2
answered on 04 Jan 2018, 09:46 AM
I have same issue after upgrading to 2017 R3
0
Dimitar
Telerik team
answered on 04 Jan 2018, 11:24 AM
Hello Henky,

It looks like you are using the custom filtering in order to highlight the text in the grid. This is already supported out of the box and will work faster because the search operation is executed on a separate thread and the highlighted text is directly painted. So is it suitable for you to use the default search functionality: Search Row.

What you can do to speed this up is to invalidate the row only once after the cell styles are set. In addition, you can enclose the update operation within a Begin/End update block. This way you will update the grid once. And instead of using the custom filtering you can use the TextChanged event of the TextBox and iterate all rows/cells. For example:
Private Sub radButton1_Click(ByVal sender As Object, ByVal e As EventArgs)
    Dim filter = radTextBox1.Text
    radGridView1.BeginUpdate()
    If filter = String.Empty Then
        For Each row As GridViewRowInfo In radGridView1.Rows
            row.IsVisible = True
            For Each cell As GridViewCellInfo In row.Cells
                cell.Style.Reset()
            Next cell
        Next row
    Else
        For Each row As GridViewRowInfo In radGridView1.Rows
            row.IsVisible = False
            For Each cell As GridViewCellInfo In row.Cells
                cell.Style.Reset()
 
                If cell.Value IsNot Nothing Then
                    Dim value = cell.Value.ToString()
                    If value.IndexOf(filter) <> -1 Then
                        row.IsVisible = True
                        cell.Style.CustomizeFill = True
                        cell.Style.DrawFill = True
                        cell.Style.BackColor = Color.Yellow
                    End If
                End If
            Next cell
        Next row
    End If
    radGridView1.EndUpdate()
End Sub

I hope this will be useful. 

Regards,
Dimitar
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
GridView
Asked by
Hengky
Top achievements
Rank 1
Veteran
Answers by
Arun Kumar
Top achievements
Rank 2
Dimitar
Telerik team
Share this question
or