Class: FilterLeaf

FilterLeaf

new FilterLeaf()

An object that represents a conditional expression node in a filter tree.

This object represents a conditional expression. It is always a terminal node in the filter tree; it has no child nodes of its own.

A conditional expression is a simple dyadic expression with the following syntax in the UI:

column operator operand

where:

  • column is the name of a column from the data row object
  • operator is the name of an operator from the node's operator list
  • operand is a literal value to compare against the value in the named column

NOTE: The ColumnLeaf extension of this object has a different implementation of operand which is: The name of a column from which to fetch the compare value (from the same data row object) to compare against the value in the named column. See Extending the conditional expression object in the readme.

The values of the terms of the expression above are stored in the first three properties below. Each of these three properties is set either by setState() or by the user via a control in el. Note that these properties are not dynamically bound to the UI controls; they are updated by the validation function, invalid().

See also the properties of the superclass: FilterNode

Properties:
Name Type Attributes Default Description
column string

Name of the member in the data row objects against which operand will be compared. Reflects the value of the view.column control after validation.

operator string

Operator symbol. This must match a key in the this.root.conditionals.ops hash. Reflects the value of the view.operator control after validation.

operand string

Value to compare against the the member of data row named by column. Reflects the value of the view.operand control, after validation.

name string

Used to describe the object in the UI so user can select an expression editor.

type string <optional>
'string'

The data type of the subexpression if neither the operator nor the column schema defines a type.

el HTMLElement

A <span>...</span> element that contains the UI controls. This element is automatically appeneded to the parent FilterTree's el. Generated by createView.

view filterLeafViewObject

A hash containing direct references to the controls in el. Added by createView.

Methods

createView()

Create a new view.

This new "view" is a group of HTML Element controls that completely describe the conditional expression this object represents. This method creates the view, setting this.el to point to it, and the members of this.view to point to the individual controls therein.

getState(optionsopt)

For 'object' and 'JSON' note that the subtree's version of getState will not call this leaf version of getState because the former uses unstrungify() and JSON.stringify(), respectively, both of which recurse and call toJSON() on their own.

Parameters:
Name Type Attributes Default Description
options object <optional>
'object'

See the subtree version of getState for more info.

invalid() → {undefined}

Called by the parent node's invalid() method, which catches the error thrown when invalid.

Also performs the following compilation actions:

  • Copies all this.view' values from the DOM to similarly named properties of this.
  • Pre-sets this.op and this.converter for use in test's tree walk.
Parameters:
Name Type Attributes Default Description
options.throw boolean <optional>
false

Throw an error if missing or invalid value.

options.focus boolean <optional>
false

Move focus to offending control.

Returns:

This is the normal return when valid; otherwise throws error when invalid.

Type
undefined

makeElement(menuopt, promptopt, sortopt)

HTML form controls factory.

Creates and appends a text box or a drop-down.

Defined on the FilterTree prototype for access by derived types (alternate filter editors).

Parameters:
Name Type Attributes Default Description
menu Array.<menuItem> <optional>

Overloads:

  • If omitted, will create an <input/> (text box) element.
  • If contains only a single option, will create a <span>...</span> element containing the string and a <input type=hidden> containing the value.
  • Otherwise, creates a <select>...</select> element with these menu items.
prompt null | string <optional>
''

Adds an initial <option>...</option> element to the drop-down with this value, parenthesized, as its text; and empty string as its value. Omitting creates a blank prompt; null suppresses.

sort <optional>
Returns:

The new element.