dock
Gives side panels a place beside or under the rows, with tabs, resizing and collapsing.
| Import | import { dock } from '@dzgrid/dom/dock'; |
|---|---|
| Signature | dock(o?: DockOptions): DockFeature |
| Texts | import { EN_DOCK } from '@dzgrid/dom/locales/en-dock';languages: en, fr, ar |
| Style sheet | import '@dzgrid/theme/dock.css'; |
| Own CSS | DOCK_CSS — to add yourself with injectStyles: false |
| Declared in | packages/dom/src/dock/index.ts |
| Options | Type |
|---|---|
open | Readonly<Record<string, DockArea>> |
panels | readonly DockPanel[] |
sizes | { readonly min?: number; readonly max?: number } |
onChange | (layout: DockState) => void |
What it does
Section titled “What it does”dock() adds three areas inside the grid’s box: start and end beside the rows (logical sides: mirrored in
Arabic) and bottom under them. The columnsChooser (panel columns), the
filtersPanel (panel filters) and your own panels stand there. Two panels in one area become
tabs. Each area is resized by its edge, by the pointer or the arrow keys, collapsed to a strip, closed, or moved to
another area with its « Place » button.
api(grid) gives show(id, area), hide(id), move(id, area), collapse(area), resize(area, px), layout()
and setLayout(layout). With gridState, where each panel stands is saved with the rest of the
state.
A floating window (area float) is not there yet: in open it is refused with an invalid-setting warning, and in a
restored layout skipped with a state-field warning.
Options
Section titled “Options”open: the panels shown at the start, and where ({ columns: 'end' }), over each panel’s own default.panels: your own panels —id,title(text, or a function asked again at each paint),area(endby default; hidden there until shown, unlessopennames it) andmount(host), which draws the content once and may return a cleanup.sizes: the limits of an area’s size in CSS px,{ min, max }(160 and 800 by default); the rows always keep 160 px.onChange(layout): after each change made by the user or the API, never after a restore: the layout as the state keeps it.
Example
Section titled “Example”import { createGrid } from '@dzgrid/dom';import { dock } from '@dzgrid/dom/dock';import { columnsChooser } from '@dzgrid/dom/columns-panel';import { EN } from '@dzgrid/dom/locales/en';import { EN_DOCK } from '@dzgrid/dom/locales/en-dock';import { EN_COLUMNS } from '@dzgrid/dom/locales/en-columns';
type Tea = { id: string; tea: string; minutes: number };
const panels = dock({ open: { columns: 'end' }, sizes: { min: 200, max: 480 }, panels: [{ id: 'notes', title: 'Notes', area: 'bottom', mount(host) { const p = host.ownerDocument.createElement('p'); p.textContent = 'Warm the pot first.'; host.append(p); return () => p.remove(); }, }], onChange: (layout) => console.log(layout),});
const grid = createGrid<Tea>(document.getElementById('teas')!, { rows: [{ id: 'e1', tea: 'Smoked pine', minutes: 4 }], columns: [ { id: 'tea', header: 'Tea' }, { id: 'minutes', header: 'Minutes', type: 'number' }, ], getRowId: (t) => t.id, messages: { ...EN, text: { ...EN.text, ...EN_DOCK.text, ...EN_COLUMNS.text } }, features: [columnsChooser(), panels],});
panels.api(grid)?.show('notes');Live demo
Section titled “Live demo”The chooser and the filters share the end area as tabs: drag the area's edge to resize it.
See also
Section titled “See also”- Dock and panels: the two panels and your own, step by step.
columnsChooserandfiltersPanel: the panels that come with DzGrid.gridState: the layout saved with the state.