Problem in refreshing datagrid content and retrieving map point.

Discussion created by v_dubey on Apr 22, 2013
Latest reply on Apr 25, 2013 by dcastano
Hi everyone

I am using a dojo datagrid to show records of a table related to the feature layer i am using in my application. This datagrid is binded to the records of the table on selection of one of the feature from the list of features present in a combo box and the map extent is set to the extent of the selected feature. And on the click event of this selected feature infowindow is shown.

But the problem occuring is the grid should get refresh whenever a new feature is selected i.e it should only show the records related to selected feature, but instead of it the data in the grid is getting appended. It is showing all the record of previously selected features plus records of currently selected feature. Also when clicking on the very first selected feature infowindow displays right results but on clicking the second or third or any further selected feature from combobox the infowindow does not show results as itdoes not get the map point where i am clicking it take some other random point on the map. But if the function to add records in datagrid is not called the infowindow is working perfectly.
I am attaching my code also. Please suggest what additions or changes required in the code. Thanks in advance.

            var query = new esri.tasks.Query();
            query.geometry = pointToExtent(map,evt.mapPoint,10);

            var deferred = electionFeatureLayer.selectFeatures(query,esri.layers.FeatureLayer.SELECTION_NEW);
function zoomToPst(item)
   var psname=item.value.toString();
   var queryTask1 = new esri.tasks.QueryTask

   var query1 = new esri.tasks.Query();
   query1.returnGeometry = true;
   query1.outFields = ["OBJECTID"];
   query1.where = "District= 'Nagpur' and AC_Name='"+ddl1+"' and PopupInfo='"+psname+"'and PS_Name='"+ddl2+"' ";
        var id;
        var selectedTaxLot;
        var symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SQUARE, new dojo.Color([0,0,0]), 2), new dojo.Color([0,0,0,0.1]));
        var features = results2.features;
        dojo.forEach (features, function(feature)
            var g = feature;

                if(graphic.attributes.OBJECTID === id)
                    selectedTaxLot = graphic;
                    return ;

        var taxLotMercator=esri.geometry.geographicToWebMercator(selectedTaxLot.geometry).getExtent().expand(2.0);
         store =new dojo.data.ItemFileReadStore({data:{identifier: "", items :[]}});
            //alert("new sr" + newStore);
function findRelatedRecords(features)
    alert("rltd rcrds");
    var relatedTopsQuery = new esri.tasks.RelationshipQuery();
    relatedTopsQuery.outFields = ["*"];
    relatedTopsQuery.relationshipId = 0;
    var ids = dojo.map(features, function (f) {
        return f.attributes.OBJECTID;
    console.log('ids: ', ids);
    relatedTopsQuery.objectIds = ids;
    electionFeatureLayer.queryRelatedFeatures(relatedTopsQuery, function(recs)
        console.log("related recs: ", recs);
        for (id in recs)
            // For each related record, create an item which will correspond to
            // a row in the data grid
                dojo.forEach(recs[id].features, function (feat) {//alert("push recs");

          //Create data object to be used in store
          var data = {
            identifier: "OBJECTID",  //This field needs to have unique values
            label: "OBJECTID", //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});
          grid.setQuery({OBJECTID: '*'});