How to Use Extended Sdk Collection to handle “properties”
In order to use fill in the Design Studio SDK: Leader Board Component I had to extend the Design Studio SDK: Collection Util Component by addition of extra generic parameters which can be passed to the collection and used as properties.
Now, you can use a new method which is returning an array with additional properties:
Scripting Functions
Scripts | Short Description |
---|---|
org.scn.pack.KeyLabelValueExtendedArray getAsKeyLabelValueExtendedArray ( /**max members*/ optional int maxMembers) |
returns the array with key, label, value + param1, param2, param3 which can be used as place holders for properties |
element.param1
element.param2
element.param3
eg.
var keysAndlabelsAsArray = COLLECTION_1.getAsKeyLabelValueExtendedArray(5);
// fill into the looser board
keysAndlabelsAsArray.forEach(function(element, index) {
LOOSERBOARD.addElement(element.key, element.label + " ("+element.key+")", element.key + ".jpg", element.value, "" + element.param1);
});
How to Fill it in?
The set* and add* methods are extended by optional parameters,
Scripts | Short Description |
---|---|
void setItems ( /*keys*/ String keys, /*labels*/ String labels, /*values*/ String values, /*separator*/ optional String separator, /*optional param 1 array*/ optional String param1s, /*optional param 2 array*/ optional String param2s, /*optional param 3 array*/ optional String param3s) |
Sets items of the array by 2 strings: for keys, labels, values. Additionally sets also 3 optional arrays for parameters 1-3. |
void addItem ( /*key*/ String key, /*label*/ String label, /*value*/ float value, /*optional param 1*/ optional String param1, /*optional param 2*/ optional String param2, /*optional param 3*/ optional String param3) |
Adds a value to new or existing array. Additionally sets also 3 optional values for parameters 1-3. |
Connecting to other elements
Now, by this you can make more comprehensive loops and save more properties in the collection (which are also sorted):
COLLECTION_1.removeAllItems();
allMembers.forEach(function(member, index) {
var memberKey = member.internalKey;
var memberText = member.text;
var dataCell = DS_1.getData("4FW8C4WXM3HULQ4M1YPFT79EF", {
"0BC_PERS1": memberKey
});
if(dataCell.formattedValue != "") {
var value = dataCell.value;
var formattedValue = dataCell.formattedValue;
COLLECTION_1.addItem(memberKey, memberText, value, formattedValue);
}
});
// leaders
COLLECTION_1.sortByValueDescending();
var keysAndlabelsAsArray = COLLECTION_1.getAsKeyLabelValueExtendedArray(5);
In the example above, also “formattedValue” is now part of the array and can be used later in this script:
LEADERBOARD.removeAllElements();
keysAndlabelsAsArray.forEach(function(element, index) {
LEADERBOARD.addElement(element.key, element.label + " ("+element.key+")", element.key + ".jpg", element.value, "" + element.param1);
});
I hope this helps to handle more complex top/bottom scenarios now.
Example Application
A live application is available in GitHub, of course you have to change the system and query to some compatible query.
GitHub Access
An Application with example can be downloaded at the BIAPP Repository:
Hi Karol,
I'm wondering if the extra parameters can be accessed individually with a lookup, similar to the getLabelByKey() method? At the moment it seems like I first need to get the entire array with getAsKeyLabelValuePropertyArray(), then loop through it to find the individual record based on the key and then access the property parameters. It would be useful to have a more direct method like getPropertyByKey(p) where p is the parameter number (1-3).
Thanks,
Mustafa.
Hi Mustafa,
yes, this is easy. I think we can add "getEntryByKey" and then return the object
org.scn.community.shared.KeyLabelValueProperty
which will allow direct access to all parts, eg.
entry.value
entry.prop1
I will look at this soon.
Karol
Thanks Karol.
done, if you take current version.
Thanks Karol,
I noticed the new method a couple of days ago 🙂 . I plan to publish a blog next week demonstrating a use case for the Collection component.
Regards,
Mustafa.