DataEngine for .NET Standard | ComponentOne
Work with Data Engine / Transform Data / Sort
In This Topic
    Sort
    In This Topic

    The Sort transformation arranges the input data in ascending or descending order. The DataEngine library allows you to sort Base Tables (data engine tables which contain the imported data) and the query result tables (result of a query) easily.

    The first step to sort a base table or a query result table is to retrieve its collection of rows using the GetTableData method or GetQueryData methods of the Workspace class respectively. These methods return an instance of the IDataList interface.

    Once the data of the base table or query result table is retrieved, you can easily sort it using the Sort method of the DataList class. The Sort method accepts the following three parameters: the collection of rows (which is an instance of the IDataList interface), name of the column to sort and the sort direction (true for ascending and false for descending).

    The following example demonstrates how the query result table ‘SalesByCategory’ can be sorted in descending order by the column ‘Sales’.

    // Output query results in CSV format to the console
    IDataList sales = workspace.GetQueryData("SalesByCountry");
    DataList.Sort(sales, "Sales", false); // Sort by Sales value in descending order