Ellen Schlechter
Posts: 0
Joined: Sun Aug 31, 2014 3:28 am

How can I sort by different things depending on which select menu option is clicked?

I have a select menu that is populated with different options on how to sort. It is just the basics like "A to Z", "Z to A", "Date", and "Weight". (Weight is just a number value)

When a user selects one of the values, I want it to sort based on what is selected.

This is what the menu looks like. Image

I read over the article"Working with the database API". I use a query service to show certain items in the database. How can I make this work?? This is what I got out of the article but I don't see how this could work. Image

Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

How can I sort by different things depending on which select menu option is clicked?

Hi Ellen -

Here is the basic approach is described, in the 'Building a dynamic select menu' part - hoping it would helps:
http://devcenter.appery.io/documentat...

Ellen Schlechter
Posts: 0
Joined: Sun Aug 31, 2014 3:28 am

How can I sort by different things depending on which select menu option is clicked?

So this is the code they gave as an example but I still don't know exactly how to make the changes that I need to sort depending on value selected.

var selectedValue = this.value;
var data = { 'Fruits': ['Orange', 'Apple', 'Banana'],
'Vegetables': ['Onion', 'Carrot', 'Tomato']
};

var dropDown = $('[name=list2]');
dropDown.html('');
var newData = data[selectedValue];
for(i = 0; i < newData.length; i++) {
dropDown.append('​' + newData + '');
}
dropDown.selectmenu('refresh');

Bruce Stuart
Posts: 0
Joined: Fri Oct 24, 2014 4:42 am

How can I sort by different things depending on which select menu option is clicked?

Hi Ellen,

Not sure if this is where your question is headed ... But....

If you've read this:

http://devcenter.appery.io/documentat...

Which is specifically about sorting, you'd have a parameter in the screen Print you called sort and then in the 'value' side you would either statically in the definition of the service have the field you want to sort on ( on the right side ). Or dynamically via JavaScript or in the service mapping before execution.

Also of note your example above, where you say A-z and Z-a , implies on at least one field you want to use the - sign to represent descending vs ascending...

In terms of implementing the service you could do that upon value change for your drop down, and when a value is selected , you could in JavaScript assign the drop down value to a local storage variable that is used in the mapping of your service ...

Make sense or would you like to see a working example ?

Bruce

Ellen Schlechter
Posts: 0
Joined: Sun Aug 31, 2014 3:28 am

How can I sort by different things depending on which select menu option is clicked?

I'm not good with JS so I think a working example would help me more.

Bruce Stuart
Posts: 0
Joined: Fri Oct 24, 2014 4:42 am

How can I sort by different things depending on which select menu option is clicked?

Ellen,

Here's an opinion....

For your dropdown menu that you show above - the values that are assigned to the list items should be the name of your fields in your DB - as shown here:

Image

Bruce Stuart
Posts: 0
Joined: Fri Oct 24, 2014 4:42 am

How can I sort by different things depending on which select menu option is clicked?

then - with your dropdown menu highlighted (mine is called select_whatsviewed) - select 'value change' and then Set Storage Variable - i've chosen a variable called swhereclause - I'd prefer you create one in model-storage - called sorder_by - and then bind it to the selected proposery of your dropdown component - like this:

Image

Bruce Stuart
Posts: 0
Joined: Fri Oct 24, 2014 4:42 am

How can I sort by different things depending on which select menu option is clicked?

in your data service - make sure you have an option for 'sort' --- like this:

Image

Bruce Stuart
Posts: 0
Joined: Fri Oct 24, 2014 4:42 am

How can I sort by different things depending on which select menu option is clicked?

in the mapping of your data service - be sure to map the sorder_by variable to the 'sort' in the data service 'BEFORE' mapping...

like this (from storage to query):

Image

Bruce Stuart
Posts: 0
Joined: Fri Oct 24, 2014 4:42 am

How can I sort by different things depending on which select menu option is clicked?

and then lastly - add another event on your select_menu (the one where the user picks the order to sort by) - to kick off the data service to requery the database in the 'sort' that was specified...

Image

let me know if that helps....

Return to “Issues”