Leaderboard - How do I sort the fccusers/top/recent api in the $.get call?

Leaderboard - How do I sort the fccusers/top/recent api in the $.get call?
0

#1

My codepen is here.

Check out line 40. Why is this not working?


#2

You can add if ... else statement to your render method.

if (this.state.sort == 'desc') {
// render descending
} else {
//render ascending
}

Roughly like this:

http://codepen.io/jenovs/pen/rrZVOy?editors=0010


#3

Yes that works to change the sorting of the scores over the last 30 days from ascend to descend and vice versa. However, what if I wanted to sort the top 30 api data by the “alltime” field?

Thanks!


#4

Actually you don’t need sorting - you should make two API calls:

if you click on “Score in Last 30 Days” you make an API call to https://fcctop100.herokuapp.com/api/fccusers/top/recent

if you click on “Overall Score” you call https://fcctop100.herokuapp.com/api/fccusers/top/alltime

And then you just show the result without sorting.

At least that’s the way it works in the example project (and that’s the way I did in my project).


#5

The requirements state “toggle between sorting the list between points THEY’VE earned the last 30 days and points THEY’VE earned total” so that is what I want to do in my solution. Everyone else’s solution is to toggle between “the top 30” and the"top 100". That’s potentially two completely separate sets of data! I want to stick with just one set of campers, and sort them two different ways, either by their points over the last 30 days or their overall points.


#6

Ok, now I understand what you want to accomplish.

To sort by “Overall Score”, you can first sort the original array by ‘alltime’ field (currently it is sorted by recent, and then call the render method).

Actually you need separate sorting function which you’ll call before the rendering function to sort by alltime or recent).

Maybe later I’ll try to write some code to check my idea.


#7

Oh my THAT’S IT!!!
I’ve been staring at this code for so long I just wasn’t seeing it!
Thanks!!!


#8

Ok check out the updated version.

Thanks again!