Skip to content

eles.filter(criterion, thisArg?)

eles.filter — Collection > Building and filtering. Cytoscape.js signatures, parameters and return contract.

eles.filter — Collection › Building and filtering

Preview · Collection › Building and filtering

Read in the complete API reference · All API members

// The subset matching the criterion
eles.filter(criterion: FilterLike<NodeData, EdgeData, Data, NodeData | EdgeData>, thisArg?: unknown): Collection<NodeData, EdgeData, Data>

The subset matching the criterion.

A structured query object is answered directly off the flags column — no per-element handles and no closures — while a predicate function is called per element. Pass either of these two forms; selector strings are not accepted.

Parameters
NameDescription
criterion: FilterLike<NodeData, EdgeData, Data, NodeData | EdgeData>

a query object ({ selected: true }, { data: { weight: { gt: 0.5 } } }, …) or an ( ele, i, eles) => boolean predicate

thisArg: unknown?

optional receiver, for the predicate form

Fields of criterion
NameDescription
group: GroupName?

restrict to one group

selected: boolean?

require the element (not) to be selected

selectable: boolean?

whether the element may be selected by the user

locked: boolean?

whether the element is locked in place

grabbed: boolean?

whether the user is dragging the element

grabbable: boolean?

whether the element may be dragged

active: boolean?

whether the element is under an active press

hovered: boolean?

whether the pointer is over the element

emphasized: boolean?

whether the element is in the current emphasis (* cy.emphasize())

parent: boolean?

structural (nodes only): has at least one child

childless: boolean?

structural (nodes only): has no children — exactly { parent: false }

child: boolean?

structural (nodes only): has a parent

orphan: boolean?

structural (nodes only): has no parent — exactly { child: false }

collapsed: boolean?

whether this compound parent is in collapsed miniature state (nodes only)

data: QueryData<Data>?

data-sidecar conditions per key; a bare value means equality. Typed, the keys are the queried elements' fields.

Returns Collection<NodeData, EdgeData, Data>

a new collection of the matching elements

Example

cy.getElementById('a').select();
console.log(cy.nodes().filter({ selected: true }).map(node => node.id())); // ['a']

Example graph and handle setup

Throws

if a query object carries an unknown key — a typo must not silently match everything