Select to view content in your preferred language

Show find task results in a DataGrid ! For multiple Find Tasks

779
2
12-04-2012 11:44 PM
DavidRaijmakers
Regular Contributor
I have a question. In this example they explain how to display result in a datagrid: http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples_start.htm

But that is only possible with the fixed tableheader id's like:

          <th field="PARCELID">Parcel ID</th>
          <th field="OWNERNME1" >Owner 1</th>
          <th field="OWNERNME2">Owner 2</th>
          <th field="RESYRBLT ">Year Built</th>
          <th field="SITEADDRESS" width="100%">Address</th>

But i cant use this, because i use different find tasks with different parameters.
So i found this example: http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples_start.htm#jssamples/fl_query_relat...

But in this example is one thing that doesnt work: and that's the identifier. If you click on any of the results in the datagrid ( with mfind tasks) then the setExtent doesnt pick the right one. It only picks the last found in the datagrid.
Does anyone know what im doing wrong?

Here's my code:

      function doFind() {
  //  
   var e = document.getElementById("QueryPicker");
   var strUser = e.options[e.selectedIndex].value;
   if (strUser==="Sporen"){
   
        findTask = new esri.tasks.FindTask("https://gis.strukton.com/ArcGIS/rest/services/ProRail_Data/MapServer");
         var findParams = new esri.tasks.FindParameters();
        findParams.returnGeometry = true;
        findParams.layerIds = [31];
findParams.searchFields = ["NR", "GeoSpoor"];
/*var gridTable = document.getElementById("grid1");
//gridTable.style.display = 'none';
   gridTable.style.visibility="hidden";

var gridTable1 = document.getElementById("grid");
gridTable1.style.visibility="visible";*/

        findParams.outSpatialReference = map.spatialReference;
  
  
  findParams.searchText = dojo.byId("ownerName").value;
  findTask.execute(findParams,showResults);
}
   else if (strUser==="Wissels"){
    findTask = new esri.tasks.FindTask("https://gis.strukton.com/ArcGIS/rest/services/ProRail_Data/MapServer");
         var findParams = new esri.tasks.FindParameters();
        findParams.returnGeometry = true;
        findParams.layerIds = [33];
findParams.searchFields = ["NR", "GeoWisselNR1", "GeoWisselNR2"];
/*var gridTable = document.getElementById("grid1");
gridTable.style.visibility="hidden";
var gridTable1 = document.getElementById("grid");
gridTable1.style.visibility="visible";*/
        findParams.outSpatialReference = map.spatialReference;
  
  
  findParams.searchText = dojo.byId("ownerName").value;
  findTask.execute(findParams,showResults);
   }
    else if (strUser==="sein"){
    findTask = new esri.tasks.FindTask("https://gis.strukton.com/ArcGIS/rest/services/ProRail_Data/MapServer");
         var findParams = new esri.tasks.FindParameters();
        findParams.returnGeometry = true;
        findParams.layerIds = [23];
findParams.searchFields = ["NUMMER", "GEOCODE"];
/*var gridTable = document.getElementById("grid");
gridTable.style.visibility="hidden";
var gridTable1 = document.getElementById("grid1");
gridTable1.style.visibility="visible";*/
        findParams.outSpatialReference = map.spatialReference;
  
  
  findParams.searchText = dojo.byId("ownerName").value;
  findTask.execute(findParams,showResults);
   }
   else if (strUser==="bovenleidingpaal"){
    findTask = new esri.tasks.FindTask("https://gis.strukton.com/ArcGIS/rest/services/ProRail_Data/MapServer");
         var findParams = new esri.tasks.FindParameters();
        findParams.returnGeometry = true;
        findParams.layerIds = [26];
  findParams.searchFields = ["NUMMER", "GEOCODE"];
/*var gridTable = document.getElementById("grid");
gridTable.style.visibility="hidden";
var gridTable1 = document.getElementById("grid1");
gridTable1.style.visibility="visible";*/
        findParams.outSpatialReference = map.spatialReference;
  
  
  findParams.searchText = dojo.byId("ownerName").value;
  findTask.execute(findParams,showResults);
   }
   else if (strUser==="Spoortoegang"){
    findTask = new esri.tasks.FindTask("https://gis.strukton.com/ArcGIS/rest/services/POI_Data/MapServer");
         var findParams = new esri.tasks.FindParameters();
        findParams.returnGeometry = true;
        findParams.layerIds = [0];
  findParams.searchFields = ["ToegangsNR"];
/*var gridTable = document.getElementById("grid");
gridTable.style.visibility="hidden";
var gridTable1 = document.getElementById("grid1");
gridTable1.style.visibility="visible";*/
        findParams.outSpatialReference = map.spatialReference;
  
  
  findParams.searchText = dojo.byId("ownerName").value;
  findTask.execute(findParams,showResults);
   }
   else if (strUser==="Kilometrering"){
    findTask = new esri.tasks.FindTask("https://gis.strukton.com/ArcGIS/rest/services/ProRail_Data/MapServer");
         var findParams = new esri.tasks.FindParameters();
        findParams.returnGeometry = true;
        findParams.layerIds = [20];
  findParams.searchFields = ["GEOCODET"];
/*var gridTable = document.getElementById("grid");
gridTable.style.visibility="hidden";
var gridTable1 = document.getElementById("grid1");
gridTable1.style.visibility="visible";*/
        findParams.outSpatialReference = map.spatialReference;
  
  
  findParams.searchText = dojo.byId("ownerName").value;
  findTask.execute(findParams,showResults);
   }
    else if (strUser==="Geocode"){
    findTask = new esri.tasks.FindTask("https://gis.strukton.com/ArcGIS/rest/services/ProRail_Data/MapServer");
         var findParams = new esri.tasks.FindParameters();
        findParams.returnGeometry = true;
        findParams.layerIds = [48];
  findParams.searchFields = ["GeocodeTekst"];
/*var gridTable = document.getElementById("grid");
gridTable.style.visibility="hidden";
var gridTable1 = document.getElementById("grid1");
gridTable1.style.visibility="visible";*/
        findParams.outSpatialReference = map.spatialReference;
  
  
  findParams.searchText = dojo.byId("ownerName").value;
  findTask.execute(findParams,showResults);
   }
   
}
        
        

  
   
 function showResults(results) {
        //This function works with an array of FindResult that the task returns
       var markerSymbol = new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_CIRCLE, 10,
   new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, 
   new dojo.Color([0,255,255]), 2),
   new dojo.Color([0,255,0,0]));
        var lineSymbol = new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID,
    new dojo.Color([0,255,255]), 4);
        var polygonSymbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID,
 new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID,
 new dojo.Color([0,255,255]), 4),new dojo.Color([0,255,255,0]));

        //find results return an array of findResult.
  map.graphics.clear();
        var dataForGrid = [];
        //Build an array of attribute information and add each found graphic to the map
        dojo.forEach(results, function(result) {
          var graphic = result.feature;
          dataForGrid.push([result.foundFieldName, result.value]);
          switch (graphic.geometry.type) {
          case "point":
            graphic.setSymbol(markerSymbol);
            break;
          case "polyline":
            graphic.setSymbol(lineSymbol);
            break;
          case "polygon":
            graphic.setSymbol(polygonSymbol);
            break;
          }
          map.graphics.add(graphic);
        });
        var data = {
   
          items: dataForGrid
        };
        var store = new dojo.data.ItemFileReadStore({
          data: data
        });
        grid.setStore(store);
      }


        //Zoom back to the initial map extent

      
   
   function onRowClickHandler(evt){
    
     //symbology for graphics
        
    
        var clickedTaxLotId = grid.getItem(evt.rowIndex).OBJECTID;
        var selectedTaxLot;

        dojo.forEach(map.graphics.graphics,function(graphic){
          if((graphic.attributes) && graphic.attributes.OBJECTID === clickedTaxLotId){
            selectedTaxLot = graphic;
            return;
          }
        });
  
 

  if ( selectedTaxLot.geometry.declaredClass == 'esri.geometry.Point' ) {
   
   
    
    var PointExtent = new esri.geometry.Extent();
PointExtent.xmin = selectedTaxLot.geometry.x - 100; //I'm using State Plane Feet, so that's 100 out from my point
PointExtent.ymin = selectedTaxLot.geometry.y - 100;
PointExtent.xmax = selectedTaxLot.geometry.x + 100;
PointExtent.ymax = selectedTaxLot.geometry.y + 100; 
map.setExtent(PointExtent);
    
    
    
     //map.centerAndZoom(selectedTaxLot.geometry);

   
  //map.setExtent(sp.getExtent().expand(3));

 
 // map.infoWindow.show(selectedTaxLot.geometry, map.getInfoWindowAnchor(sp));


  }
  else{

 var taxLotExtent = selectedTaxLot.geometry.getExtent();
        map.setExtent(taxLotExtent);
 
   //map.setExtent(mappoint);

}


And some HTML:

<div data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region:'bottom'" style="height:350px;" >
<table data-dojo-type="dojox.grid.DataGrid" jsid="grid" id="grid" data-dojo-props="rowsPerPage:'5', rowSelector:'20px'">
      <thead>
        <tr>

          <th field="0" width="auto" >
            Gezocht op
          </th>
          <th field="1" width="auto" >
            Gevonden
          </th>
        </tr>
      </thead>
    </table>
    </div>
        
        </div>
0 Kudos
2 Replies
DavidRaijmakers
Regular Contributor
It could be in this sentences.

var clickedTaxLotId = grid.getItem(evt.rowIndex).OBJECTID;
        var selectedTaxLot;

        dojo.forEach(map.graphics.graphics,function(graphic){
          if((graphic.attributes) && graphic.attributes.OBJECTID === clickedTaxLotId){
            selectedTaxLot = graphic;
alert("found");
            return;
          }
        });

The OBJECTID is the unique value. But when i type this in the alert does'nt get called
0 Kudos
SreenivasaRaoPigili
Frequent Contributor
Hi,

Actually my task is - if user selects no.of rows in the grid result, we have to change the map extent to show all the selected features.
I have tried to solve the issue in below steps.
1. Captured all the selected rows information from the grid
2. Loop through all these selected rows
3. Compare the attribute value with one of the grid column (i.e PARCELID).
   Based on that value i am planning to UNION all the selected feature extent.

   I have tried to modify the existing find task code for single row to multiple row selection as below.

      //Zoom to the parcel when the user clicks a row
      function onRowClickHandler(evt)
      {
        var items = grid.selection.getSelected();
        if(items.length)
        {
            dojo.forEach(items, function(selectedItem)
            {
                if(selectedItem !== null)
                {
             var selectedTaxLot;
                  //alert('attrbute values are '+grid.store.getAttributes(selectedItem));
                  dojo.forEach(grid.store.getAttributes(selectedItem), function(attribute)
                  {
                     if(attribute == 'PARCELID')
                    {
                       var clickedTaxLotId=grid.store.getValues(selectedItem, attribute);
                  //     alert('enter into parcelid loop with value '+clickedTaxLotId);

                 
   dojo.forEach(map.graphics.graphics,function(graphic)
   {          
      if((graphic.attributes) && graphic.attributes.PARCELID === clickedTaxLotId)
      {            
        alert('entered into comparision');
         selectedTaxLot = graphic;            
         return;          
      }        
   });  //end of dojo.foreach for graphics


                     }
                  });

                } // end if


            }); // end forEach

        } // end if

      } //end of function onRowClickHandler


Can any one please look into this one. Here i am not getting the message from the last alert message - which is in last forEach loop.
Please let me know, if my analysis is wrong to achieve my task.

It could be in this sentences.

var clickedTaxLotId = grid.getItem(evt.rowIndex).OBJECTID;
        var selectedTaxLot;

        dojo.forEach(map.graphics.graphics,function(graphic){
          if((graphic.attributes) && graphic.attributes.OBJECTID === clickedTaxLotId){
            selectedTaxLot = graphic;
alert("found");
            return;
          }
        });

The OBJECTID is the unique value. But when i type this in the alert does'nt get called
0 Kudos