new FilterNode()
A node in a filter tree.
A filter tree represents a complex conditional expression and consists of a single instance of a FilterTree
object as the root of an n-ary tree.
Filter trees are comprised of instances of FilterNode
objects. However, the FilterNode
constructor is an "abstract class"; filter node objects are never instantiated directly from this constructor. A filter tree is actually comprised of instances of two "subclasses" of FilterNode
objects:
FilterTree
(or subclass thereof) objects, instances of which represent the root node and all the branch nodes:- There is always exactly one root node, containing the whole filter tree, which represents the filter expression in its entirety. The root node is distinguished by having no parent node.
- There are zero or more branch nodes, or subtrees, which are child nodes of the root or other branches higher up in the tree, representing subexpressions within the larger filter expression. Each branch node has exactly one parent node.
- These nodes point to zero or more child nodes which are either nested subtrees, or:
FilterLeaf
(or subclass thereof) objects, each instance of which represents a single simple conditional expression. These are terminal nodes, having exactly one parent node, and no child nodes.
The programmer may extend the semantics of filter trees by extending the above objects.
Properties:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
sqlIdQts |
sqlIdQtsObject |
<optional> |
{beg:'"',end:'"'} | Quote characters for SQL identifiers. Used for both parsing and generating SQL. Should be placed on the root node. |
el |
HTMLElement | The DOM element created by the |
Members
(static) optionsSchema :object
Defines the standard options available to a node.
The following properties bear the same names as the node options they define.
Type:
- object
editor :string
Filter editor for user interface.
Name of filter editor used by this and all descendant nodes. Pertains to leaf nodes only.
Type:
- string
- Default Value:
- 'Default'
eventHandler :function
Event handler for UI events.
See Events in the readme for more information.
Type:
- function
keep :boolean
Undeleteable node.
Truthy means don't render a delete button next to the filter editor for this node.
Type:
- boolean
opMenu :Array.<menuItem>
Override operator list at any node.
The default is applied to the root node and any other node without an operator menu.
Type:
- Array.<menuItem>
- Default Value:
opMustBeInMenu :boolean
Truthy considers op valid only if in menu.
Type:
- boolean
ownSchema :Array.<string>
Default column schema for column drop-downs of direct descendant leaf nodes only.
Type:
- Array.<string>
parent :FilterNode
Reference to this node's parent node.
When this property is undefined, this node is the root node.
Type:
root :FilterNode
Convenience reference to the root node.
Type:
schema :Array.<menuItem>
Column schema for column drop-downs of all descendant nodes. Pertains to leaf nodes only.
Type:
- Array.<menuItem>
sortColumnMenu :boolean
Truthy will sort the column menus.
Type:
- boolean
type :string
Fields data type.
Type:
- string
typeOpMap :object
Dictionary of operator menus for specific data types.
A hash of type names. Each member thus defined contains a specific operator menu for all descendant leaf nodes that:
- do not have their own operator menu (
opMenu
property) of their own; and - whose columns resolve to that type.
The type is determined by (in priority order):
- the
type
property of theFilterLeaf
; or - the
type
property of the element in the nearest node (including the leaf node itself) that has a definedownSchema
orschema
array property with an element having a matching column name.
Type:
- object
Methods
parseStateString(stateopt, optionsopt) → {FilterTreeStateObject}
Convert a string to a state object.
They string's syntax is inferred as follows:
- If state is undefined or already an object, return as is.
- If
options.context
is defined,state
is assumed to be a CSS selector string (auto-detected) pointing to an HTML form control with avalue
property, such as a HTMLInputElement or a HTMLTextAreaElement. The element is selected and if found, its value is fetched from the DOM and assigned tostate
. - If
options.syntax
is'auto'
, JSON syntax is detected ifstate
begins and ends with either[
and]
or{
and}
(ignoring leading and trailing white space). - If JSON syntax, parse the string into an actual
FilterTreeStateObject
using JSON.parse and throw an error if unparsable. - If not JSON, parse the string as SQL into an actual
FilterTreeStateObject
using parser-SQL'sparser
and throw an error if unparsable.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
state |
FilterTreeStateObject |
<optional> |
|
options |
FilterTreeSetStateOptionsObject |
<optional> |
Returns:
The unmolested state
parameter. Throws an error if state
is unknown or invalid syntax.
remove()
Remove both:
this
filter node from it'sparent
'schildren
collection; andthis
filter node'sel
's container (always a<li>
element) from its parent element.
render()
Insert each subtree into its parent node along with a "delete" button.
NOTE: The root tree (which has no parent) must be inserted into the DOM by the instantiating code (without a delete button).
setState(state, optionsopt)
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
state |
FilterTreeStateObject | ||
options |
FilterTreeSetStateOptionsObject |
<optional> |