Thanks for the quick response. I was originally using a composite locator and could not bind it and assumed my data grid was structured wrong. However, once I used a single locator, I could bind. I guess the composite returns a different array structure.Thanks again.
What would the datagrid headings look like? I get an error when trying to bind the datastore to the following datagrid: <table data-dojo-type="dojox.grid.DataGrid" data-dojo-id="AddressGrid" id="AddressGrid" data-dojo-props="rowSelector:''" style="width: 325px; height: 350px; margin: 0; overflow: scroll"> <thead> <tr> <th field="Match_addr"> Match_addr </th> <th field="Score"> Score </th> <th field="Ref_ID"> Ref_ID </th> </tr> </thead> </table>
... var layout = { cells: [ { field: "Match_addr", name: "Match Address", width: 'auto' }, { field: "Score", name: "Scores", width: '125px' }, { field: "Ref_ID", name: "Reference ID", width: '125px' } ] }; var grid = dijit.byId("AddressGriD"); grid.attr("structure", layout); ...
Hi HemingSorry but I have stumbled upon another problem so if you fancy figuring the following out I would appreciate it! 🙂All of my candidate addresses are coming up in the data grid and I can successfully zoom to each one which is great, but I am trying to limit the number of results that are outputted to the grid using an if statement which is used in the ESRI locator sample (the code snippet below is what I have tried to use).I run it when the array 'items' is built to try and only select those that have a candidate score of 80 or above - my graphics layer is successfully drawing only those candidates that have a score of +80 but the data grid has an error, when using firebug it mentions that it "cannot set property '_RI' of undefined".Digging a bit deeper this variable seems to be set in the dojo.data.ItemFileReadStore:-this._rootItemPropName = "_RI"; // Default Item Id for isItem to attach to every item.This might be something more dojo related but I don't suppose you have any other possible ways of limiting the candidates down by scores or indeed if the above error might be solvable?I appreciate all the help you have given me so far! 🙂//CODE//create array of attributes var items = dojo.map(candidates,function(candidate){ if (candidate.score > 80){ geom = new esri.geometry.Point(candidate.location.x, candidate.location.y); var attributes = candidate.attributes; var scoreCandidate = candidate.score; 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;//break out of loop after one candidate with score greater than 80 is found. } });//CODE
Hi HemingThanks a lot for your help with this, figured out that I need to use the geometry property just as I posted my last reply.Thanks again! 🙂PS - How can I give you credit for this? I cannot find a "this post answered my question" option anywhere?
Hi Heming I put an alert in the onrowclick function to write the attributes of graphic just to see what I would get. Before it was just saying undefined but it now successfully shows the Ref_ID value of the row I clicked on which means the code you provided has worked. The problem now is I do not have the X,Y coordinates to use in the attributes to do a zoom to point (I do not have X,Y coordinates available in the candidate fields to use so will have to use the candidate.location values somehow).
dojo.forEach(map.graphics.graphics,function(graphic){ if((graphic.attributes) && graphic.attributes.IDENT === clickedAddressId){ selectedAddress = graphic; return; } }); //map.centreAndZoom(selectedAddress,7); map.centreAndZoom(selectedAddress.geometry,7); }
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?//CODEfunction 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
Hi HemingThanks for your response.Yes I was looking at this sample and wondering how it can be implemented for a locator.I was confused as to how you would list the data in the grid particularly with the field headings as they are defined differently.
Hi Manish,I only recently posted this (around an hour ago) so am still waiting for a response 🙂
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.