useSortBy()

Sorts the collection by a given key


Usage

import { useRepo } from 'pinia-orm'import { useSortBy } from 'pinia-orm/dist/helpers'import User from './models/User'const users = useRepo(User).all()// sort by the 'name' attributeuseSortBy(users, 'name')// sorts the collection by 'name' descending and then by 'lastname' ascendinguseSortBy(users, [    ['name', 'desc'],    ['lastname', 'asc'],])// sort by the 'age' attributeuseSortBy(users, (model) => model.age)

Type Declaration

export type sorting<T> = ((record: T) => any) | string | [string, 'asc' | 'desc'][]export function useSortBy<T>(collection: T[], sort: sorting<T>): T[]