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

Method checkDynamicColumn

src/gridstack.ts:962–984  ·  view source on GitHub ↗

checks for dynamic column count for our current size, returning true if changed

()

Source from the content-addressed store, hash-verified

960
961 /** checks for dynamic column count for our current size, returning true if changed */
962 protected checkDynamicColumn(): boolean {
963 const resp = this.opts.columnOpts;
964 if (!resp || (!resp.columnWidth && !resp.breakpoints?.length)) return false;
965 const column = this.getColumn();
966 let newColumn = column;
967 const w = this._widthOrContainer(true);
968 if (resp.columnWidth) {
969 newColumn = Math.min(Math.round(w / resp.columnWidth) || 1, resp.columnMax);
970 } else {
971 // find the closest breakpoint (already sorted big to small) that matches
972 newColumn = resp.columnMax;
973 let i = 0;
974 while (i < resp.breakpoints.length && w <= resp.breakpoints[i].w) {
975 newColumn = resp.breakpoints[i++].c || column;
976 }
977 }
978 if (newColumn !== column) {
979 const bk = resp.breakpoints?.find(b => b.c === newColumn);
980 this.column(newColumn, bk?.layout || resp.layout);
981 return true;
982 }
983 return false;
984 }
985
986 /**
987 * Re-layout grid items to reclaim any empty space. This is useful after removing widgets

Callers 3

constructorMethod · 0.95
updateOptionsMethod · 0.95
onResizeMethod · 0.95

Calls 4

getColumnMethod · 0.95
_widthOrContainerMethod · 0.95
columnMethod · 0.95
findMethod · 0.80

Tested by

no test coverage detected