Skip to main content

filter()

filters items in the diagram

filter(rule?: IFilterCallback | IFilterMode, config?: IFilterConfig): void;

Parameters:

  • rule: function | object - the filtering criteria
  • config: object - optional, defines the parameters of filtering

Example

// filtering by the key of the shape attribute
diagram.data.filter({ by: "text", match: "Read N" });

// filtering by a function
diagram.data.filter(function (shape) {
return shape.id > 3;
});

Related sample: Diagram. Data. Filtering shapes

To revert the diagram to the initial state, call the filter() method without parameters.

diagram.data.filter();

The rule parameter:

  • if set as a function, the filtering will be applied by the rule specified in the function:

For example:

diagram.data.filter(function (shape) {
return shape.id > 3;
});
  • if set as an object, the parameter has the following attributes:
by(string) mandatory, the key of the item attribute
match(string) mandatory, a pattern to match
compare(function) optional, a function for extended filtering that takes three parameters:
  • value - the value to compare
  • match - a pattern to match
  • item - a data item the values of which should be compared (e.g. a shape)

For instance:

diagram.data.filter({ by: "text", match: "Read N" });

The config parameter may contain two properties:

add(boolean) defines whether each next filtering will be applied to the already filtered data (true), or to the initial data (false, default)
smartFilter(boolean) defines whether a filtering rule will be applied after adding and editing items of the collection

Filtering items