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();
        var options = {
           url: ***,
           partsObj: ***,
           ...
        };
        filter.placeAt(filterDiv);
        filter.build(options);
      });

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);
    }

build(options)

Builds the UI for the Filter dijit by JSON (which includes the filter information) or 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> 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.

<String> expr—Optional. The SQL query statement that 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.

Note:

The partsObj or expr parameter is required; partsObj has priority.

<Object> layerDefinition—Optional. The structure is the same as the information returned by REST for a layer in a feature service or map service.

<String> featureLayerId—Optional. The ID of the current feature layer.

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.