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

Method getCellHeight

src/gridstack.ts:857–885  ·  view source on GitHub ↗

* Gets the current cell height in pixels. This takes into account the unit type and converts to pixels if necessary. * * @param forcePixel if true, forces conversion to pixels even when cellHeight is specified in other units * @returns the cell height in pixels * * @example * const

(forcePixel = false)

Source from the content-addressed store, hash-verified

855 * const pixelHeight = grid.getCellHeight(true);
856 */
857 public getCellHeight(forcePixel = false): number {
858 if (this.opts.cellHeight && this.opts.cellHeight !== 'auto' &&
859 (!forcePixel || !this.opts.cellHeightUnit || this.opts.cellHeightUnit === 'px')) {
860 return this.opts.cellHeight as number;
861 }
862 // do rem/em/cm/mm to px conversion
863 if (this.opts.cellHeightUnit === 'rem') {
864 return (this.opts.cellHeight as number) * parseFloat(getComputedStyle(document.documentElement).fontSize);
865 }
866 if (this.opts.cellHeightUnit === 'em') {
867 return (this.opts.cellHeight as number) * parseFloat(getComputedStyle(this.el).fontSize);
868 }
869 if (this.opts.cellHeightUnit === 'cm') {
870 // 1cm = 96px/2.54. See https://www.w3.org/TR/css-values-3/#absolute-lengths
871 return (this.opts.cellHeight as number) * (96 / 2.54);
872 }
873 if (this.opts.cellHeightUnit === 'mm') {
874 return (this.opts.cellHeight as number) * (96 / 2.54) / 10;
875 }
876 // else get first cell height
877 const el = this.el.querySelector('.' + this.opts.itemClass) as HTMLElement;
878 if (el) {
879 const h = Utils.toNumber(el.getAttribute('gs-h')) || 1; // since we don't write 1 anymore
880 return Math.round(el.offsetHeight / h);
881 }
882 // else do entire grid and # of rows (but doesn't work if min-height is the actual constrain)
883 const rows = parseInt(this.el.getAttribute('gs-current-row'));
884 return rows ? Math.round(this.el.getBoundingClientRect().height / rows) : this.opts.cellHeight as number;
885 }
886
887 /**
888 * Update current cell height - see `GridStackOptions.cellHeight` for format by updating eh Browser CSS variable.

Callers 5

_setupAcceptWidgetMethod · 0.95
onStartMovingMethod · 0.95
resizeToContentMethod · 0.80
gridstack-spec.tsFile · 0.80

Calls 1

toNumberMethod · 0.80

Tested by

no test coverage detected