Select to view content in your preferred language

Not working: FeatureTable using Client-Side FeatureLayer with applyEdits

330
3
Jump to solution
08-19-2024 02:36 PM
ForrestLin
Frequent Contributor

I'm trying to use FeatureTable with Client-Side FeatureLayer

1. Create Client-Side FeatureLayer with empty source:

      const featureLayer = new FeatureLayer({

                  source: [], //empty 
                 geometryType: 'polygon',
                 objectIdField: "OBJECTID",
                 spatialReference,
                 editingEnabled: true,
                // .....

        });

2. Add it to map layer:

        view.map.add(featureLayer);

3. Create FeatureTable with featureTable 

       const featureTable = new FeatureTable({
              layer: featureLayer,
               view,
               container,
               returnGeometryEnabled: true,
               editingEnabled: true,
              // ...
        });
 
4. Add features to featureLayer using applyEdits
         const edits = {
              addFeatures: graphics  // will add 5 graphics
          };
         featureLayer.applyEdits(edits)
            .then(editsResult => {
              console.log(editsResult.addFeatureResults.length);  // 5
              console.log(featureLayer.source.length);                     // 0
         });

I got:
       editsResult.addFeatureResults.length = 5;
       featureLayer.source.length = 0;
 
The featureTable has no record, because featureLayer.source is still [] (empty).
 
ForrestLin_0-1724155888658.png

 

Forrest

0 Kudos
2 Solutions

Accepted Solutions
UndralBatsukh
Esri Regular Contributor

Hi there, 

I replied on your other thread about not using FeatureLayer.source it is initialized. As for FeatureTable, please call FeatureTable.refresh() once your edits are completed. Here is a codepen showing this workflow - https://codepen.io/U_B_U/pen/PorRwbM?editors=100

View solution in original post

0 Kudos
ForrestLin
Frequent Contributor

It works after calling featureTable refresh method in 

featureLayer.applyEdits(edits)
      .then( editsResult => {
           featureTable.refresh();
       });

View solution in original post

0 Kudos
3 Replies
UndralBatsukh
Esri Regular Contributor

Hi there, 

I replied on your other thread about not using FeatureLayer.source it is initialized. As for FeatureTable, please call FeatureTable.refresh() once your edits are completed. Here is a codepen showing this workflow - https://codepen.io/U_B_U/pen/PorRwbM?editors=100

0 Kudos
ForrestLin
Frequent Contributor

@UndralBatsukh 

Thank you!

Issue is resolved.

Forrest

0 Kudos
ForrestLin
Frequent Contributor

It works after calling featureTable refresh method in 

featureLayer.applyEdits(edits)
      .then( editsResult => {
           featureTable.refresh();
       });
0 Kudos