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

How to prevent paging from counting 'hidden' rows in RadGrid?

2 Answers 135 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Clayton
Top achievements
Rank 1
Clayton asked on 22 Jul 2010, 03:55 AM

Take the following (simple) datasource for a grid:

Restaurant    Food

------------------------

joe's pizza       pizza

taco bell          salad

mcdonalds      burger

mcdonalds      salad

taco bell          tacos

 

Now, I want each restaurant to display only once in a radgrid with only a single column (restaurant name), but I also want to programatically filter on 'food'. I've written a simple function to go through every row in a radgrid and 'hide' rows that have duplicate entries for the 'restaurant' column:

Public Sub RemoveDuplicateGridRows(ByVal grid As Telerik.Web.UI.RadGrid, ByVal columnIndex As String)
 
    'Array of column items to compare against for duplicates
    Dim aColumns As New ArrayList
    Dim value As String
 
    Dim gridRows As GridDataItemCollection = grid.MasterTableView.Items
    For Each row As GridDataItem In gridRows
        value = row.Cells(columnIndex).Text
        If Not aColumns.Contains(value) Then
            aColumns.Add(value)
        Else
            row.Visible = False
        End If
    Next
End Sub

This function works perfectly. The issue is that the paging feature on the RadGrid will still count the 'hidden' rows (where row.visible=false) when it generates the 'pager'. For example, if the paging is set to 10 items, but on page1 there are 4 rows 'hidden', it will only show 6 rows on the page. The 'alternating' line theme gets all messed up as well.

I've attached a screenshot of what the end result looks like. Completely removing the rows altogether is not an option, since I would not be able to get the desired result if i applied a filter for 'salad' and the 'mcdonalds' entry had been deleted since it was the 2nd 'mcdonalds' row.

2 Answers, 1 is accepted

Sort by
0
Clayton
Top achievements
Rank 1
answered on 22 Jul 2010, 03:59 AM
And here is a screenshot showing 'page 2' with the alternating row theme not working correctly since it was applied before the rows were hidden.

It's also worth noting that my function to hide duplicate rows is called during the DataBound event of the grid.
0
Clayton
Top achievements
Rank 1
answered on 22 Jul 2010, 04:08 PM

Since I could not locate any information on re-generating the paging stuff AFTER data has already been bound to a RadGrid, here is my quick and dirty fix:

1) Use sqldatasource that I was populating grid with to populate a datatable

2) apply the custom filter (I had generated for the RadGrid) to the datatable

3) modify my function from earlier post to weed out duplicate rows from a datatable

4) remove datasourceID from RadGrid, and on NeedsDatasource event, set datasource to the datatable

It now requires more code than I would have wanted, but it gets the job done. If anyone has any better suggestions, please let me know. If not, I hope this post was at least helpful to the one other person in the world who might be trying to do what I did :)

Tags
Grid
Asked by
Clayton
Top achievements
Rank 1
Answers by
Clayton
Top achievements
Rank 1
Share this question
or