0
votes

I have a drop-down menu that i want to populate from one specific Datasource. the issue is i want to add one option that isn't an item in the db.

The table I have is Brand.

The value of options for that dropdown currently is @datasources.Brand.items, which shows all the items in the db.

  • Brand item 1
  • Brand item 2
  • Brand item 3

All the items in Brand will be in the dropdown , but i want to add one option "All Brands".

I tried to set options of the dropdown to ["All Brands",@datasources.Brand.items]

I don't get the result i want i get "All Brands as option 1 and the 2nd one is one line:

SimplePropertyList{itemType=Brand Record,items[com.google.apps.appmaker.client.model.ActiveRecord.

What I'm looking for is:

  • All Brands
  • Brand item 1
  • Brand item 2
  • ....
1
Depending on the query, can you use a UNION to add "All Brands"? - Jon
The easiest thing to do is to allow null and use the null value for all brands. - Morfinismo
@Jon but how to do the query to be able to use union in the options ? - Duaa
@Morfinismo will try to keep that option as the last one , there must be a way , unfortunately i'm still new to all this and having a difficulty - Duaa

1 Answers

1
votes

If you really insist in not using the null value and you must have the "All Brands" option as one of the selections, then you need to do the following on the options binding:

Array.prototype.concat(
    ["All Brands"], 
    (@datasources.Brand.items).map(function(item){return item.BRANDNAME;})
)

In the above, BRANDNAME represents the field name that contains the brand name in your model.

Please note that this approach will not allow you to choose a brand record from the dropdown, but instead it will only allow you to choose the brand name(which is a string).

If you are looking for an approach that will let you choose the record instead of only the brand name, then you will need to create a record that contains the "All Brands" as a name and then you can simply sort it to make sure it always appear at the top by doing the following on the binding:

(@datasources.Brand.items).sort(function(a,b){
    return a.BRANDNAME === "All Brands" ? -1 : 1;
});