Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

firebaseArray descending order?

Using firebaseArray, is it possible to order by a specified child key: (https://www.firebase.com/docs/web/guide/retrieving-data.html#section-queries)?

var fireRef = new Firebase(https://dinosaur-facts.firebaseio.com/dinosaurs);
var query = fireRef.orderByChild("echo").limitToFirst(25);
var todos = $firebaseArray(query);

However, by default, Firebase retrieves the keys in ascending order.

Children with a numeric value come next, sorted in ascending order.

Is there any way to get results in the descending order directly from firebaseArray? For example, do they have anything like .reverse() or .orderBy(desc, ...)?

like image 753
Sung Kim Avatar asked Jul 08 '15 01:07

Sung Kim


1 Answers

This doesn't directly answer the original question, but for anyone using FirebaseUI Java/Android, with a RecyclerView, it's possible to order the RecyclerView in reverse, rather than using a query on Firebase:

Example:

LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
layoutManager.setReverseLayout(true);
layoutManager.setStackFromEnd(true);
recyclerView.setLayoutManager(layoutManager)

(Ensuring you set both before adding the layout manager to the RecyclerView also)

Github issue: https://github.com/firebase/FirebaseUI-Android/issues/90#issuecomment-230643303

like image 70
Alan Avatar answered Nov 07 '22 07:11

Alan