changing definitionExpression on client side feature layer doesn't work. 4.3 Bug?

1578
5
05-04-2017 05:26 AM
BrandonFlessner
Occasional Contributor

I'm trying to filter features on a feature layer that is created from client side graphics. When I set the definitionExpression, the layer does not update.

To replicate, use this sample, then add 

document.getElementById('filter').addEventListener('change', function(e){
        if (e.target.checked){
          lyr.definitionExpression = "mag < 2";
        } else {
          lyr.definitionExpression = "";
        }
        console.log(lyr.definitionExpression);
      });‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

immediately below the errback function and 

<div style="position:absolute; top: 15px; right: 15px; color: #fff;"><label><input type="checkbox" id="filter" > Filter</label></div>

in the body of the html. When you click the checkbox, the definitionExpression is updated, but the view is not. 

From the docs

If the definition expression is set after the layer has been added to the map, the view will automatically refresh itself to display the features that satisfy the new definition expression.

Can anyone confirm if this is a bug or if I'm making some other mistake?

Note that in my test application I was able to get this to work when the feature layer was constructed using a url instead of client side data.

0 Kudos
5 Replies
KenBuja
MVP Esteemed Contributor

Take a look at this discussion: https://community.esri.com/message/613497 

It looks like you can't use a definitionExpression on a FeatureLayer created from graphics.

BrandonFlessner
Occasional Contributor

Thanks for your reply Ken. The docs referenced in that discussion appear to be from the 3.20 version. I can't find any documentation in the 4.3 docs that say you can't do this. However, I believe you are correct. It's likely just the docs that need updating, or maybe I'm looking in the wrong place.

For now I'll loop through my graphics array manually. Seems like the API should handle this for me with a definitionExpression ...

0 Kudos
KristianEkenes
Esri Regular Contributor

You are correct. The docs need updating. We'll take care of that for our next release. Thanks for pointing this out. As far as supporting this functionality for client-side FL, we have it on our radar and plan on adding support for it. No timetable yet though.

DylanHowell
New Contributor

Has the client side definitionExpression functionality been added yet?

Thanks

-Dylan

0 Kudos
JackFairfield
Occasional Contributor II

I also would love to have this feature.  Any updated timetable on this functionality?  Or can you provide a workaround?

0 Kudos