Menu
Free Trials
Table of contents

Custom sorting

Custom sorting allows you to define a specific order for displaying columns, rows or pages. It can be set using sortOrder property:

sortOrder (optional) – Array. Using this property you can set custom sorting for hierarchy members. You can specify sortOrder the following way: [“member_1”, “member_2”, etc.].

We will analyze a simple example to understand how it works. There is a report with one hierarchy defined as a row:

{
    "dataSource": {
        "filename": "http://www.flexmonster.com/download/data.csv"
    },
    "slice": {
        "rows": [
            {
                "uniqueName": "Category"
            }
        ]
    }
}

This hierarchy has the following members: “Accessories”, “Bikes”, “Clothing”, “Components”, “Cars”. To define custom sorting we add sortOrder property:

{
    "dataSource": {
        "filename": "http://www.flexmonster.com/download/data.csv"
    },
    "slice": {
        "rows": [
            {
                "uniqueName": "Category",
                "sortOrder": ["Bikes", "Cars", "Clothing", 
                    "Accessories", "Components"]
            }
        ]
    }
}

Now hierarchy members will be displayed in predefined order:

customsort

The reverse alphabetical order will sort opposite to the order defined in sortOrder property:

customsort-za

If you remove both alphabetical and reverse alphabetical sorting, hierarchy members will be displayed in the same order they came from the data source:

customsort-no-order

Custom sorting is an easy way to predefine your own order for columns, rows or pages in the slice.