Nevron Open Vision Documentation

About  Sorting

Sorting is the process of sorting the rows that reside on the same hierarchical level. The grid support multiple sorting rules that define a certain sorting order of the rows that reside at the same level in the grid grouping or self-referencing level.

Sorting rules are represented by instances of the NSortingRule class that reside in a NSortingRuleCollection accessible from the NGrid.SortingRules property. In most cases you will create filter rules that are associated with grid columns - the following code example first sorts by the Name and then by the Sales column:

Multiple Sorting Rules
Copy Code
NSortingRule sortByName = new NSortingRule(grid.Columns.GetColumnByFieldName("Name"));
NSortingRule sortBySales = new NSortingRule(grid.Columns.GetColumnByFieldName("Sales"));

Sorting can be visually performed by the user in several ways:

Sorting Rule and its Row Value and Sorting Direction 

Each sorting rule has an assigned Row Value that associates each row with a specific value, by which the rule sorts the rows. The Row Value is specified by the RowValue property. Additionally each sorting rule has a sorting direction which is specified by the rule Sorting Direction property. The following code example creates a sorting rule and modifies its row value and sorting rule, so that the rule sorts the rows by the Name field in Descending order:

Sorting Rule Row Value and Sorting Direction
Copy Code
NSortingRule sortByName = new NSortingRule();
sortByName.RowValue = new NFieldRowValue("Name");
sortByName.SortingDirection = ENSortingDirection.Ascending;
Sorting Rule and the associated Column

Each sorting rule can be associated with a grid column. The associated column is specified by the NSortingRule.Column property. There are several things, which happen when a sorting rule is associated with a column:

Sorting Rules created by Columns

When the user clicks on the sorting button of a column header, the grid asks the column to create a sorting rule for that column. By default the column creates a sorting rule that sorts by the column value (i.e. a sorting rule that is simply associated with the column). You may however want to create a custom sorting rule when the user clicks on the column header sorting button. This is achieved by handling the NColumn.CreateSortingRuleDelegate delegate, like shown in the following example:

Custom sorting rules created by columns
Copy Code
column.CreateSortingRuleDelegate = delegate(NColumn theColumn)
    // create a custom sorting rule
    NSortingRule sortingRule = new NSortingRule();
    NCustomRowValue<double> customRowValue = new NCustomRowValue<double>();
    customRowValue.GetRowValueDelegate = delegate(NCustomRowValueGetRowValueArgs<double> args)
        NDataSource dataSource = args.DataSource;
        return (double)((double)dataSource[args.Row, "Price"] * (int)dataSource[args.Row, "Quantity"]);
    sortingRule.RowValue = customRowValue;
    return sortingRule;
See Also
Send Feedback