AnsweredAssumed Answered

Can I populate a FeatureTable with a FeatureLayer built from a query and a featureCollection?

Question asked by vandervoort on Jan 29, 2015
Latest reply on Jan 30, 2015 by khutchins-esristaff

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.

Outcomes