abrown31

IdentifyTask results' attributes to Datagrid

Discussion created by abrown31 on Jul 21, 2011
Latest reply on Mar 9, 2012 by map12
Hello,

I'm trying to use the results' attributes from an identifytask to populate a dynamic datagrid. I found an ESRI example that uses the findtask to do this, but I'm having issues with the identifyTask. The grid structure is created, but there is a problem with the itemfilereadstore.

Does anybody have any examples? Or does anybody know what I'm doing wrong? My code is below:

          identifyParams = new esri.tasks.IdentifyParameters(); 
          identifyParams.tolerance = 3; 
          identifyParams.returnGeometry = true; 
          identifyParams.layerIds = [1];
          identifyParams.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_VISIBLE;
          identifyParams.geometry = geometry;
          identifyParams.mapExtent  = map.extent; 
          identifyParams.width  = map.width; 
          identifyParams.height = map.height; 
          identifyTask.execute(identifyParams, function(identifyResults){
            if(identifyResults.length>0){
              var items = dojo.map(identifyResults, function(result){
                var graphic = result.feature;
                switch(result.geometryType){
              
                case "esriGeometryPoint":
                symbol = new esri.symbol.SimpleMarkerSymbol();
                break;
                case "esriGeometryPolygon":
                symbol = 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]));
                break;
                }
                graphic.setSymbol(symbol);
                map.graphics.add(graphic);
                return result.feature.attributes;
                
              });
            
          var fieldName;
        var fieldNameArr = [];
        var selectedLayer;
        
        clearSelectResults();

        for (fieldName in items[0]) {
          if (items[0].hasOwnProperty(fieldName)) {
            fieldNameArr.push({
              field: fieldName,
              name: tableNames(fieldName),
              editable: false
            });
            
            
          }
        }
        var data = {
          identifier: "OBJECTID",  //This field needs to have unique values
          items: items
        }; 
        var store2 = new dojo.data.ItemFileReadStore({ data:data });
        
        var children = dojo.byId("wellsTab");
        while(children.firstChild){
         children.removeChild(children.firstChild); 
        }
        
        wellsGrid = new dojox.grid.EnhancedGrid({
          query: {
            OBJECTID: '*'
          },
          
          clientSort:true,
          autowidth:true,
          structure:fieldNameArr,
          rowsPerPage: 250,
          plugins: {
            indirectSelection:{ 
                name:"Select",
                field:"Select",
                width: "70px",
                styles: "text-align: center;"
                
                }
          }
        });
        dojo.byId("wellsTab").appendChild(wellsGrid.domNode);
        wellsGrid.setStore(store2);
        dijit.byId("bottomTabs").selectChild(dijit.byId("wellsTab"));
        
        wellsGrid.startup();
        wellsGrid.update();
        wellsGrid.rowSelectCell.toggleAllSelection(true);
        
        wellsGrid.resize();
        
        dojo.connect(wellsGrid, 'onDeselected', function(rowId){
          
          map.graphics.remove(results.features[rowId]);
        
        
        });
        dojo.connect(wellsGrid, 'onSelected', function(rowId){
        
            map.graphics.add(results.features[rowId]);
        
        });
        
        }
        });

Outcomes