Bajaru
Posts: 0
Joined: Sat May 11, 2013 6:46 am

Sort the bus schedule?

In the tutorial project "Building a Clickable List App with HTML5 Local Storage" if I wanted to sort the RoutesService response by @tag, what might be a good way to to do it?
B2

Alena Prykhodko
Posts: 0
Joined: Tue Apr 09, 2013 7:36 am

Sort the bus schedule?

Hello Brian!

You can sort it with JavaScript.
Look here https://getsatisfaction.com/apperyio/...

Bajaru
Posts: 0
Joined: Sat May 11, 2013 6:46 am

Sort the bus schedule?

I think I'm awfully close, but I'm still missing something.
I added the JS plug-in (jQuery.fn.sortElements) and mapped the service response fields to the labels. Does the following look about right for the JS to run on success? (mobilelistitem name = mobilelistitem1_3, the hidden field name = tagID)

function compareFunc(a, b) {
var first, second;
first = $("[name=tagID]", a).text();
second = $("[name=tagID]", b).text();
return +first - (+second);
}
var $li = $("[name=mobilelistitem1_3]:gt(0)"); //:gt(0) - we don't need first element. it's used for mapping
$li.sortElements(compareFunc, function(){ return this;});

Igor
Posts: 0
Joined: Tue Apr 02, 2013 12:05 pm

Sort the bus schedule?

Hello Brian.

Do you get any errors in the console?
Please provide us a publick link to your app or share it with a href="mailto:support@appery.io" rel="nofollow"support@appery.io/a.

Bajaru
Posts: 0
Joined: Sat May 11, 2013 6:46 am

Sort the bus schedule?

Hi,
No errors are thrown but the sorting is not happening. I shared the project "Bus sched tutorial" with you.
-thanks!

Oleg Danchenkov
Posts: 0
Joined: Tue Apr 30, 2013 5:51 pm

Sort the bus schedule?

Hi Brian.
The problem is in tagID field. It has numbers and strings (for example '1BX', 'K OWL'). Try to use
return first second ? 1 : -1;
instead of
return +first - (+second);

Bajaru
Posts: 0
Joined: Sat May 11, 2013 6:46 am

Sort the bus schedule?

That works. Thank you so much! (Now... to figure out exactly how it works. I'm still learning JS...)

Return to “Issues”