Sorting in Mobile app

Home for older / inactive topics

Sorting in Mobile app

Postby vincentc » Mon Feb 11, 2013 11:38 am

Hello,

Lists on mobile side are sorted by table Ids (by default). Is there a way to change the field on which I would like to sort ?

By example, I would like to sort the companies list by company_name asc but it seems to not work in mobile.

Thank you.
vincentc
 
Posts: 56
Joined: Thu Aug 25, 2011 11:12 am

Re: Sorting in Mobile app

Postby patrick » Mon Feb 11, 2013 12:30 pm

On mobile you don't have a real database that understands a SQL "Order By" clause. You can sort the foundset by using a sort function. Something like

Code: Select all
function fsSort(record1, record2) {
   var result = 0;
   if (record1.company_name > record2.company_name) {
      result = 1;
   } else if (record1.company_name < record2.company_name) {
      result = -1;
   }
   return result;
}

fs.sort(fsSort);
Patrick Ruhsert
Servoy DACH
patrick
 
Posts: 3703
Joined: Wed Jun 11, 2003 10:33 am
Location: Munich, Germany

Re: Sorting in Mobile app

Postby vincentc » Mon Feb 11, 2013 4:56 pm

Hello patrick,

Thank you very much for your answer.

This solution doesn't work for me, but I think this is because my Mobile form is based on the "entites" table. To access my field, I have to write "entites_to_companies.company_name".

And I think that this method of sorting doesn't work with related fields, right ?
vincentc
 
Posts: 56
Joined: Thu Aug 25, 2011 11:12 am

Re: Sorting in Mobile app

Postby patrick » Mon Feb 11, 2013 7:06 pm

Why shouldn't this work:

var record = foundset.getSelectedRecord(); // your entity
var fs = record.entites_to_companies; // the foundset you want to sort

fs.sort(fsSort);
Patrick Ruhsert
Servoy DACH
patrick
 
Posts: 3703
Joined: Wed Jun 11, 2003 10:33 am
Location: Munich, Germany

Re: Sorting in Mobile app

Postby vincentc » Mon Feb 18, 2013 11:02 am

We have to do this on the mobile side ? Sorry, I can not make it work :(
vincentc
 
Posts: 56
Joined: Thu Aug 25, 2011 11:12 am

Re: Sorting in Mobile app

Postby patrick » Mon Feb 18, 2013 1:38 pm

Can you show the code that you are using now?
Patrick Ruhsert
Servoy DACH
patrick
 
Posts: 3703
Joined: Wed Jun 11, 2003 10:33 am
Location: Munich, Germany

Re: Sorting in Mobile app

Postby vincentc » Thu Feb 21, 2013 4:02 pm

I don't use relation anymore, but just a table companies, so in theory it is very simple. I use the code that you gave me first. the field's name is "comp_name", so in my mobile side I have :

Code: Select all
function fsSort(record1, record2) {
   var result = 0;
   if (record1.comp_name > record2.comp_name) {
      result = 1;
   } else if (record1.comp_name < record2.comp_name) {
      result = -1;
   }
   return result;
}

and in my onShow() method :
fs.sort(fsSort);
vincentc
 
Posts: 56
Joined: Thu Aug 25, 2011 11:12 am

Re: Sorting in Mobile app

Postby patrick » Thu Feb 21, 2013 11:24 pm

hm. Not sure if that is too late. What if you do this outside of the form you want to show sorted and then say forms.xy.controller.showRecord(sortedFs) to show it?
Patrick Ruhsert
Servoy DACH
patrick
 
Posts: 3703
Joined: Wed Jun 11, 2003 10:33 am
Location: Munich, Germany

Re: Sorting in Mobile app

Postby vincentc » Tue Mar 05, 2013 10:39 am

I don't success to make it work ... "The property controller is private".

Nobody else has a solution ?

I think I will wait the final version of Servoy 7 to try again. Thank you so much for your answers.
vincentc
 
Posts: 56
Joined: Thu Aug 25, 2011 11:12 am

Re: Sorting in Mobile app

Postby jcompagner » Tue Mar 05, 2013 11:32 am

that means that you accessed the "controller" property of a form that has that controller encapsulated (see the forms properties)
You can change this to public

But where did you access the controller property in this sort problem?
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8828
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: Sorting in Mobile app

Postby vincentc » Tue Mar 05, 2013 12:20 pm

Ok I changed the encapsultation but it doesn't work. The problem is that I need to make a sort on the FirstForm of my solution (companies). In this case, where it is better to call the forms.companies.controller.showRecord(sortedFs)

Johan, for you, is it possible to sort a list in a Mobile app ? if yes, how ?
vincentc
 
Posts: 56
Joined: Thu Aug 25, 2011 11:12 am

Re: Sorting in Mobile app

Postby jcompagner » Tue Mar 05, 2013 2:51 pm

that should all just work
in companies:

foundset.sort(mysortfunction)

that should sort and display the order in a form. If you have a solution where you don't see that, create a case with that solution.

ofcourse

var justafoundset = xxxxx;
justafoundset.sorT(mysortfunction)
controller.showRecords(justafoundset)

should also just work
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8828
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: Sorting in Mobile app

Postby jgarfield » Tue Mar 05, 2013 6:21 pm

Sorting a foundset via a function seems cool, but is something I haven't heard of before... Is this Mobile only, or can we do this anywhere?
Programmer.
adBlocks
http://www.adblocks.com
jgarfield
 
Posts: 223
Joined: Wed Sep 28, 2005 9:02 pm
Location: Boston, US

Re: Sorting in Mobile app

Postby Joas » Tue Mar 05, 2013 6:38 pm

jgarfield wrote:Sorting a foundset via a function seems cool, but is something I haven't heard of before... Is this Mobile only, or can we do this anywhere?

That can be done anywhere, check the sample code for JSFoundset.sort(function).
I think this is possible since 6.0.
Joas de Haan
Yield Software Development
Need help on your project? yieldsd.com
User avatar
Joas
Site Admin
 
Posts: 842
Joined: Mon Mar 20, 2006 4:07 pm
Location: Leusden, NL

Re: Sorting in Mobile app

Postby vincentc » Tue Mar 05, 2013 6:52 pm

Finally, I understood why it didn't work !
Sage CRM add some space characters (" ") in the field values of the database ... That is why the sorting wasn't working. I had to trim the values in the ws_read, and now it works like a charm.
Thank you for your answers !
vincentc
 
Posts: 56
Joined: Thu Aug 25, 2011 11:12 am

Next

Return to Archive

Who is online

Users browsing this forum: No registered users and 1 guest

cron