Having trouble sorting data in Firebase for a web project.
I tried using orderByChild to filter the data, but now I need to also order it by date. Here's what I've attempted:
- Tried using object.values with .sort, no luck
- Attempted to use lodash with _.orderBy, resulted in an empty array
- Changed the syntax of both methods above, still unsuccessful
- Successfully ordered different data not from Firebase using lodash orderBy
Any suggestions on how to achieve this?
Desired behavior:
Expected:
Code snippet being used:
var ref2 = firebase.database().ref(sessionToken+'/users/agendas/');
ref2.orderByChild('animalUid').equalTo(codigoAnimal).on("child_added", function(snapshot) {
var dadosFiltrados = snapshot.val();
var keys = snapshot.key;
var appendAulas = $('#atendimentosTimeline');
var tdLine = "";
tdLine += '<div class="timeline__box"><div class="timeline__date"><span class="timeline__day"></span><span class="timeline__month">'+dadosFiltrados.hora+' - '+dadosFiltrados.end+'</span></div>';
var ref3 = firebase.database().ref(sessionToken+'/users/atendimento/');
ref3.orderByKey().equalTo(dadosFiltrados.idAtendimento).on("child_added", function(snapshot) {
// firebase.database().ref(sessionToken+'/users/atendimento/'+dadosFiltrados.idAtendimento).once("value", function(info){
var keyAtendimento = snapshot.key;
var dadosAtendimento = snapshot.val();
Looking to sort the data in dadosFiltrados
.