AnsweredAssumed Answered

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

Question asked by bflessner on May 4, 2017
Latest reply on Jul 17, 2018 by Jefairfi

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.

Outcomes