How to: Filter Top or Bottom Ranked Values
- 2 min to read
This example demonstrates how to display the top/bottom ranked values using the "Top 10" filter.
- Turn on the filtering functionality for the required range, as described in the How to: Enable Filtering example.
- Use the AutoFilterBase.Columns property of the SheetAutoFilter object to get a collection of columns in the filtered range (the AutoFilterColumnCollection object). Each column in the collection is defined by the AutoFilterColumn object which provides basic methods for data filtering. To filter data in a particular column, get access to this column by its index in the AutoFilterColumnCollection collection.
Call the AutoFilterColumn.ApplyTop10Filter and pass the following parameters.
- A filter operator specified by one of the Top10Type enumeration members.
- A positive integer that defines the number or percentage value to filter by.
A complete sample project is available at https://github.com/DevExpress-Examples/spreadsheet-document-server-api-part-2-t217615
Worksheet worksheet = workbook.Worksheets["Regional sales"]; workbook.Worksheets.ActiveWorksheet = worksheet; // Enable filtering for the specified cell range. CellRange range = worksheet["B2:E23"]; worksheet.AutoFilter.Apply(range); // Apply a filter to the "Sales" column to display the top ten values. worksheet.AutoFilter.Columns.ApplyTop10Filter(Top10Type.Top10Items, 10);