Thanks Heming that was very helpful, I have now managed to get my candidate addresses into the data grid with my desired fields!
Using the find sample I would now like to be able to zoom to each individual feature from the grid but am having some problems here.
In the original find sample the variable 'graphic' is defined as the result.feature of the find task which has attributes assigned to it already.
I have assigned attributes to the 'graphic' variable in my code but it does not seem to work.
Is there anything obviously wrong with the below code as to why it might not zoom to each address point?
//CODE
function locate() {
map.graphics.clear();
var searchResult = dijit.byId("addressSearch").value;
var address = {"Single Line Input": searchResult};
locator.addressToLocations(address,["Ref_ID, Score, Match_addr"]);
}
function showResults(candidates) {
var symbol = new esri.symbol.SimpleMarkerSymbol();
symbol.setStyle(esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE);
symbol.setColor(new dojo.Color([153,0,51,0.75]));
//create array of attributes
var items = dojo.map(candidates,function(candidate){
var geom = esri.geometry.Point(candidate.location);
var attributes = {IDENT:candidate.attributes.Ref_ID};
var graphic = new esri.Graphic(geom, symbol, attributes);
//add a graphic to the map at the geocoded location
map.graphics.add(graphic);
return candidate.attributes;
});
var data = {
identifier: "Ref_ID", //This field needs to have unique values
label: "Ref_ID", //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 });
var grid = dijit.byId('grid');
grid.setStore(store);
}
function onRowClickHandler(evt){
var clickedAddressId = grid.getItem(evt.rowIndex).Ref_ID;
var selectedAddress;
dojo.forEach(map.graphics.graphics,function(graphic){
if((graphic.attributes) && graphic.attributes.IDENT === clickedAddressId){
selectedAddress = graphic;
return;
}
});
map.centreAndZoom(selectedAddress,7);
}
//FINISH CODE