Selected feature in dgrid not passing objectID to relationQuery

1270
19
Jump to solution
01-12-2018 08:33 AM
JayHill
Occasional Contributor II

I have a watchUtil for a popup opening, to trigger a related table query. Works perfectly when a user clicks on a feature on the map but when a grid row is clicked the relationshipQuery doesnt return any results.

                  watchUtils.when(app.view.popup, "selectedFeature", function photos(evt){
                       console.log(app.view.popup.selectedFeature);
                       query("#panelDetails").removeClass("in");

                       var objectID = app.view.popup.selectedFeature.attributes.OBJECTID;
console.log(objectID);
                       var queryTask = new QueryTask({
                            url: "https://services.arcgis.com/ZzrwjTRez6FJiOq4/arcgis/rest/services/Core_Locations_20171129/FeatureSer..."
                       });

                       relationQuery = new RelationshipQuery({
                            objectIds: [objectID],
                            outFields: ["Filename", "directory", "TYPE", "Usage", "Top_Depth", "Bottom_Depth"],
                            relationshipId: 1
                       });
console.log(relationQuery);
                       queryTask.executeRelationshipQuery(relationQuery).then(function(rslts){

                         document.getElementById("attDetails").innerHTML = "";
                         //No rslt given back here when clicking on dgrid
console.log(rslts);
                                       var features = rslts[objectID].features;
console.log(features);
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Jay,

  So this is what I am finding. Your Search widget is not returning the right features for the search. When I search for "#D-616 (STATE) LISBON" it returns 4 features and here are the objectids of those results (3048,3049,3050,3051).

When I click on the well with the actual name of "#D-616 (STATE) LISBON" its objectid is actually 2892. So the reason your images are not working for the dgrid click is the objectids in the results are not the correct ones. Now as to why the search is messing up so bad... I am not real sure. The one thing I see that is off is the JS is case sensitive and you have

searchFields: ["UWI","Well_Name", "Operator", "PROD_FORM", "Township", "Range"],

The "Operator" in the above list is not the correct field name it is "OPERATOR". See if that makes a difference.

View solution in original post

0 Kudos
19 Replies
RobertScheitlin__GISP
MVP Emeritus

Jay,

  I don't see anything in your code that says you have a dgrid or any event setup on the grid to interact with the relationship query..?

0 Kudos
JayHill
Occasional Contributor II

Ah sorry Robert! Here is the dgrid code.

var grid = new (declare([ OnDemandGrid, Selection ]))({
  class: "grid",
  selectionMode: 'single',
  autoHeight:true,
  autoWidth:true,
  initialWidth:"100%",

  columns: [
    { label: "UWI", field: "UWI" },
    { label: "Well Name", field: "Well_Name" },
    { label: "Operator", field: "Operator" },
  ]
}, "grid");
grid.startup();


function resizeGrid() {
   grid.resize();
   grid.update();
}
// when user resizes window, resize the search grid results
app.view.on('resize', function(e) {
    resizeGrid();
});

app.searchWidgetNav.allPlaceholder = "Search Wells";
app.searchWidgetNav.activeSourceIndex = "1";

app.searchWidgetNav.on("search-complete", function(e){
    app.view.popup.clear();  // close popup if its open from last search
    var results = null;  // clear old searches
    query("#panelDetails").removeClass("in");

    if ( e["results"] ){

        // first we need to map the source layer to the graphics
        resultsArray = [];
        e["results"].forEach(function (rslt) {    // loop through the three possible source layers

            // now loop through each graphic and assign the layer field
            rslt.results.forEach(function (rslt2) {

                resultsArray.push(rslt2.feature);
            });
            //resultsArray.push(graphics);
        });


        // put our attributes in an object the datagrid can ingest.
        var srch = {"items": [  ]};
        resultsArray.forEach(function (ftrs) {

            var att = ftrs.attributes;

            srch.items.push( att );
        });

        var test_store = new Memory({data: srch, idProperty: "OBJECTID"});
        //console.log(test_store);
        grid.set('collection', test_store);

        grid.on('.dgrid-row:click', function (event) {

          query("#panelDetails").removeClass("in");   //close any open panels
          query("#collapseDetails").removeClass("in");
          app.view.graphics.removeAll();
          var idx = "";
          var idx = grid.row(event).id;
                var item;
             resultsArray.forEach(function (ftr) {
                    if (ftr.attributes.OBJECTID === idx){
                         item = ftr;
                    }
             });
             console.log(item);

               var cntr = [];
               cntr.push(item.geometry.longitude);
               cntr.push(item.geometry.latitude);

                app.view.goTo({
                  center: cntr,     // position:
                  zoom: 13
                });

                app.view.graphics.removeAll();
                  var graphic = new Graphic({

                    geometry: item.geometry,
                    symbol: new SimpleMarkerSymbol({
                       //color: [0,255,255],
                       style: "circle",
                       //size: "8px",
                       outline: {
                            color: [255,255,0],
                            width: 3
                       }
                  })
                });

                app.view.graphics.add(graphic);


                // open the popup, assign its attributes and location
                app.view.popup.open({
                  features: [item],

                  location: item.geometry
                });

}, );

    }  // end if

});
0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Jay,

   So when you click on a row in the dgrid it does open the popup, but does not trigger your watch util.

0 Kudos
JayHill
Occasional Contributor II

It triggers the watchUtil but the relationQuery on line 17 above, doesnt return the objectID for the rest of the code to work.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Jay,

   Are you talking about line 6 and 7 in your original code posted?

0 Kudos
JayHill
Occasional Contributor II

no line 17 in my original code. the console log on line 21 doesnt return an objectID.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

OK, But does line 6 in your original print the objectid to the console when click on the row in the dgrid? I need to know if the related query parameters are getting set properly?

0 Kudos
JayHill
Occasional Contributor II

yes it does. as well as line 16. line 16 just puts it in an array

  1. {__accessor__: b}
    1. definitionExpression:(...)
    2. geometryPrecision:(...)
    3. maxAllowableOffset:(...)
    4. objectIds:Array(1)
      1. 0:3048
      2. length:1
      3. __proto__:Array(0)
0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Does the console output look identical to above then clicking on the map?

0 Kudos