
Hi all,
I am trying to sort a definition objects array using the sort method, as below.
oObjDefs = ArisData.sort(oObjDefs, Constants.SORT_TYPE, Constants.AT_NAME, Constants.SORT_NONE, g_nLoc);
The required sort is by Type, Name, Symbol Num. For Type and Name its working ok. I kindly need to know what constant I need to use for the Symbol Number attribute (is there any?).
Regards,
Nicola
Hi,
you cannot sort object definitions by symbols, because the symbols are part of the properties of the occurrences. So an object definition may have multiple occurrences with different symbols.
You could use the default symbol, but this must not always be the same as the symbol the object occurrences (even if only a single one) have - so I would not use this. And there is afaik no sort method for the default symbol.
If you want to sort it, I would go through the list and add the objects to different arrays per default symbol (if you know beforehand which symbols there will be) OR I would use a java map with the key the default symbol type and the value an array of found objects...
BR Robert
If you just need them sorted by default symbol number without any custom ordering, you can simply define your own javascript function by which the Javascript array.sort method should sort the object definitions.
Example:
var nLocale = Context.getSelectedLanguage();
var selGroup = ArisData.getSelectedGroups()[0];
var allObjDef = selGroup.ObjDefList();
function sortObjDefs(objDefA, objDefB) {
var result = objDefA.getDefaultSymbolNum() - objDefB.getDefaultSymbolNum();
if(result == 0) { //if same default symbol
result = objDefA.Name(nLocale).localeCompare(objDefB.Name(nLocale)); //sort by name of object definition
}
return result;
}
var sortedObjDefs = allObjDef.sort(sortObjDefs);