Feature table and query results

733
2
03-15-2019 04:52 AM
MarkBalman
Occasional Contributor

Hi all

Wondering if anyone can assist with how to display query results to a feature table? I have searched pretty much everything I can find but just cannot get this to work - I am beginning javascript and I am stumped as to how to get the query results to display in the feature table. I am using the Toolbar function to allow a user to draw a shape and select the features they want. These are the results I want to display. At the moment I can draw a shape and select the features I want and can see that these are returned in the console log but all features in the table are displaying in the table and not the subset. If I use a definition query to subset the layer then only those are displayed. If anyone has any suggestions I would be really grateful. I am using the feature table option as I like the way this handles related tables but happy to adopt other methods such as dgrid if anyone can point me in the right direction.

Some of my code follow - (am using 3.27 api version)

var featureLayer = new FeatureLayer("http://localhost:6080/arcgis/rest/services../MapServer/2",{
mode: FeatureLayer.MODE_ONDEMAND,
showRelatedRecords: true,
//definitionExpression: "objectid in (1176,1184)",
outFields: ["*"]
});

function initToolbar() {
tb = new draw(map);
tb.on("draw-end", addGraphic);

// event delegation so a click handler is not
// needed for each individual button
on(dom.byId("info"), "click", function(evt) {
if ( evt.target.id === "info" ) {
return;
}
var tool = evt.target.id.toLowerCase();
map.disableMapNavigation();
tb.activate(tool);
});
}

function addGraphic(evt) {
map.graphics.clear();
//deactivate the toolbar and clear existing graphics
tb.deactivate();
map.enableMapNavigation();

// figure out which symbol to use
var symbol;
if ( evt.geometry.type === "point" || evt.geometry.type === "multipoint") {
symbol = markerSymbol;
} else if ( evt.geometry.type === "line" || evt.geometry.type === "polyline") {
symbol = lineSymbol;
}
else {
symbol = fillSymbol;
}

map.graphics.add(new graphic(evt.geometry, symbol));
queryMapService(evt.geometry);
}


//working code
function queryMapService(Geom){
var promises = [];
var featureId = [];
var query = new Query();
query.returnGeometry = false;
query.objectIds = [featureId];
//query.where = "1=1";
query.outFields = ["*"];
query.geometry = Geom;

promises.push(featureLayer.selectFeatures(query, FeatureLayer.SELECTION_NEW));

var allPromises = new All(promises);
allPromises.then(function (r) {
console.log(r);
//r is an array of stuff
loadTable(r);
});
}

//Array of stuff
function loadTable(results){
var objectIds = objectIds;
var featureTable = new FeatureTable({
featureLayer : featureLayer,
map : map,
syncSelection: false,
showRelatedRecords: true,
showAttachments: true,
outFields: ["NatName"],
}, 'myTableNodeSites');

featureTable.selectedRowIds = objectIds;
featureTable.filterSelectedRecords(true);
featureTable.startup();
}

Thanks in advance,

Mark

0 Kudos
2 Replies
RobertScheitlin__GISP
MVP Emeritus

Mark,

   Have you seen this dGrid sample?

dgrid | ArcGIS API for JavaScript 3.27 

0 Kudos
MarkBalman
Occasional Contributor

Hi Robert

Many thanks for this, as much as I have looked at pretty much all the examples I cannot seem to find anything to help me work out how to return the results of a query (user defined shape) and put these into a table that also shows related records. Lack of knowledge on my behalf but slowly getting there.

Thanks again,

Mark

0 Kudos