Spread for ASP.NET 8.0 Product Documentation > Developer's Guide > Customizing User Interaction > Managing Filtering of Rows of User Data > Creating Filtered Rows and Setting the Appearance |
You can customize the appearance of filtered rows to allow you to see which rows are filtered in and which ones are filtered out. Rows that meet the criteria for the row filter are said to be "filtered in"; rows that do not meet the criteria are said to be "filtered out." Filtering may either hide the rows that are filtered out, or change the styles such as the background color for both filtered-in and filtered-out rows. If you want the styles to change, so that you can continue to display all the data but highlight rows that match some criteria, then you must define a filtered-in style and a filtered-out style.
Hidden rows are not displayed even if they match the filter criteria.
A row filter uses a style row filter or a hide row filter. The style row filter changes the appearance of the filtered row. The hide row filter hides the rows that do not meet the filter criteria.
You define styles by creating NamedStyle objects that contain all the style settings. Then when the row filtering is applied to a column, you specify those defined style settings by referring to the NamedStyle object for that filtered state. For more information about the row filter that uses styles, refer to the StyleRowFilter class.
You can create a hide or style row filter using the Spread Designer. Select the Spread control in the property grid drop-down of the designer, then select the Sheets Collection (under Data), and then select the Row Filter option in the SheetView Collection editor.
In addition to creating row filters for the user to select the item; you can also programmatically filter a row.
You can specify simple filtering, enhanced filtering, or the filter bar with the AutoFilterMode property.
For detailed information on the objects involved, refer to these classes.
Create a named style and then set the style row filter.
This example code sets a style row filter.
C# |
Copy Code
|
---|---|
FarPoint.Web.Spread.NamedStyle instyle = new FarPoint.Web.Spread.NamedStyle(); FarPoint.Web.Spread.NamedStyle outstyle = new FarPoint.Web.Spread.NamedStyle(); instyle.BackColor = Color.Yellow; outstyle.BackColor = Color.Aquamarine; FarPoint.Web.Spread.FilterColumnDefinition fcd = new FarPoint.Web.Spread.FilterColumnDefinition(1, FarPoint.Web.Spread.FilterListBehavior.SortByMostOccurrences | FarPoint.Web.Spread.FilterListBehavior.Default); FarPoint.Web.Spread.FilterColumnDefinition fcd1 = new FarPoint.Web.Spread.FilterColumnDefinition(2); FarPoint.Web.Spread.FilterColumnDefinition fcd2 = new FarPoint.Web.Spread.FilterColumnDefinition(); FarPoint.Web.Spread.StyleRowFilter sf = new FarPoint.Web.Spread.StyleRowFilter(FpSpread1.Sheets[0], instyle, outstyle); sf.AddColumn(fcd); sf.AddColumn(fcd1); sf.AddColumn(fcd2); FpSpread1.Sheets[0].RowFilter = sf; |
VB |
Copy Code
|
---|---|
Dim instyle As New FarPoint.Web.Spread.NamedStyle() Dim outstyle As New FarPoint.Web.Spread.NamedStyle() instyle.BackColor = Color.Yellow outstyle.BackColor = Color.Aquamarine Dim fcd As New FarPoint.Web.Spread.FilterColumnDefinition(1, FarPoint.Web.Spread.FilterListBehavior.SortByMostOccurrences Or FarPoint.Web.Spread.FilterListBehavior.Default) Dim fcd1 As New FarPoint.Web.Spread.FilterColumnDefinition(2) Dim fcd2 As New FarPoint.Web.Spread.FilterColumnDefinition() Dim sf As New FarPoint.Web.Spread.StyleRowFilter(FpSpread1.Sheets(0), instyle, outstyle) sf.AddColumn(fcd) sf.AddColumn(fcd1) sf.AddColumn(fcd2) FpSpread1.Sheets(0).RowFilter = sf |
Create a column filter definition and set a hide row filter.
This example code uses the hide row filter.
C# |
Copy Code
|
---|---|
FarPoint.Web.Spread.FilterColumnDefinition fcd = new FarPoint.Web.Spread.FilterColumnDefinition(1, FarPoint.Web.Spread.FilterListBehavior.SortByMostOccurrences | FarPoint.Web.Spread.FilterListBehavior.Default); FarPoint.Web.Spread.FilterColumnDefinition fcd1 = new FarPoint.Web.Spread.FilterColumnDefinition(2, FarPoint.Web.Spread.FilterListBehavior.Default); FarPoint.Web.Spread.FilterColumnDefinition fcd2 = new FarPoint.Web.Spread.FilterColumnDefinition(3); FarPoint.Web.Spread.HideRowFilter hf = new FarPoint.Web.Spread.HideRowFilter(FpSpread1.Sheets[0]); hf.AddColumn(fcd); hf.AddColumn(fcd1); hf.AddColumn(fcd2); FpSpread1.Sheets[0].RowFilter = hf; |
VB |
Copy Code
|
---|---|
Dim fcd As New FarPoint.Web.Spread.FilterColumnDefinition(1, FarPoint.Web.Spread.FilterListBehavior.SortByMostOccurrences Or FarPoint.Web.Spread.FilterListBehavior.Default) Dim fcd1 As New FarPoint.Web.Spread.FilterColumnDefinition(2) Dim fcd2 As New FarPoint.Web.Spread.FilterColumnDefinition(3) Dim hf As New FarPoint.Web.Spread.HideRowFilter(FpSpread1.Sheets(0)) hf.AddColumn(fcd) hf.AddColumn(fcd1) hf.AddColumn(fcd2) FpSpread1.Sheets(0).RowFilter = hf |
Create a column filter definition and set a row filter.
This example applies a filter programmatically with the AutoFilterColumn method.
C# |
Copy Code
|
---|---|
FpSpread1.Sheets[0].Cells[0, 2].Text = "test"; FarPoint.Web.Spread.NamedStyle instyle = new FarPoint.Web.Spread.NamedStyle(); FarPoint.Web.Spread.NamedStyle outstyle = new FarPoint.Web.Spread.NamedStyle(); instyle.BackColor = Color.Yellow; outstyle.BackColor = Color.Aquamarine; FarPoint.Web.Spread.FilterColumnDefinition fcd = new FarPoint.Web.Spread.FilterColumnDefinition(1, FarPoint.Web.Spread.FilterListBehavior.SortByMostOccurrences | FarPoint.Web.Spread.FilterListBehavior.Default); FarPoint.Web.Spread.FilterColumnDefinition fcd1 = new FarPoint.Web.Spread.FilterColumnDefinition(2); FarPoint.Web.Spread.FilterColumnDefinition fcd2 = new FarPoint.Web.Spread.FilterColumnDefinition(); FarPoint.Web.Spread.StyleRowFilter sf = new FarPoint.Web.Spread.StyleRowFilter(FpSpread1.Sheets[0], instyle, outstyle); sf.AddColumn(fcd); sf.AddColumn(fcd1); sf.AddColumn(fcd2); FpSpread1.Sheets[0].RowFilter = sf; FpSpread1.Sheets[0].AutoFilterColumn(2, "test"); |
VB |
Copy Code
|
---|---|
FpSpread1.Sheets(0).Cells(0, 2).Text = "test" Dim instyle As New FarPoint.Web.Spread.NamedStyle() Dim outstyle As New FarPoint.Web.Spread.NamedStyle() instyle.BackColor = Color.Yellow outstyle.BackColor = Color.Aquamarine Dim fcd As New FarPoint.Web.Spread.FilterColumnDefinition(1, FarPoint.Web.Spread.FilterListBehavior.SortByMostOccurrences Or FarPoint.Web.Spread.FilterListBehavior.Default) Dim fcd1 As New FarPoint.Web.Spread.FilterColumnDefinition(2) Dim fcd2 As New FarPoint.Web.Spread.FilterColumnDefinition() Dim sf As New FarPoint.Web.Spread.StyleRowFilter(FpSpread1.Sheets(0), instyle, outstyle) sf.AddColumn(fcd) sf.AddColumn(fcd1) sf.AddColumn(fcd2) FpSpread1.Sheets(0).RowFilter = sf FpSpread1.Sheets(0).AutoFilterColumn(2, "test") |