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 NextEnd 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.