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

Question about Filtering/Sorting and Empty Rows

1 Answer 49 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Matt Travis
Top achievements
Rank 1
Matt Travis asked on 26 Sep 2008, 08:08 PM
Greetings,

I have a RadGrid that fits in a space larger than the height of the rendered grid itself and add empty rows to it to fill in the background area to make it visually look more appealing (like a spreadsheet).

I use the following bit of code to add the empty rows to the end of the data table that I use as a source of data.

 Dim remainder As Integer 
 Math.DivRem(dt.Rows.Count, GridPageSize, remainder) 
 If remainder <> 0 Then 
     For i As Integer = 1 To GridPageSize - remainder 
         dt.Rows.Add(dt.NewRow()) 
     Next 
 End If 

The GridPageSize can vary, but for this example, let's say that it is set to 30 and that I only retrieve 4 records from the database.

This serves the purpose of rendering the Grid in the following way:

Column Headers
Filter Row
4 Rows with Data
26 Empty Rows
CommandItems
Pager

When I apply a filter on the table, my empty rows are hidden.
When I sort the table by a column, my empty rows are included in the sort.

For the Filter, which functions and/or events do I have to work with to show my empty rows after the filter is applied?

For a Sort, which functions and/or events do I have to work with to temporarily remove my empty rows and add back after the sort is complete?

Thanks in advance,

Matt


1 Answer, 1 is accepted

Sort by
0
Jason
Top achievements
Rank 2
answered on 26 Sep 2008, 08:43 PM
Hi Matt,

You should be able to exclude your empty rows by hooking onto the SortCommand event of the RadGrid. I think you'll need to actually remove the empty rows from the table before you sort because technically even though the rows are empty, they represent valid sources of data. You can manipulate the sorting like so:

Protected Sub YourRadGrid_SortCommand(ByVal source As Object, _ 
                                      ByVal e As GridSortCommandEventArgs) _ 
                                      Handles YourRadGrid.SortCommand 
 
     If e.CommandArgument = "TheSortFieldThatWasClicked" Then 
          ' Do some stuff..., reapply the datasource and rebind 
          e.Item.OwnerTableView.DataSource = YourDataSource 
          e.Item.OwnerTableView.Rebind() 
     End If 
 
End Sub 

As for the filtering, you can intercept and manipulate the filter command by handling the ItemCommand event as follows:

Protected Sub YourRadGrid_ItemCommand(ByVal source As Object, _ 
                                      ByVal e As GridCommandEventArgs) _ 
                                      Handles YourRadGrid.ItemCommand 
 
     If e.CommandName = RadGrid.FilterCommandName Then 
         ' Do whatever you want here... 
     End If 
 
End Sub 
Tags
Grid
Asked by
Matt Travis
Top achievements
Rank 1
Answers by
Jason
Top achievements
Rank 2
Share this question
or