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

Filtering and Sorting On Custom Column Type

1 Answer 97 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Muds
Top achievements
Rank 1
Muds asked on 28 Jan 2015, 04:12 PM
Hi All

We needed a row number column in our radGridView hence we followed a suggestion wherein we create a custom column type like this --

Public Class RowNumberColumn
    Inherits Telerik.Windows.Controls.GridViewDataColumn

    Public Overrides Function CreateCellElement(ByVal cell As GridViewCell, ByVal dataItem As Object) As FrameworkElement
        MyBase.CreateCellElement(cell, dataItem)

        Dim col = cell.Column
        Dim textBlock1 As TextBlock = cell.Content

        If (textBlock1 Is Nothing) Then
            textBlock1 = New TextBlock()
        End If

        Dim t As IList = DataControl.ItemsSource
        textBlock1.Text = (t.IndexOf(dataItem) + 1).ToString()
 
       Return textBlock1
    End Function
End Class


And then use this new column as --

        <reservingUi:RowNumberColumn Header="#" IsFilterable="True" IsSortable="True"/>



Can you please advise on how to enable column filtering and sorting based on the value in the textBlock ?

Thanks !

1 Answer, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 29 Jan 2015, 01:14 PM
Hello Mudit,

Only columns that are data bound can be filtered/sorted/grouped. You will need to expose a property in your business object that holds the information about the index of the item. Then you can bind the column directly to that property and you will be able to do data operations on it. Still, please keep in mind that you will need to synchronize that property when sorting/filtering is applied.


Regards,
Maya
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
GridView
Asked by
Muds
Top achievements
Rank 1
Answers by
Maya
Telerik team
Share this question
or