<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<title>FeatureTable with popup interaction | Sample | ArcGIS Maps SDK for JavaScript</title>
<link rel="stylesheet" href="https://js.arcgis.com/5.0/esri/themes/light/main.css" />
<!-- Load the ArcGIS Maps SDK for JavaScript from CDN -->
<script type="module" src="https://js.arcgis.com/5.0/"></script>
.esri-popup--is-docked-top-right .esri-popup__main-container {
-webkit-transition: 0.4s;
-webkit-transition: 0.4s;
input:checked + .slider {
background-color: #2196f3;
box-shadow: 0 0 1px #2196f3;
input:checked + .slider:before {
-webkit-transform: translateX(20px);
-ms-transform: translateX(20px);
transform: translateX(20px);
const [WebMap, MapView, FeatureLayer, FeatureTable, reactiveUtils] = await $arcgis.import([
"@arcgis/core/WebMap.js",
"@arcgis/core/views/MapView.js",
"@arcgis/core/layers/FeatureLayer.js",
"@arcgis/core/widgets/FeatureTable.js",
"@arcgis/core/core/reactiveUtils.js",
const webmap = new WebMap({
id: "209aa768f537468cb5f76f35baa7e013",
const view = new MapView({
// When view is ready, find feature layer and set title and outFields
const featureLayer = webmap.findLayerById("OverlaySchools_2862");
featureLayer.title = "US Private school enrollment";
featureLayer.outFields = ["*"];
// Get references to div elements for toggling table visibility
const appContainer = document.getElementById("appContainer");
const tableContainer = document.getElementById("tableContainer");
const tableDiv = document.getElementById("tableDiv");
const featureTable = new FeatureTable({
view: view, // make sure to pass in view in order for selection to work
// autocasts to TableTemplate
// takes an array of GroupColumnTemplate and FieldColumnTemplate
// autocasts to FieldColumnTemplate
fieldName: "PercentagePrivate",
label: "Private school percentage",
fieldName: "PercentagePublic",
label: "Public school percentage",
// Add toggle visibility slider
view.ui.add(document.getElementById("mainDiv"), "top-right");
// Get reference to div elements
const checkboxEle = document.getElementById("checkboxId");
const labelText = document.getElementById("labelText");
// Listen for when toggle is changed, call toggleFeatureTable function
checkboxEle.onchange = () => {
function toggleFeatureTable() {
// Check if the table is displayed, if so, toggle off. If not, display.
if (!checkboxEle.checked) {
appContainer.removeChild(tableContainer);
labelText.textContent = "Show Feature Table";
appContainer.appendChild(tableContainer);
labelText.textContent = "Hide Feature Table";
// Watch for the popup's visible property. Once it is true, clear the current table selection and select the corresponding table row from the popup
() => view.popup.viewModel?.active,
selectedFeature = view.popup.selectedFeature;
if (selectedFeature !== null && view.popup.visible !== false) {
featureTable.highlightIds.removeAll();
featureTable.highlightIds.add(view.popup.selectedFeature.attributes.OBJECTID);
id = selectedFeature.getObjectId();
<div id="tableContainer" class="container">
<div id="tableDiv"></div>
<div id="mainDiv" class="esri-widget">
<input id="checkboxId" type="checkbox" checked="yes" />
<span class="slider round"></span>
<label class="labelText" id="labelText">Hide feature table</label>