Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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 hereAs you can see all elements are sorting but the "ALL" entry is not sorting

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"})
  }
share|improve this question
    
Let me know if you require the complete code.. –  Sunil Nov 27 '12 at 7:34
    
I am referring this (blogs.esri.com/esri/arcgis/2010/08/30/…) link & the example mentioned in the link –  Sunil Nov 27 '12 at 8:10
1  
please post the code –  David Wilton Nov 27 '12 at 11:51
    
@David combo-box elements are coming from 'topic' column and I have added "ALL" element to display all the records..thanks for your response –  Sunil Nov 27 '12 at 12:04
    
How should I enter code to proper format here (without any gap) ??..thanks –  Sunil Nov 27 '12 at 12:05
add comment

1 Answer

up vote 3 down vote accepted

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;
                    }
                }
            });
share|improve this answer
    
thanks for your prompt response !! Let me try then I will get back to you.. –  Sunil Nov 27 '12 at 13:06
    
I added a JS fiddle to show code running –  David Wilton Nov 27 '12 at 17:16
    
@David..thanks I am testing this @ my end..thanks a lot : ) –  Sunil Nov 28 '12 at 7:29
    
@David.. I tried your way and its working : ) so thanks a lot David once again..You are great !! –  Sunil Nov 28 '12 at 12:22
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.