Order By is used to sort the data in ascending or descending order, based on any column.

Sql

Select * from Table_Name Order by column_name sort_type;

JsStore

var results = await connection.select({
    from: "Table_Name",
    order: {
        by: column_name,
        type: sort_type //supprted sort type is - asc,desc
    }
});
//results will be array of objects.
console.log(results);

Option order has following properties -

  • by: string; // sorting column name

  • type: string; // sorting type - asc/desc, default is asc

  • idbSorting: boolean // whether to do sorting by indexeddb or by jsstore, default - true

Example

Order by multiple column


For ordering by multiple column - you need to provide all order object value in an array

var results = await connection.select({
    from: "Table_Name",
    order: [{
        by: column_name1,
        type: sort_type //supprted sort type is - asc,desc
    },
    {
        by: column_name2,
        type: sort_type //supprted sort type is - asc,desc
    }]
});
//results will be array of objects.
console.log(results);

Example

Order by when using join


Unlike query without join, order here is little different. You need to provide query along with table name in the form of [tablename].[columnName]

e.g -

select({
    from: "Student",
    join: {
        with: "StudentDetail",
        on: "Student.Name=StudentDetail.Name"
    },
    order: { by: 'Student.Order', type: 'asc' }
})

Example