Page 1 of 1
Sort listimtems not working
Posted: Tue Dec 17, 2013 5:10 pm
by avdhooft
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
Sort listimtems not working
Posted: Tue Dec 17, 2013 5:51 pm
by Kateryna Grynko
Hi Sander,
You use codepre$("[name=mobilelistitem]:gt(0)");/preWhile your mobilelist is named 'mobilelistitem_28'.
Sort listimtems not working
Posted: Tue Dec 17, 2013 5:56 pm
by avdhooft
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.
Sort listimtems not working
Posted: Wed Dec 18, 2013 7:27 am
by Maryna Brodina
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)"); //:gt(0) - we don't need first element. it's used for mapping
$li.sortElements(compareFunc, function(){ return this;});/pre
Sort listimtems not working
Posted: Wed Dec 18, 2013 8:37 am
by avdhooft
That was the trick. Thanks.
I used:
code
function compareFunc(a, b)
{
var first, second;
first = $("[name=v]", a).text();
second = $("[name=v]", b).text();
return first > second ? 1 : -1;
}
var $li = $("[name=mobilelistitem]:gt(0)"); //:gt(0) - we don't need first element. it's used for mapping
$li.sortElements(compareFunc, function(){ return this; });
/code
Sort listimtems not working
Posted: Wed Dec 18, 2013 8:46 am
by avdhooft
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.
I found an other post where a solution is given: https://getsatisfaction.com/apperyio/...
I tried adding the following code:
code
$t.refreshScreenFormElements($.mobile.activePage.prop('id'));
Appery("mobilelistitem").find("li").eq(0).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...
Sort listimtems not working
Posted: Wed Dec 18, 2013 12:30 pm
by Maryna Brodina
Try pre$t.refreshScreenFormElements($.mobile.activePage.prop('id'));
Appery("mobilelistName").find("li").eq(0).hide();
return;/prewhere mobilelistName - List name (not item name)
Sort listimtems not working
Posted: Wed Dec 18, 2013 8:12 pm
by avdhooft
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.
Do you know the reason why?
Sort listimtems not working
Posted: Wed Dec 18, 2013 8:42 pm
by avdhooft
I have found the problem. It is due a label with html data. This "corrupts" the list structure during the sort.
Sort listimtems not working
Posted: Wed Dec 18, 2013 8:51 pm
by Kateryna Grynko
Glad it's working! Thank you for the update!