AnsweredAssumed Answered

infoTemplate setContent function used also for datagrid click?

Question asked by schlot on Feb 27, 2013
Latest reply on Feb 27, 2013 by schlot
I have an infoTemplate that is using a function to format the content of the infoWindow:
parcelInfoContent = parcelInfoTemplate.setContent(parcelSetWindowContent);


A lot of my fields don't have any data, so in my function I'm checking to see if there is data before I put the information for that field:
function parcelSetWindowContent(graphic) {     var addressTest = graphic.attributes.SITEADDRES;     var legalTest = graphic.attributes.LEGAL1;     var twpRangeSecString = "Township:" + graphic.attributes.TOWNSHIP + "  Range:" + graphic.attributes.RANGE + "  Section: " + graphic.attributes.SECTION_ + "<br>" +"Legal Description:<br>" + graphic.attributes.LEGAL1;     var initString = "";     if (addressTest.length > 1) {         initString = initString + "Site Address:  :" + addressTest ;     }      if (legalTest) {         initString = initString + "<br>" + twpRangeSecString;     }     return initString; }    


I am also populating a datagrid of these parcels and I also need to have an onclick which zooms to the parcel and opens the same infoWindow.  I'd like to use the same function to format, but I'm not sure how to get there.  I thought maybe there was a function for 'getInfoContent' on the featurelayer I'm using this for.  I can't quite figure this out.  I thought maybe I could set a variable parcelInfoContent when I set the definition initially, but that didn't do the trick.

function onRowClickHandler(evt){          map.graphics.clear();         map.infoWindow.hide();         var OID = grid.getItem(evt.rowIndex).OBJECTID;          var selectedParcel;          var query = new esri.tasks.Query();         query.objectIds = [OID];        // query.where = "PID= '" + parcelId + "'";         parcelFeatureLayer.selectFeatures(query,esri.layers.FeatureLayer.SELECTION_NEW, function (features) {            var parcelExtent = esri.graphicsExtent(features);            parcelExtent.expand(2);            map.setExtent(parcelExtent);                  var feature = features[0];                                 var centerPt = parcelExtent.getCenter();                 feature.setInfoTemplate(parcelInfoTemplate);                                 map.infoWindow.setTitle(feature.attributes.PID);                 var content = esri.substitute(feature.attributes, parcelInfoContent);                 map.infoWindow.setContent(content);               //   map.infoWindow.setFeatures([feature]);                  var labelPt = new esri.geometry.Point(centerPt, spatialReference);                 map.infoWindow.show(labelPt);         });                    } 

Outcomes