AnsweredAssumed Answered

Sorting elements in Combo box (API version 2.8)

Question asked by sunilpalkar on Nov 21, 2012
Hello All,

I am trying to sort elements in combo-box. If I use
  query.orderByFields = ["TOPIC ASC"];
then its showing only few records..

If I hide above raw then its showing all records . I don't understand  why this is happening..

Details : I have created sql query layer in ArcMap 10.1 and publishing that layer in ArcGIS Server 10.1

Any help will be great...thanks in advance : )

Code is

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html>   <head>     <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>     <meta http-equiv="X-UA-Compatible" content="IE=7" />     <title>Identify Sample</title>          <link rel="stylesheet" type="text/css" href="https://serverapi.arcgisonline.com/jsapi/arcgis/3.1/js/dojo/dijit/themes/claro/claro.css">     <style>            </style>     <script type="text/javascript">djConfig = { parseOnLoad:true }</script>     <script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.8"></script>     <script type="text/javascript">       dojo.require("esri.map");       dojo.require("esri.tasks.identify");       dojo.require("dijit.layout.ContentPane");       dojo.require("dijit.layout.TabContainer");       dojo.require("dijit.form.Button");       dojo.require("esri.map");        dojo.require("esri.dijit.Legend");       dojo.require("esri.tasks.query");       dojo.require("dojo.parser");       dojo.require("dijit.layout.BorderContainer");       dojo.require("dijit.layout.ContentPane");       dojo.require("dijit.form.ComboBox");       dojo.require("dojo.data.ItemFileReadStore");       dojo.require("esri.layers.FeatureLayer");        dojo.require("esri.tasks.identify");       dojo.require("dijit.layout.ContentPane");       dojo.require("dijit.layout.TabContainer");       dojo.require("dijit.form.Button");       dojo.require("esri.dijit.Scalebar");        var map, identifyTask, identifyParams, symbol;       var layer2results, layer3results, layer4results;         var featureLayer,resizeTimer;                function init() {         var initExtent = new esri.geometry.Extent({"xmin":2544919.74,"ymin":1517148.92,"xmax":7436889.55,"ymax":4452330.81,"spatialReference":{"wkid":102100}});       //  map = new esri.Map("mapDiv",{extent:esri.geometry.geographicToWebMercator(initExtent)});        map = new esri.Map("mapDiv",{extent:initExtent});        dojo.connect(map, "onLoad", initFunctionality);         var scalebar = new esri.dijit.Scalebar({             map: map,             scalebarUnit:'english'           });                var basemap = new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer");         map.addLayer(basemap);                  //query task starts var queryTask = new esri.tasks.QueryTask("http://<my machine>:6080/arcgis/rest/services/Test_1/MapServer/0");                  //Define query parameters        var query = new esri.tasks.Query();         query.outFields = ["TOPIC"];         query.returnGeometry = false;         query.where  = "TOPIC <> ''"         query.orderByFields = ["TOPIC ASC"];         queryTask.execute(query,populateList);                           var landBaseLayer = new esri.layers.ArcGISDynamicMapServiceLayer("http://<my machine>:6080/arcgis/rest/services/Test_1/MapServer",{opacity:.90,id:"S1.DBO.d1"});         dojo.connect(map.infoWindow, "onShow", function() {           dijit.byId("tabs").resize();         });         map.addLayer(landBaseLayer);                  //legend data      /*   dojo.connect(map,'onLayersAddResult',function(results){           var layerInfo = dojo.map(results, function(layer,index){             return {layer:layer.layer,title:layer.layer.name};           });           if(layerInfo.length > 0){             var legendDijit = new esri.dijit.Legend({               map:map,               //layerInfos:layerInfo                              //new settings                   layerInfos:[{layer:landBaseLayer, title:" "},                                                               ]                            },"legendDiv");             legendDijit.startup();           }         });         map.addLayers([landBaseLayer]);  */        }        function initFunctionality(map) {         dojo.connect(map, "onClick", doIdentify);          identifyTask = new esri.tasks.IdentifyTask("http://<my machine>:6080/arcgis/rest/services/Test_1/MapServer");          identifyParams = new esri.tasks.IdentifyParameters();         identifyParams.tolerance = 3;         identifyParams.returnGeometry = true;         identifyParams.layerIds = [0,2];         identifyParams.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_ALL;         identifyParams.width  = map.width;         identifyParams.height = map.height;                  map.infoWindow.resize(415, 200);         map.infoWindow.setContent(dijit.byId("tabs").domNode);         map.infoWindow.setTitle("Identify Results");          symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255,0,0]), 2), new dojo.Color([255,255,0,0.25]));       }        //here it will identify the information       function doIdentify(evt) {         map.graphics.clear();         identifyParams.geometry = evt.mapPoint;         identifyParams.mapExtent = map.extent;         identifyTask.execute(identifyParams, function(idResults) { addToMap(idResults, evt); });       }        function addToMap(idResults, evt) {         bldgResults = {displayFieldName:null,features:[]};        // parcelResults = {displayFieldName:null,features:[]};          for (var i=0, il=idResults.length; i<il; i++) {           var idResult = idResults[i];           if (idResult.layerId === 0) {             if (!bldgResults.displayFieldName) {bldgResults.displayFieldName = idResult.displayFieldName};             bldgResults.features.push(idResult.feature);           }                   }         dijit.byId("bldgTab").setContent(layerTabContent(bldgResults,"bldgResults"));                  map.infoWindow.show(evt.screenPoint, map.getInfoWindowAnchor(evt.screenPoint));       }        function layerTabContent(layerResults, layerName) {         var content = "";         switch (layerName) {           case "bldgResults":            // content = "<i>Total features returned: " + layerResults.features.length + "</i>";             content += "<table border='1'><tr><th>TEXT</th><th>USERNAME </th></tr>";             for (var i=0, il=layerResults.features.length; i<il; i++) {               content+="<tr><td>"+layerResults.features[i].attributes['TEXT']+" <a href='#' onclick='showFeature(" + layerName + ".features[" + i + "]); return false;'></a></td>";               content+="<td>"+layerResults.features[i].attributes['USERNAME']+"</td>";             }             content+="</tr></table>";             break;                    }         return content;       }        function showFeature(feature) {         map.graphics.clear();         feature.setSymbol(symbol);         map.graphics.add(feature);       }              //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;          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;       }              function applyLayerDef(selItem){               //Filter the layer to display only the selected zoning types         if (selItem.value !== 'ALL') {           var layerDefs = [];           // added newly  11 nov 2012           //var layer = map.getLayer("S1.DBO.d1");            layerDefs[0] = "TOPIC = " + "'" + selItem.value + "'";           layerDefs.visibleLayers = [0];           map.getLayer("S1.DBO.d1").setLayerDefinitions(layerDefs);         }         else {           map.getLayer("S1.DBO.d1").setDefaultLayerDefinitions();         }       }        function resizeMap() {         //Handle browser resize            clearTimeout(resizeTimer);                  resizeTimer = setTimeout(function() {           map.resize();           map.reposition();         }, 800);       }        dojo.addOnLoad(init);     </script>    </head>   <body class="claro">     <div id="header"              dojotype="dijit.layout.ContentPane"              region="top"              style="height:25px;">         <select id="mySelect"               dojotype="dijit.form.ComboBox"              style="width:300px;font-size:18px;"              autoComplete="true"              forceValidOption="false"              value="Select"              onchange="applyLayerDef(this)"></select>       </div>             <div id="mapDiv" style="width:1000px; height:600px; border:1px solid #000;"></div>        <!-- info window tabs -->     <div id="tabs" dojoType="dijit.layout.TabContainer" style="width:385px;height:150px;">       <div id="bldgTab" dojoType="dijit.layout.ContentPane" title="Information"></div>            </div>          </body> </html>

Outcomes