Class Criterion

java.lang.Object
com.smartgwt.client.docs.serverds.Criterion

public class Criterion extends Object
An object representing a criterion to apply to a record.

This class is not meant to be created and used, it is actually documentation of settings allowed in a DataSource descriptor (.ds.xml file), for use with Smart GWT Pro Edition and above. See com.smartgwt.client.docs.serverds for how to use this documentation.

A criterion is part of the definition of an AdvancedCriteria object, which is used to filter records according to search criteria.

A criterion consists of an operator and typically a fieldName from a Record and a value to compare to. However some operators either don't require a value (eg, isNull) or act on other criteria rather than directly on a Record's fields (eg, the "and" and "or" logical operators). Also, it is possible to specify a fieldQuery instead of a fieldName and/or a valueQuery instead of a value

A shortcut form is also allowed where only fieldName and value values are provided. In this case the operator is assumed to be "equals".

  • Field Details

    • operator

      public OperatorId operator
      Operator this criterion applies.

      Default value is null

      See Also:
    • fieldName

      public String fieldName
      Name of the field in each Record that this criterion applies to. Not applicable for a criterion with sub-criteria. Can be specified as a dataPath to allow matching nested objects. Use '/' as delimiters for dataPath. See dataPath for more information.

      fieldQuery shortcuts

      fieldName can also be used to express a compact form of related-field filtering. If you set this property to the qualified name of a field on a related DataSource, it will be transformed into a basic AdvancedCriterionSubquery. For example, say you have an Order dataSource, which has a foreign key relation to your Customer dataSource, and your Customer dataSource has a "region" field. If you wanted to fetch all Orders for Customers in the EMEA region, you could declare criteria like this:
           {fieldName: "Customer.region", operator: "equals", value: "EMEA"}
        
      This would be transformed into a subquery filter that would select only the records you want:
        {
             fieldQuery: {
                 dataSource: "Customer",
                 queryOutput: "region"
             }, operator: "equals", value: "EMEA"
        }
        
      The full includeVia syntax is supported, including disambiguation when multiple foreign keys point to the same DataSource and multi-hop paths. See the includeVia docs for full details.

      Aggregation shorthand

      The same shorthand also supports aggregation across a related DataSource, using #-prefixed function names. For example, if an Order has many OrderLine records (linked by foreign key), you can filter on aggregates of those line items:
      • OrderLine.#count — count of related OrderLine records
      • OrderLine.amount.#sum — sum of the amount field across related records (also #max, #min, #avg)
      Example: fetch Orders that have more than 5 line items:
           {fieldName: "OrderLine.#count", operator: "greaterThan", value: 5}
        
      This expands to a fieldQuery with summaryFunctions and is evaluated on both client and server.

      See the AdvancedCriterionSubquery overview linked above for more details of the extremely powerful subquery filtering options.

      When criteria are evaluated against a rule context (as with FormItem.visibleWhen, Canvas.enableWhen, or a dynamic property), fieldName as a dataPath also accepts . as a segment separator in addition to /, with no difference in behavior -- see Canvas.provideRuleContext(). Dot-separated paths such as "grid.selectedRecord.name" are preferred in this context.

      The dot-notation syntax for related DataSource fields is formally described at RelationalReference. For the full set of dynamic references available in validators and field properties (including auth.*, context.*, values.*), see ServerDynamicCriteria.

      Default value is null

      See Also:
    • valueQuery

      public AdvancedCriterionSubquery valueQuery
      A subquery to use instead of a value. When you use a valueQuery instead of a value, you are comparing the values in the record field named in the criterion fieldName to the result of running a per-record subquery, rather than a literal scalar value. . Note, it is also possible to specify both a valueQuery and a fieldQuery.

      See the subquery overview for more details of the criteria subquery feature, and examples of use.

      Note, if you specify both valueQuery and value in a criterion, we use the value and the valueQuery is ignored

      valueQuery is supported for client-side filtering of clientOnly DataSources, MockDataSources, and DataSources with a complete cache. See the "Client-Side Subquery Support" section in the subquery overview for details.

      Default value is null

      See Also:
    • fieldQuery

      public AdvancedCriterionSubquery fieldQuery
      A subquery to use instead of a fieldName. When you use a fieldQuery instead of a fieldName, you are comparing the criterion value to the result of running a per-record subquery, rather than a field value found directly on the record. Note, it is also possible to specify both a fieldQuery and a valueQuery.

      See the subquery overview for more details of the criteria subquery feature, and examples of use.

      Note, if you specify both fieldQuery and fieldName in a criterion, we use the fieldName and the fieldQuery is ignored.

      Note also that fieldName supports a shortcut syntax for declaring a a simple qualified "dsName.fieldName" reference, which gets automatically converted into a basic fieldQuery by the criteria system. See the documentation for that property for details.

      fieldQuery is supported for client-side filtering of clientOnly DataSources, MockDataSources, and DataSources with a complete cache. See the "Client-Side Subquery Support" section in the subquery overview for details.

      Default value is null

      See Also:
    • fieldStaticValue

      public Object fieldStaticValue
      A constant value to use as the left-hand side of the comparison, instead of a field value from the record. When set, this value is used in place of the field value that would normally be derived from fieldName or fieldQuery.

      This is useful when comparing a constant value against the result of a valueQuery. For example, to check whether a particular product code appears in the set of products ordered by a customer:

        {
            fieldStaticValue: "PROD-001",
            operator: "inSet",
            valueQuery: {
                dataSource: "OrderLine",
                queryOutput: "productCode"
            }
        }
        
      If both fieldStaticValue and fieldName are specified, fieldStaticValue is used instead. If both fieldStaticValue and fieldQuery are specified, fieldStaticValue is used instead.

      Default value is null

      See Also:
    • end

      public Object end
      End value of a criterion with an operator of type "valueRange".

      Default value is null

      See Also:
    • start

      public Object start
      Start value of a criterion with an operator of type "valueRange".

      Default value is null

      See Also:
    • criteria

      public Criterion[] criteria
      For a criterion with an operator that acts on other criteria (eg "and", "or"), a list of sub-criteria that are grouped together by the operator.

      Default value is null

      See Also:
    • value

      public Object value
      Value to be used in the application of this criterion.

      Value may be required or not required, or may be an Array, according to the OperatorValueType of the operator.

      Default value is null

      See Also:
  • Constructor Details

    • Criterion

      public Criterion()