Filtering is the process of passing only certain records from the data source to be displayed by the grid. The filtering is the first data processing step performed by both the Table Grid and the Tree Grid. The filtering of a grid is defined by a collection of NFilteringRule instances that are contained inside the NFilteringRuleCollection collection accessible from the NGrid.FilterRules property.
Each NFilteringRule defines a predicate (i.e. a function that evaluates to true or false). In order for a record from the data source to be displayed by the grid, the record must pass all filtering rules - i.e. for that record all filter predicates must return true. The filtering rule predicate is specified by a Row Condition.
Each NFilteringRule can be optionally associated with a grid column. This is achieved by setting the NFilteringRule.Column property to reference the column that you want to associate with the rule. When a filter rule is associated with a column, by default that column serves as a row value provider for the row condition that the filtering rule aggregates.
The following code example creates two filtering rules:
Filter Rules Example |
Copy Code
|
---|---|
// create a view and get its grid NTableGridView tableView = new NTableGridView(); NTableGrid tableGrid = tableView.Grid; // bind to data source NMemoryDataTable dataTable = new NMemoryDataTable(new NFieldInfo("Price", typeof(double)), new NFieldInfo("Quantity", typeof(int))); dataTable.AddRow(20.0d, 4); dataTable.AddRow(30.0d, 5); dataTable.AddRow(40.0d, 5); tableGrid.DataSource = new NDataSource(dataTable); // create a filter rule that only passes records for which the value of the Price is greater than 25 tableGrid.FilteringRules.Add(new NFilteringRule(tableGrid.Columns.GetColumnByFieldName("Price"), ENRowConditionOperator.GreaterThan, "25")); // create a filter rule that only passes records for which the value of the Price is less than 25 tableGrid.FilteringRules.Add(new NFilteringRule(tableGrid.Columns.GetColumnByFieldName("Price"), ENRowConditionOperator.LessThan, "35")); |