I have an application with a query task that I configured with AGOL WebAppBuilder. I have a simple CONTAINS query that selects all features that contain a certain value of an attribute. How can I adjust the JS so that the features which are NOT selected are not shown when I the query is executed? Is this possible/practical using WebAppBuilder
First, i think you will need to use Web app builder developer edition, which is easier for customizing purpose.
And if you have developer version, you can actually modify the widget.js file inside the widgets\Query folder.
I think there might be several steps to achieve it:
1. you could find where it is getting the response of the query, then you can get all the selected features from response.features.
2. you could build an array of the objectids from all the response.features.
3. then setDefinitionEXpression based on the objectids, for example:
this.map.itemInfo.itemData.operationalLayers.layerObject.setDefinitionExpression("objectid=1 or objectid =2");
There might be other tons of better ways to do that though.
One option is to get the eSearch widget and configure the widget for that layer and make sure that layer is not part of your map. The eSearch does not require the searched layer to be part of the map and thus the result graphics will only be those that match the search criteria.
I don't quite understand. I am executing the search against a layer that is a part of the map. I am familiar with the search widget, however, not the eSearch widget.
There are several custom widgets out there for users of WAB Dev edition. The eSearch is one of them. If you have a web map that already has the layer as part of the map then your only options are to do as Chen suggests or add the eSearch and turn off that layer in the map that way the results of the eSearch will only show the searched results on the map.