By default, the store returns entities in the order in which they arrived from the server. The entities you add are pushed to the end of the collection. You may prefer getting the entities from the store in some other order. You can provide a sortBy option which could be based on an entity key or a comparer function.

Akita will keep the collection in the order prescribed by your key or comparer. You can set it once for the entire Query:

import { QueryConfig, Order } from '@datorama/akita';
sortBy: 'price',
sortByOrder: Order.ASC
export class ProductsQuery extends QueryEntity<ProductsState> {
constructor(protected store: ProductsStore) {

Or you can set it per selectAll():

const products$ = sortControl.valueChanges.pipe(
switchMap((sortBy) => productsQuery.selectAll({

The query sortBy function also passes the whole state as the third argument, give you the ability to return a different sortBy function based on your current state. For example:

const sortBy = (a, b, state) => (
state.sortyByPrice ?
sortByPrice(a, b) :
sortById(a, b)
// With QueryConfig
@QueryConfig({ sortBy })
// With selectAll
queryTodos.selectAll({ sortBy });