Ga naar hoofdinhoud

CnDashboardGrid

Low-level drag-and-drop grid layout engine powered by GridStack. Manages widget placement, drag, and resize interactions and emits layout changes for persistence. Does not handle widget rendering — the parent provides content via the #widget scoped slot.

Used internally by CnDashboardPage. Only use this directly if you need fine-grained control over the grid without the full dashboard page shell.

Requires: gridstack (bundled dependency)

Try it

Loading CnDashboardGrid playground…

Usage

<CnDashboardGrid
:layout="placements"
:editable="isEditing"
:columns="12"
:cell-height="80"
@layout-change="onLayoutChange">
<template #widget="{ item }">
<MyWidget :config="item" />
</template>
</CnDashboardGrid>
// Layout item shape
const placements = [
{ id: 1, gridX: 0, gridY: 0, gridWidth: 6, gridHeight: 3 },
{ id: 2, gridX: 6, gridY: 0, gridWidth: 6, gridHeight: 3 },
]

function onLayoutChange(updated) {
// updated is the full layout array with new x/y/w/h values
saveLayout(updated)
}

Props

PropTypeRequiredDefaultDescription
layoutArrayArray of layout items: { id, gridX, gridY, gridWidth, gridHeight, ...extra }
editableBooleanfalseEnables drag and resize interactions
columnsNumber12Number of grid columns
cellHeightNumber80Cell height in pixels
marginNumber12Gap between grid items in pixels
minWidthNumber2Minimum widget width in grid units
minHeightNumber2Minimum widget height in grid units
columnOptsObjectnullGridStack v12 responsive columnOpts bag; when set the grid reflows its column count across screen sizes. Build it with getDashboardColumnOpts. Default null = fixed columns.
cellHeightCssVarStringnullWhen set, cellHeight is mirrored into this CSS custom property on the document root at init (e.g. --app-cell-height). Default null = none.
itemKeyFunctionnullOptional (item) => string|number to derive each item's render key; forces a re-render when an item changes in a way its id doesn't capture (e.g. style edits). Default null = key on item.id.

Events

EventPayloadDescription
layout-changelayout[]Emitted when any item is dragged or resized; payload is the full updated layout array

Slots

SlotScopeDescription
widget{ item }Content to render inside each grid cell; item is the layout object

Reference (auto-generated)

The tables below are generated from the SFC source via vue-docgen-cli. They reflect what's actually in CnDashboardGrid.vue and update automatically whenever the component changes.

Props

NameTypeRequiredDefaultDescription
layoutarrayArray of layout items: { id, gridX, gridY, gridWidth, gridHeight, ...extra }
editablebooleanfalseWhether drag and resize are enabled
columnsnumber12Number of grid columns
cellHeightnumber80Cell height in pixels
marginnumber12Grid margin in pixels
minWidthnumber2Minimum widget width in grid units
minHeightnumber2Minimum widget height in grid units
columnOptsunionnullGridStack v12 responsive columnOpts bag (breakpoints + reflow layout). When set, the grid reflows column count across screen sizes. Build it with getDashboardColumnOpts(). Default null = fixed columns, no responsive reflow (backwards-compatible).
cellHeightCssVarunionnullWhen set, cellHeight is mirrored into this CSS custom property on the document root at init (e.g. '--app-cell-height'), so app CSS can align to the grid geometry. Default null = no CSS var written.
itemKeyunionnullOptional (item) =&gt; string|number to derive each item's render key. Use it to force a re-render when an item changes in a way its id doesn't capture (e.g. style edits — return \${item.id}:\${item.updatedAt}). Default null = key on item.id.

Events

NamePayloadDescription
layout-change

Slots

NameBindingsDescription
widgetitem