FeatureTable component

This sample demonstrates how to use the FeatureTable component to display attribute data from FeatureLayers within a webmap. The table's visible columns and order are saved within the webmap's JSON (i.e. in the AttributeTableInfo object) which maps to the layer's attributeTableTemplate. These settings are automatically recognized and honored when displayed by the feature table. By default, the name of the relationship column displays whatever is set on the underlying feature service's relationship name. This sample updates the relationship column name by setting its corresponding AttributeTableTemplate's relationship element label.

The FeatureTable component is added to the app as shown below. Take note of the reference-element, show-layer-dropdown, related-records-enabled, and hide-selection-column attributes. Setting the reference element to the map enables highlighting corresponding features in the map once selected in the table. Next, setting the layer dropdown to display adds the ability to toggle layers on the table. Setting the related-records-enabled attribute allows any related records to display within the table. Lastly, by setting hide-selection-column hides the selection column in the table.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
        <arcgis-feature-table
          reference-element="arcgis-map"
          show-layer-dropdown
          related-records-enabled
          hide-selection-column
        ></arcgis-feature-table>

Listen for the map to be ready. Once ready, iterate through the layers and find the layer titled "Region" and initialize. This is the layer that will display upon loading the table. If the layer's relationship id and its corresponding relationship element's id match, we update the element's label.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
          arcgisMap.addEventListener("arcgisViewReadyChange", async () => {
            const layers = arcgisMap.map.layers.items;

            await Promise.all(
              layers.map(async (layer) => {
                await processLayerRelationships(layer);
                if (layer.title === "Region") resolve(layer);
              })
            );
          });
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
      const processLayerRelationships = async (layer) => {
        // Ensure the layer is loaded
        if (!layer.loaded) await layer.load();

        // Check if the layer has relationships and an attribute table template.
        if (layer.relationships?.length > 0 && layer.attributeTableTemplate?.elements) {
          for (const element of layer.attributeTableTemplate.elements) {
            if (element.type === "relationship") {
              // Match the relationship by ID and update its label.
              const matchingRelationship = layer.relationships.find((rel) => rel.id === element.relationshipId);

              // Update the relationship name and display within the column's label.
              if (matchingRelationship) {
                const prefix = matchingRelationship.name.split("_")[0];
                element.label = `Related to: ${prefix}`;
              }
            }
          }
        }
      };

We then initialize the component with the layer to initially display. The MapViewer table's action column does not persist in the table's AttributeTableTemplate. Set an ActionColumn on it.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
        table.layer = regionLayer;

        // Add a custom action column for main table.
        table.actionColumnConfig = {
          label: "Go to feature",
          icon: "zoom-to-object",
          callback: (event) => arcgisMap.goTo(event.feature)
        };

Lastly, we listen for when a related table is available and configure properties for its display.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
        reactiveUtils.when(
          () => table.relatedTable,
          (relatedTable) => {
            // Configure the related table.
            relatedTable.visibleElements.columnMenus = false;
            relatedTable.visibleElements.selectionColumn = false;

            // Add a custom action column for related tables.
            relatedTable.actionColumnConfig = {
              label: `Go to ${relatedTable.layer.title} feature`,
              icon: "zoom-to-object",
              callback: (event) => arcgisMap.goTo(event.feature)
            };
          }
        );

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.