I have a FeatureLayer in my map. I want to query the FeatureLayer and display the results in a esri.dijit.FeatureTable (ie., a subset of the graphics in the FeatureLayer need to be used to populate the FeatureTable). Those are the requirements. Simple, right. What am I missing???
Querying the FeatureLayer directly returns a TypeError: cyclic object value so I can't even create the FeatureLayer to hydrate the FeatureTable with.
The code:
var myQuery = new Query();
myQuery.returnGeometry = true;
myQuery.where = "1=1";
myFeatureLayer.queryFeatures(myQuery,function(queryResults) {
var layerDefinition = {
"geometryType": queryResults.geometryType,
"fields": queryResults.fields
};
var layerDefinition = {
"geometryType": queryResults.geometryType,
"fields": queryResults.fields
};
var featureCollection = {
layerDefinition: layerDefinition,
"featureSet": {
"features": queryResults.features,
"geometryType": queryResults.geometryType
}
};
var featureLayer = new FeatureLayer(featureCollection, {
mode: esri.layers.FeatureLayer.MODE_SNAPSHOT
});
alert("GOT FSET");
});
Using a QueryTask with the url of the FeatureLayer (thus creating round-trips to the server) doesn't work either and errors with Error: FeatureLayer::_query - query contains one or more unsupported parameters:
var queryTask = new QueryTask(myFeatureLayer.url);
var query = new Query();
query.where = "1=1";
queryTask.execute(query, function(queryResults) {
var layerDefinition = {
"geometryType": queryResults.geometryType,
"fields": queryResults.fields
};
var layerDefinition = {
"geometryType": queryResults.geometryType,
"fields": queryResults.fields
};
var featureCollection = {
layerDefinition: layerDefinition,
"featureSet": {
"features": queryResults.features,
"geometryType": queryResults.geometryType
}
};
var featureLayer = new FeatureLayer(featureCollection, {
mode: esri.layers.FeatureLayer.MODE_SNAPSHOT
});
myTable = new FeatureTable({
"featureLayer" : featureLayer,
"map" : map
}, 'myTableNode');
myTable.startup();
alert("GOT queryResults");
});
And yes, I know the FeatureTable is in beta at 3.12. And yes, I can already do this in Silverlight and Flex.
Dirk,
You can do this using query on the grid property of the FeatureTable. So if I wanted to display only records where the the common name equaled 'Snowdrop tree' I could setup a query as follows:
myTable.on("load", function(){ myTable.grid.set("query", { "Cmn_Name": "Snowdrop tree"}); });
To clear the query do the following:
myTable.grid.set("query", []);
More complex queries can be created using regular expressions. Here's an example
myTable.grid.set("query", { "Spp_Code": new RegExp("ba", 'i')}); // show all rows where the value for Spp_Code contains the letters ‘ba’
More details can be found in the following dojo dgrid tutorial
Using Grids and Stores - dgrid Tutorial
Finally if you want to then select the associated features in your feature layer you can use the FeatureLayer's selectFeatures method. Here's a link to a sample that shows this in action:
One note about your dGrid tutorial link, Kelly Hutchins. You're pointing to the 0.4 version, but the JSAPI v3.12 uses dGrid 0.3.16. There are some difference, notably in the second paragraph.
Starting with 0.4 dgrid interfaces directly with dstore stores.
You should link to the 0.3 version.
Good point Ken. Thanks for adding the link to the correct version.