1

I have a simple app built using the 3.16 API that includes a flat table (so no spatial attributes) using the Feature Table widget. Can I select rows by attribute rather than just by the user clicking on a row? For example, if I wanted the table to display only rows where the "State" field equals 'California' when its initially loaded, but the user could choose to clear the selection to see all rows if desired? Or would I be better off setting a query on the feature layer that the table is built from?

My code is below.

require([
    "esri/map",
    "esri/urlUtils",
    "esri/arcgis/utils",
    "esri/layers/ArcGISDynamicMapServiceLayer",
    "esri/layers/FeatureLayer",
    "esri/layers/LOD",
    "esri/layers/LayerInfo",
    "esri/dijit/FeatureTable",

    "dojo/dom",
    "dojo/_base/array",
    "dojo/ready",
    "dojo/parser",
    "dojo/on",
    "dojo/domReady!",

    "esri/IdentityManager"
],

function (Map, urlUtils, arcgisUtils, ArcGISDynamicMapServiceLayer, FeatureLayer, LOD, LayerInfo, 
      FeatureTable, dom, rrayUtils, ready, parser, on) {

    // Wait until DOM is ready *and* all outstanding require() calls have been resolved
    ready(function () {

    // Parse DOM nodes decorated with the data-dojo-type attribute
    parser.parse();

    //create a regular plain old map
    var mapMain = new Map("mapDiv", {
        basemap: "topo",
        center:  [-117.4, 33.3], //[-120, 38],
        zoom: 11,  
        showLabels: true
    });

    mapMain.on("load", function() {loadTable(mapMain); });

    function loadTable(myMap){
    console.log("Here comes a table.")

    // Create the feature layer
    myFeatureLayer = new FeatureLayer("https://data.farwestern.com/arcgis/rest/services/scratch/test_SD_RelatedResources/MapServer/2", {
        mode: FeatureLayer.MODE_ONDEMAND,
        visible: true,
        outFields: ["*"]
    });

    mapMain.addLayer(myFeatureLayer)

    // Create the feature table
    myFeatureTable = new FeatureTable({
        featureLayer : myFeatureLayer,
        outFields: ["State", "County", "Name"],
        map : myMap,
        gridOptions: {
        allowSelectAll: true,
        allowTextSelection: true,
        selectionMode: "extended"
        },
        syncSelection : false
    }, 'tableDiv');
    myFeatureTable.startup();
        }

  });
});
  • "Or would I be better off setting a query on the feature layer that the table is built from?" Sounds like you already have a good idea on what you need to do. This option has my vote. – Mintx Jun 16 '16 at 20:41
  • 1
    For those interested, I resolved this issue by performing a query to get the ids of rows that met my criteria, and then performing a select on the table for those ids. I used the code provided by Robert Scheitlin on this thread over at geonet as an example to get it working. geonet.esri.com/thread/174610 – geobug Jun 21 '16 at 2:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.