Web AppBuilder for ArcGIS (Developer Edition)

Filter class

The Filter class constructs complicated SQL query statements by UI operations to filter features from the feature layer or stream layer. It supports String, Number, and Date fields.

AMD Module Require

require(["jimu/dijit/Filter"], function(Filter) { /* code goes here */ });

Constructor

new Filter(params, srcNodeRef)

Creates a new Filter dijit.

Parameters:

<Object> params—Optional. Parameters for the Filter dijit.

<DOMNode | String> srcNodeRef—Optional. HTML element where Filter is rendered.

params properties:

<String> noFilterTip—Optional. Shows the ToolTip when no filters are added.

Example:

require(['jimu/dijit/Filter'], function(Filter){
        var url = "http://sampleserver6.arcgisonline.com/arcgis/rest/services/SampleWorldCities/MapServer/0";
        var filter = new Filter();
        filter.placeAt(filterDiv);
        filter.buildByExpr(url, "1=1");
      });

Methods

reset()

Removes all filters and resets the Filter dijit to the original status.

toJson()

Gets the filter JSON information using the UI settings.

Return type: Object. The returned value contains the SQL query statement.

Example:

var partsObj = filter.toJson();
 if(partsObj && partsObj.expr){
    console.log("SQL query statement:", partsObj.expr);
    }

buildByExpr(url,sql)

Parses the SQL query statement and builds the UI for the Filter dijit.

Return type: Deferred object. When it resolves, the build process is done.

Parameters:

<String> url—Required. The REST service URL.

<String> sql—Optional. The SQL query statement the Filter dijit will parse. If you don't pass it, the default value is '1=1', which means no filters. If you pass an invalid SQL query statement, it may throw an exception. To make sure you pass a valid SQL query statement, get the SQL expression from the toJson method of the Filter dijit.

buildByFilterObj (url, partsObj)

Builds the UI for the Filter dijit by JSON, which includes the filter information.

Return type: Deferred object. When it resolves, the build process is done.

Parameters:

<String> url—Required. The REST service URL.

<String> partsObj—Required. The partsObj format is the same as the returned value of the toJson method. Practically, you should not construct this object by yourself, but call the toJson method to get the partsObj parameter and save it in memory or a file. In this way, you can pass parsObj into the method and build the UI for the Filter dijit so that a user can see the same Filter UI again.