Does anyone know how to filter or sort collections on Retool mobile? I dont know if its a query/code or a feature.
The collection is attached to a query. The query can be filtered with a where clause and use data from a variable in your app or you can filter using a transformer (for a javascript filter).
It's basically the same as regular retool if you don't use the filter built in to the table.
How do i Build this? Can you provide an example please?'
Here is the docs for adjusting the query Reading from SQL
Here is an example of a transformer I use in one of my apps to filter a query:
const searchTerm = {{searchReservations.value}}.toLowerCase();
const reservations = formatDataAsArray(data);
let filteredReservations;
if (!searchTerm) {
filteredReservations = reservations;
} else {
filteredReservations = reservations.filter(reservation => reservation.reservation.toLowerCase().includes(searchTerm) || reservation.reservation_number.toString().toLowerCase().includes(searchTerm));
}
ok thank you. I wish we did not have to do all this just to filter something, I will try and implement this. Thank you
Would this be the same to sort a collection as well?
Yes. Use "order by" in your query.