This sample demonstrates how to add a table list and view a table's data in the feature table component.
In this example, two FeatureLayer tables are displayed in the table list. One table is saved within a WebMap, while the other is added programmatically in the app by calling the Layer.fromPortalItem method and passing in the item
of the associated hosted table. Selecting one of the tables in the table list will display the table's data in the feature table component.
In order for the component to recognize if a table is valid, the feature layer's isTable property must return true
.
When a table is loaded dynamically, it must first be loaded and then added to the map's tables collection.
// A function to add a table to the map and feature table
// from a portal item id
async function addTable(id) {
const table = await Layer.fromPortalItem({
portalItem: new PortalItem({
id
})
});
// Wait for the table to load
await table.load();
// If the table is a table,
// set the title and add it to the map and feature table
if (table.isTable) {
table.title = "Table from portal item";
arcgisMap.addTable(table);
arcgisFeatureTable.layer = table;
}
}