SapphireDb logo SapphireDb

Order data - OrderBy/ThenOrderBy prefilter

You can use the orderBy-prefilter to change the ordering of the data the server returns.
Pass the property name you want to sort by.

In this example the values are sorted by content. The first example is in ascending order, the second in descending order.

\f:(typescript:demo.component.ts) export class DemoComponent implements OnInit {\n \tvalues$: Observable<Entry[]>;\n \tvalues2$: Observable<Entry[]>;\n\n \tconstructor(private db: SapphireDb) { }\n\n \tngOnInit() {\n \t\tthis.values$ = this.db.collection<Entry>('entries')\n \t\t\t.orderBy('content', SortDirection.ascending)\n \t\t\t.values();\n\n \t\tthis.values2$ = this.db.collection<Entry>('entries')\n \t\t\t.orderBy('content', SortDirection.descending)\n \t\t\t.values();\n \t}\n }
null

null
The second parameter of the method is used to define the direction of sorting. If false the values are sorted in ascending order, if true in descending order.
If you want to sort by more than one object use thenOrderBy for following sorting statements.
Continue with limit prefilters

This website uses Google Analytics. If you want to disable it just unselect the option: