Is there any way to edit attributes on the client side of a hosted feature layer in the JS API 4.15

93
4
05-28-2020 12:31 AM
Highlighted
New Contributor

I have made an app where a certain score is given to an area based on parameters. And to give the score to that area a calculation is made and the score has to written into the attribute table of the layer. That way i can edit the symbology of the area based on that score in the attribute table. But all of the ways to edit in the layer seem to update the layer itself. I want to do the edits in the client itself. Therefore no changes are made in the layer and when the page is reloaded the layer is reset. Is there a way to accomplish this?

Tags (2)
Reply
0 Kudos
4 Replies
Highlighted
MVP Esteemed Contributor

Guus,

   Is it a vary large dataset? If it is not to large then you can create a client side feature layer using a a graphics source. Just use a queryTask to get the layers graphics.

https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#client-s... 

This way it is an isolated client side copy of your layer.

Reply
0 Kudos
Highlighted
New Contributor

Hi Robert,

Thank you for your response, it is not a big dataset. It's only all the neighborhoods of a municipality. Around 100 features. I'm going to try your idea, thank you. 

Reply
0 Kudos
Highlighted
New Contributor

Hi Robert, it worked perfectly thank you very much. I am now struggling to edit the attribute table of the new layer. When I try to use the applyEdit() method I keep getting the error that the objectID identifier field is missing. But I transferred it to the new layer.

Here is some code, if you can take a look at it that would be amazing:

"p" is  an integer that represents a objectid

"Score" is the field of "p" which i'm trying to edit

Thanks in advance

sectorenLayer.applyEdits({
                    updateFeatures: [{
                        attributes: {ObjectID: p, Score: endScore}
                    }]
                }).then(function(response){
                    console.log(response)
                })
Reply
0 Kudos
Highlighted
MVP Esteemed Contributor

Guus,

   Normally you would get the feature (graphic) and update the attribute of Score and add that whole graphic to an array to pass to the updateFeatures method. They way you are attempting will not work (passing a simple object that has an attribute property).

Reply
0 Kudos