avdhooft
Posts: 0
Joined: Tue Dec 17, 2013 5:10 pm

Sort listimtems not working

I try to sort the items returned from a service and show them in a list.
I used the example from https://getsatisfaction.com/apperyio/...
But I can not get it working.
I shared the app with a href="mailto:support@appery.io" rel="nofollow"support@appery.io/a.

Thanks,

Sander Image

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Sort listimtems not working

Hi Sander,

You use codepre$("[name=mobilelistitem]:gt(0)");/preWhile your mobilelist is named 'mobilelistitem_28'.

avdhooft
Posts: 0
Joined: Tue Dec 17, 2013 5:10 pm

Sort listimtems not working

I changed the name (I tried that earlier as well). But still it does not sort the list.
There must be something else I do wrong.

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Sort listimtems not working

Hello! In example there is a comparison of numeral values, not strings. Please try the following code.prefunction compareFunc(a, b)
{
var first, second;
first = $("[name=v]", a).text().toLowerCase();
second = $("[name=v]", b).text().toLowerCase();
console.log("["+first+"|"+second+"]");
if (first < second){
return -1;
}else if (first second){
return 1;
}else{
return 0;
}
}
var $li = $("[name=mobilelistitem]:gt(0)"); &#47;&#47;:gt(0) - we don't need first element&#46; it's used for mapping
$li&#46;sortElements(compareFunc, function(){ return this;});/pre

avdhooft
Posts: 0
Joined: Tue Dec 17, 2013 5:10 pm

Sort listimtems not working

That was the trick. Thanks.
I used:

code
function compareFunc(a, b)
{
var first, second;
first = $("[name=v]", a)&#46;text();
second = $("[name=v]", b)&#46;text();
return first > second ? 1 : -1;
}

var $li = $("[name=mobilelistitem]:gt(0)"); &#47;&#47;:gt(0) - we don't need first element&#46; it's used for mapping
$li&#46;sortElements(compareFunc, function(){ return this; });

/code

avdhooft
Posts: 0
Joined: Tue Dec 17, 2013 5:10 pm

Sort listimtems not working

Now I have one other thing left.
The first autodiver on top of the list should not be there. In this case it is an L. But there is already an L further in the list.
Image
I found an other post where a solution is given: https://getsatisfaction.com/apperyio/...

I tried adding the following code:
code
$t&#46;refreshScreenFormElements($&#46;mobile&#46;activePage&#46;prop('id'));
Appery("mobilelistitem")&#46;find("li")&#46;eq(0)&#46;hide();
return;
/code
I added it on "service complete" with order 2 so it's started after the code that sorts the list. But this does not work...

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Sort listimtems not working

Try pre$t&#46;refreshScreenFormElements($&#46;mobile&#46;activePage&#46;prop('id'));
Appery("mobilelistName")&#46;find("li")&#46;eq(0)&#46;hide();
return;/prewhere mobilelistName - List name (not item name)

avdhooft
Posts: 0
Joined: Tue Dec 17, 2013 5:10 pm

Sort listimtems not working

That worked!
Thanks again.

There is however a strange problem (not releated to the previous issue) which results in multiple autodividers for the same letter.
Image

Do you know the reason why?

avdhooft
Posts: 0
Joined: Tue Dec 17, 2013 5:10 pm

Sort listimtems not working

I have found the problem. It is due a label with html data. This "corrupts" the list structure during the sort.

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Sort listimtems not working

Glad it's working! Thank you for the update!

Return to “Issues”