I am using sorting elements in combo box in ArcGIS Java Script API (v.2.8) & for sorting I am using “ fetchProperties="{sort:[{attribute:'name', descending:false}]}". All entries in combo box are sorting excluding “ALL” entry.
So I am not able to understand that why “ALL” is not sorting ascending. It is displaying at the end but when make “descending: true” then its displaying first.
I want to put “ALL” in the beginning of the combo-box. Therefore, any help will be great.
Please check the screenshot below: enter image description here
Image :
Code is :
//combo box item
function populateList(results) {
//Populate the dropdown list box with unique values
//alert("sss: "+results.length);
var zone;
var values = [];
var testVals={};
//Add option to display all zoning types to the dropdown list
//values.push({name:"ALL"})
var features = results.features;
//values.push({name:'ALL'});
dojo.forEach (features, function(feature) {
zone = feature.attributes.TOPIC;
if (!testVals[zone]) {
testVals[zone] = true;
values.push({name:zone});
}
});
var dataItems = {
identifier: 'name',
label: 'name',
items: values
};
var store = new dojo.data.ItemFileReadStore({data:dataItems});
dijit.byId("mySelect").store = store;
values.push({name:"ALL"})
}
Answer
Looking at your code I assume you tried pushing in the 'All' Item to the array before the result items? This should work, the order of the array controls the order they appear. Just tidied up the code and added both a label and an identifier (I don't think this is required to be different or controls the order).
Update: Here is a JS fiddle running in 2.8 returning the results in the correct order
var dataItems = {
identifier: 'id',
label: 'name',
items: values
};
dataItems.items.push({ name: 'ALL', id: 0 });
var features = results.features;
var i = 1;
var zone;
dojo.forEach(features, function(feature) {
zone = feature.attributes.TOPIC;
if (zone) {
if (!testVals[zone]) {
testVals[zone] = true;
dataItems.items.push({ name: zone, id: i });
++i;
}
}
});
No comments:
Post a Comment