Page 1 of 1

Sort the bus schedule?

Posted: Sat May 11, 2013 6:21 pm
by Bajaru

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


Sort the bus schedule?

Posted: Sat May 11, 2013 6:38 pm
by Alena Prykhodko

Hello Brian!

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


Sort the bus schedule?

Posted: Sun May 12, 2013 8:23 pm
by Bajaru

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;});


Sort the bus schedule?

Posted: Mon May 13, 2013 4:42 am
by Igor

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.


Sort the bus schedule?

Posted: Mon May 13, 2013 2:03 pm
by Bajaru

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


Sort the bus schedule?

Posted: Mon May 13, 2013 5:21 pm
by Oleg Danchenkov

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);


Sort the bus schedule?

Posted: Tue May 14, 2013 2:43 am
by Bajaru

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