Select to view content in your preferred language

Feature Table doesn't show records

1450
3
Jump to solution
05-07-2018 05:28 AM
MKF62
by
Regular Contributor

I've never created a feature table before so I'm sure I'm just missing something small, but when I implement the Feature Table widget it loads in the appropriate place but doesn't show any records. I've tried a few different things, but nothing has worked yet. 

Currently, my code looks like this:

//Add the habitat patches feature layer
var patchesFL = new FeatureLayer("URL", {
    refreshInterval: 10,
    definitionExpression: 'EXTRACT(YEAR FROM "ObsvDate") = ' + currentYear,
    visible: false,
    infoTemplate: patchesPopupBox,
    outFields: ["*"]
});
patchesFL.setMinScale(500000);

//Add the feature layers to the map object
map.addLayer(patchesFL);

//Create attribute table
var attrTable = new FeatureTable({
    featureLayer: patchesFL,
    editable: false,
    outFields: ["StateID", "Point", "PatchNum", "IsDeveloped", "CropTypeID", "CropResidue", "CnpyOver12",
        "CnpyDecid", "CnpyConif", "ShrubCover", "ShbHiStemsDens", "GrassCover", "ForbCover",
        "FrbAsProtect", "ForbSpecies", "BareGround", "HerbHeight", "Overstory",
        "Understory", "OfficialQH", "ObsvDate", "ObsvType"],
    map: map
}, "attribute-table");
attrTable.startup();

I have attempted to add this line because I saw it in a bunch of examples, and changed the visibility property to true when instantiating the feature layer:

mode: FeatureLayer.MODE_ONDEMAND,

I have also tried changing the feature table options to be in quotes because I found it done both ways in the documentation and wasn't sure which was right:

//Create attribute table
var attrTable = new FeatureTable({
    "featureLayer": patchesFL,
    "editable": false,
    "outFields": ["StateID", "Point", "PatchNum", "IsDeveloped", "CropTypeID", "CropResidue", "CnpyOver12",
        "CnpyDecid", "CnpyConif", "ShrubCover", "ShbHiStemsDens", "GrassCover", "ForbCover",
        "FrbAsProtect", "ForbSpecies", "BareGround", "HerbHeight", "Overstory",
        "Understory", "OfficialQH", "ObsvDate", "ObsvType"],
    "map": map
}, "attribute-table");
attrTable.startup();‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

None of these changes have affected anything. I have made sure to zoom into my map to the appropriate extent where the feature layer is visible to see if that did the trick, it doesn't. 

Do I need to have records selected in order for anything to show up in the table? This is what I get when the map loads, you can see the Feature Table widget exists based on the ability to turn on/off fields but no records show up:

0 Kudos
1 Solution

Accepted Solutions
MKF62
by
Regular Contributor

Alright, I figured it out. Was something stupid I was doing as per usual . When I instantiate the map, there is a drop-down menu that will set the definition expression on the layer. The definition expression by default is set to show data from the current year, but we don't have any data for the current year yet. When I was picking a new year (a year that has data), I figured the table would automatically update, but I found you actually need to use the refresh method. Once I implemented attrTable.refresh(); in the function where the definition expression for the feature layer gets updated, it started populating with records. I still can't figure out why the header and column names won't show though upon load...

The CSS is just this:

#attribute-table{
    display: none;
    position: absolute;
    height: 500px;
    background-color: white;
    bottom: 0;
    z-index: 31;
}
‍‍‍‍‍‍‍‍

View solution in original post

0 Kudos
3 Replies
RobertScheitlin__GISP
MVP Emeritus

Molly,

  Are there any errors in the browsers console? Have you tried to remove the field property for testing?

//Create attribute table
var attrTable = new FeatureTable({
    featureLayer: patchesFL,
    editable: false,
    map: map
}, "attribute-table");
attrTable.startup();
0 Kudos
MKF62
by
Regular Contributor

No errors in the console and I just removed the fields option, but still no dice. It is interesting though when I open the console, suddenly the header and column names show up in the div when they don't initially on load. That's probably more of a CSS issue though.

After I open the console and it resizes my map:

0 Kudos
MKF62
by
Regular Contributor

Alright, I figured it out. Was something stupid I was doing as per usual . When I instantiate the map, there is a drop-down menu that will set the definition expression on the layer. The definition expression by default is set to show data from the current year, but we don't have any data for the current year yet. When I was picking a new year (a year that has data), I figured the table would automatically update, but I found you actually need to use the refresh method. Once I implemented attrTable.refresh(); in the function where the definition expression for the feature layer gets updated, it started populating with records. I still can't figure out why the header and column names won't show though upon load...

The CSS is just this:

#attribute-table{
    display: none;
    position: absolute;
    height: 500px;
    background-color: white;
    bottom: 0;
    z-index: 31;
}
‍‍‍‍‍‍‍‍
0 Kudos