MCPcopy Index your code
hub / github.com/gridstack/gridstack.js / sort

Method sort

src/utils.ts:312–319  ·  view source on GitHub ↗

* Sort an array of grid nodes by position (y first, then x). * * @param nodes array of nodes to sort * @param dir sort direction: 1 for ascending (top-left first), -1 for descending * @returns the sorted array (modifies original) * * @example * const sorted = Utils.sort(nodes);

(nodes: GridStackNode[], dir: 1 | -1 = 1)

Source from the content-addressed store, hash-verified

310 * const reverse = Utils.sort(nodes, -1); // Sort bottom-right to top-left
311 */
312 static sort(nodes: GridStackNode[], dir: 1 | -1 = 1): GridStackNode[] {
313 const und = 10000;
314 return nodes.sort((a, b) => {
315 const diffY = dir * ((a.y ?? und) - (b.y ?? und));
316 if (diffY === 0) return dir * ((a.x ?? und) - (b.x ?? und));
317 return diffY;
318 });
319 }
320
321 /**
322 * Find a grid node by its ID.

Callers 7

sortNodesMethod · 0.80
columnChangedMethod · 0.80
constructorMethod · 0.80
loadMethod · 0.80
reorderMainContentFunction · 0.80
reorderSidebarNavigationFunction · 0.80
utils-spec.tsFile · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected