Select to view content in your preferred language

Query works but populate data grid doesn't

883
4
Jump to solution
05-15-2012 11:40 AM
DavidAshton
Frequent Contributor
I have a query that works.  It creates a graphic, zooms to the graphics, and creates the info window for the graphics but I can't seem to populate my store and fill my grid...can someone take a look at my items array and tell me what's off.

Thanks -D

 var txtSing = "SIGNTYPE = ";   var grid;          function doQuery() {           query.where = (txtSing + "\'" + dojo.byId("SignQuery").value + "\'").toString();         //execute query         queryTask.execute(query,showFResults);       }         function showFResults(results) {                    //remove all graphics on the maps graphics layer     map.graphics.clear();         esri.show(dojo.byId("grid"));               var polygonSymbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([98,194,204]), 2), new dojo.Color([98,194,204,0.5]));         var markerSymbol = new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE, 20, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([0, 0, 255]), 1), new dojo.Color([0, 255, 0, 0.25]));         var lineSymbol = new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_DASH, new dojo.Color([255, 0, 0]), 1);             var items = [];                 dojo.forEach(results.features, function (feature) {                     var graphic = feature;                     switch (graphic.geometry.type) {                case "point":                  graphic.setSymbol(markerSymbol);                  break;                case "polyline":                  graphic.setSymbol(lineSymbol);                  break;                case "polygon":                  graphic.setSymbol(polygonSymbol);                  break;                }                                // //Set the infoTemplate.               graphic.setInfoTemplate(SignInfoTemplate);                                //Add graphic to map                     map.graphics.add(graphic);                   //  return feature.feature.attributes;                     items.push(feature.attributes);                 });                                       //Create data object to be used in store         var data = {           identifier: "OBJECTID",  //This field needs to have unique values           label: "OBJECTID", //Name field for display. Not pertinent to a grid but may be used elsewhere.           items: items         };           //Create data store and bind to grid.         store = new dojo.data.ItemFileReadStore({ data:data });         grid = dijit.byId('grid');         grid.setStore(store);       // Show Grid     // esri.show(dojo.byId("grid"));                   //Zoom back to extent of graphics selected                   var graphicExtent = esri.graphicsExtent(map.graphics.graphics);        map.setExtent(graphicExtent);       }
0 Kudos
1 Solution

Accepted Solutions
DavidAshton
Frequent Contributor
GOT IT.  All along I was using ObjectID as my primary field identifier, once I switch it FacilityID it worked...I was asking for ObjectID in my ery.outFields = "STATEMENT".
identifier: "FACILITYID",  //This field needs to have unique values
          label: "FACILITYID", //Name field for display. Not pertinent to a grid but may be used elsewhere.

Thanks
-D

View solution in original post

0 Kudos
4 Replies
DavidAshton
Frequent Contributor
if I try to push my array and set my array to a string all I see is the string [object Object] building (see attachments)

 var items = [];
                dojo.forEach(results.features, function (feature) {
                    var graphic = feature;
                  
                    switch (graphic.geometry.type) {
               case "point":
                 graphic.setSymbol(markerSymbol);
                 break;
               case "polyline":
                 graphic.setSymbol(lineSymbol);
                 break;
               case "polygon":
                 graphic.setSymbol(polygonSymbol);
                 break;
               }
               
               // //Set the infoTemplate.
              graphic.setInfoTemplate(SignInfoTemplate);
               
               //Add graphic to map
                    map.graphics.add(graphic);
                    //return feature.attributes;
                    items.push(feature.attributes);
                
                    var Istring = items.toString();
                    alert(Istring);
                });


Each time it loops to another feature it creates a new [object, Object]

Can someone tell me my problem and why I'm not seeing my attributes?

Thanks
-D
0 Kudos
KavitaRavindran
New Contributor
Try:

for(i=0; i < features.attributes.length; i++){
  items.push(features.attributes;
}
0 Kudos
DavidAshton
Frequent Contributor
Kavita,

Thanks for the reply but I'm still getting the [object, Object] returned and not my fields.  I had to modify your code slightly:


var items = [];          
    for (var i=0, il=results.features.length; i<il; i++)
    {
     items.push(results.features.attributes);
     } 
     var Istring = items.toString();  //send to string
          alert(Istring);  //show string -- where I see [object, Object] 
0 Kudos
DavidAshton
Frequent Contributor
GOT IT.  All along I was using ObjectID as my primary field identifier, once I switch it FacilityID it worked...I was asking for ObjectID in my ery.outFields = "STATEMENT".
identifier: "FACILITYID",  //This field needs to have unique values
          label: "FACILITYID", //Name field for display. Not pertinent to a grid but may be used elsewhere.

Thanks
-D
0 Kudos