OK, I'll break down the relevant code. First a feature is selected on the map.
var selquery = new esri.tasks.Query();
selquery.where = "OBJECTID = " + featID;
var geoLyr = map.getLayer(layerId);
geoLyr.selectFeatures(selquery);
In the init() function, each feature layer is connected to an 'onSelectionComplete' function:
dojo.connect(geoLyr, "onSelectionComplete", selectFeature);
Once a feature has been selected, then we query a business table (also a feature layer loaded in the map) to select the associated record:
function selectFeature(geoResults) {
if (geoResults.length === 1) {
var accNum = geoResults[0].attributes["ACCNUM"];
var accTbl = map.getLayer("accTable"); // ACCESSIONS table feature layer
var accQuery = new esri.tasks.Query();
accQuery.returnGeometry = false;
accQuery.where = "ACCESSIONNUMBER = '" + accNum + "'";
accTbl.selectFeatures(accQuery, esri.layers.FeatureLayer.SELECTION_NEW);
}
}
That's really it. The selectFeature function fires every time any single feature is selected on the map. When the Identify task is used to select a feature, the Accessions table selection works as expected and the Attribute table loads correctly.When a feature is selected via the datagrid onRowClickHandler function, the same selectFeature function also fires, but you get the error as shown in the screenshots above UNLESS it has already been displayed by a previous Identify selection. To clarify, if a user selects a feature first using the Identify task, the Attribute Inspector will load the selected feature from the Accessions table correctly, and it will continue to work correctly if the user selects a search result from the datagrid. However, if a user makes their first selection from the datagrid, the Attribute Inspector will fail to load the selected record on all subsequent selections, regardless of the method used.I find it strange and baffling that the same 'onSelectionComplete' function, which returns the correct feature every time, only loads the Attribute Inspector some of the time.