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
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);
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 ?
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 :
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);
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?
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?
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 ?
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 !