[GIS] How to Set a feature layer Editable? (without Editor widget)

arcgis-javascript-apiarcgis-server

I'm new to arcgis JS api, now I want to update the whole records in a specific field of the feature layer, but I don't want to use the Editor Widget, is it possible? How to set the layer editable?
I did some research about using ApplyEdit() method, but still confuse about it.
Can anyone give me some hints or code examples? Thanks in advance!

Best Answer

you don't really do anything specific in your code to set a featureLayer to be editable. if the url of the service you supply supports the applyEdits operation (as visible near the bottom of the layer's REST endpoint), then it will be possible to edit the feature layer.

in the sample below you can see that a click event is wired to delete features without relying on a widget. we check to see if the CTRL key is down before calling applyEdits() with a graphic as the third argument. https://developers.arcgis.com/en/javascript/jssamples/ed_feature_creation.html

if you just want to update an existing feature, all you need to do is get a reference to a specific graphic, update its attributes, and then pass the same graphic to applyEdits() as the second argument (to update).

applyEdits(adds?,updates?,deletes?,callback?,errback?) https://developers.arcgis.com/en/javascript/jsapi/featurelayer-amd.html#applyedits