Skip to content

eles.sort(sortFn)

eles.sort — Collection > Iteration and aggregation. Cytoscape.js signatures, parameters and return contract.

eles.sort — Collection › Iteration and aggregation

Preview · Collection › Iteration and aggregation

Read in the complete API reference · All API members

// A copy sorted by a comparator
eles.sort(sortFn: ( a: Collection<NodeData, EdgeData, Data>, b: Collection<NodeData, EdgeData, Data>, ) => number): Collection<NodeData, EdgeData, Data>

A copy sorted by a comparator. Note that sort order is a property of the collection, not of drawing: draw order is structural and there is no z-index.

Parameters
NameDescription
sortFn: ( a: Collection<NodeData, EdgeData, Data>, b: Collection<NodeData, EdgeData, Data>, ) => number

( a, b) comparator over length-1 collections; a non-function is ignored and returns this collection unchanged

Returns Collection<NodeData, EdgeData, Data>

a new, sorted collection

Example

const sorted = eles.sort((a, b) => a.id().localeCompare(b.id()));
console.log(sorted.first().id()); // 'a'

Example graph and handle setup