# GridConfig

> _Since v0.1.0_

Grid configuration for Vue applications.

Extends the base GridConfig with Vue-augmented ColumnConfig support.

#### Example

```ts
import type { GridConfig } from '@toolbox-web/grid-vue';
import { SelectionPlugin } from '@toolbox-web/grid/all';

const config: GridConfig<Employee> = {
  columns: [
    { field: 'name', header: 'Name' },
    {
      field: 'department',
      header: 'Department',
      renderer: (ctx) => h('span', { class: 'badge' }, ctx.value),
    },
  ],
  plugins: [new SelectionPlugin({ mode: 'row' })],
};
```

## Properties

| Property | Type | Description |
| -------- | ---- | ----------- |
| `rowClass?` | <code>(row: TRow) =&gt; string &#124; string[]</code> | Dynamic CSS class(es) for data rows. Called for each row during rendering. Return class names to add to the row element. |
| <span id="fitmode"></span>`fitMode?` | <code><a href="/grid/api/core/types/fitmode/">FitMode</a></code> | Sizing mode for columns. Can also be set via `fitMode` prop. |
| `columnInference?` | <code><a href="/grid/api/core/types/columninferencemode/">ColumnInferenceMode</a></code> | How automatic column inference combines with explicitly provided columns. Can also be set via the `columnInference` prop or `column-inference` attribute. <span class="since-badge" title="Introduced in v2.17.0">v2.17.0+</span> |
| `sortable?` | <code>boolean</code> | Grid-wide sorting toggle. When false, disables sorting for all columns regardless of their individual `sortable` setting. When true (default), columns with `sortable: true` can be sorted. |
| `resizable?` | <code>boolean</code> | Grid-wide resizing toggle. When false, disables column resizing for all columns regardless of their individual `resizable` setting. When true (default), columns with `resizable: true` (or resizable not set, since it defaults to true) can be resized. |
| `rowHeight?` | <code>number &#124; (row: TRow, index: number) =&gt; number &#124; undefined</code> | Row height in pixels for virtualization calculations. The virtualization system assumes uniform row heights for performance. |
| `plugins?` | <code><a href="/grid/api/plugin-development/interfaces/gridplugin/">GridPlugin</a>[]</code> | Array of plugin instances. Each plugin is instantiated with its configuration and attached to this grid. |
| `features?` | <code>Partial&lt;<a href="/grid/api/core/interfaces/featureconfig/">FeatureConfig</a>&lt;TRow&gt;&gt;</code> | Declarative feature configuration. Alternative to manually creating plugin instances in `plugins`. Features are resolved using the core feature registry. |
| <span id="columnstate"></span>`columnState?` | <code><a href="/grid/api/core/interfaces/gridcolumnstate/">GridColumnState</a></code> | Saved column state to restore on initialization. Includes order, width, visibility, sort, and plugin-contributed state. |
| `icons?` | <code><a href="/grid/api/core/interfaces/gridicons/">GridIcons</a></code> | Grid-wide icon configuration. |
| <span id="animation"></span>`animation?` | <code><a href="/grid/api/core/interfaces/animationconfig/">AnimationConfig</a></code> | Grid-wide animation configuration. Controls animations for expand/collapse, reordering, and other visual transitions. Individual plugins can override these defaults in their own config. |
| `sortHandler?` | <code><a href="/grid/api/core/types/sorthandler/">SortHandler</a>&lt;TRow&gt;</code> | Custom sort handler for the entire grid. |
| `initialSort?` | <code>&#123; field: string; direction: desc &#124; asc &#125;</code> | Initial sort state applied when the grid first renders. |
| `getRowId?` | <code>(row: TRow) =&gt; string</code> | Function to extract a unique identifier from a row. Used by `updateRow()`, `getRow()`, and ID-based tracking. |
| `typeDefaults?` | <code>Record&lt;string, <a href="/grid/vue/api/types/typedefault/">TypeDefault</a>&lt;TRow&gt;&gt;</code> | Type-level renderer and editor defaults. |
| `gridAriaLabel?` | <code>string</code> | Accessible label for the grid. Sets `aria-label` on the grid's internal table element for screen readers. |
| `gridAriaLabelledBy?` | <code>string</code> | ID of an element that labels the grid. Sets `aria-labelledby` on the grid's internal table element so screen readers can use the referenced element's text as the accessible name — useful when the grid already sits next to a heading. |
| `gridAriaDescribedBy?` | <code>string</code> | ID of an element that describes the grid. Sets `aria-describedby` on the grid's internal table element. |
| `gridAriaRoleDescription?` | <code>string</code> | Override the screen-reader-announced role name for the grid via `aria-roledescription`. Useful for localization (e.g. `"Tabell"` in Norwegian) or domain-specific naming (e.g. `"Employee table"`). |
| `a11y?` | <code><a href="/grid/api/core/interfaces/a11yconfig/">A11yConfig</a></code> | Accessibility configuration for screen reader announcements. |
| `locale?` | <code><a href="/grid/api/core/types/gridlocale/">GridLocale</a></code> | Translations for the built-in UI chrome rendered by plugins — filter panels, the column visibility panel, the pivot panel, context-menu items, and the print button. <span class="since-badge" title="Introduced in v3.5.0">v3.5.0+</span> |
| `emptyOverlay?` | <code><a href="/grid/api/core/types/emptyoverlay/">EmptyOverlay</a></code> | Where the empty-state overlay is mounted. <span class="since-badge" title="Introduced in v2.12.0">v2.12.0+</span> |
| `editOn?` | <code>false &#124; click &#124; dblclick &#124; manual</code> | Edit trigger mode. Requires `EditingPlugin` to be loaded. |
| `rowEditable?` | <code>(row: TRow) =&gt; boolean</code> | Row-level editability gate. Requires `EditingPlugin` to be loaded. |
| `filterable?` | <code>boolean</code> | Grid-wide filtering toggle. Requires `FilteringPlugin` to be loaded. |
| `columnGroups?` | <code><a href="/grid/vue/api/types/columngroupdefinition/">ColumnGroupDefinition</a>[]</code> | Declarative column group definitions for the GroupingColumnsPlugin. Each group specifies an id, header label, and array of column field names. The plugin will automatically assign the `group` property to matching columns. |
| `selectable?` | <code>boolean</code> | Grid-wide selection toggle. Requires `SelectionPlugin` to be loaded. |
| `shell?` | <code><a href="/grid/plugins/shell/interfaces/shellconfig/">ShellConfig</a></code> | Shell configuration for header bar and tool panels. When configured, adds an optional wrapper with title, toolbar, and collapsible side panels. |
| <span id="columns"></span>`columns?` | <code><a href="/grid/vue/api/types/columnconfig/">ColumnConfig</a>&lt;TRow, unknown, TField&gt;[]</code> | Column definitions with Vue renderer/editor support. |
| <span id="loadingrenderer"></span>`loadingRenderer?` | <code>Component &#124; <a href="/grid/api/core/types/loadingrenderer/">LoadingRenderer</a> &#124; (ctx: <a href="/grid/api/core/interfaces/loadingcontext/">LoadingContext</a>) =&gt; VNode</code> | Custom loading renderer - can be: - A vanilla function `(ctx: LoadingContext) => HTMLElement | string` - A Vue component with a `size` prop - A Vue render function `(ctx: LoadingContext) => VNode` |
| `emptyRenderer?` | <code>Component &#124; <a href="/grid/api/core/types/emptyrenderer/">EmptyRenderer</a> &#124; (ctx: <a href="/grid/api/core/interfaces/emptycontext/">EmptyContext</a>) =&gt; VNode &#124; unknown</code> | Custom empty-state renderer shown when the grid has no rows and is not loading. Can be: - A vanilla function `(ctx: EmptyContext) => HTMLElement | string` - A Vue component receiving `sourceRowCount` and `filteredOut` props - A Vue render function `(ctx: EmptyContext) => VNode` |

### Property Details

#### `rowClass`

Dynamic CSS class(es) for data rows.
Called for each row during rendering. Return class names to add to the row element.

Applies to custom-rendered rows too (e.g. a Responsive `cardRenderer` card), but not to rows
a plugin both synthesizes and renders itself — group headers, pivot rows and loading
placeholders (grouped or ServerSide) are skipped because they are not `TRow` values.
ServerSide placeholders only reach `rowClass` under its opt-in
`placeholderRendering: 'columns'`.

```typescript
// Highlight inactive rows
rowClass: (row) => row.active ? [] : ['inactive', 'dimmed']

// Status-based row styling
rowClass: (row) => [`priority-${row.priority}`]

// Single class as string
rowClass: (row) => row.isNew ? 'new-row' : ''
```

---

#### `columnInference`

How automatic column inference combines with explicitly provided columns.
Can also be set via the `columnInference` prop or `column-inference` attribute.

- `'auto'` (default): infer only when no columns are provided (current behavior).
- `'merge'`: always infer from data, then overlay provided columns by `field`.

**See also:** `ColumnInferenceMode`

---

#### `sortable`

Grid-wide sorting toggle.
When false, disables sorting for all columns regardless of their individual `sortable` setting.
When true (default), columns with `sortable: true` can be sorted.

This affects:
- Header click handlers for sorting
- Sort indicator visibility
- Multi-sort plugin behavior (if loaded)

**Default:** `true`

```typescript
// Disable all sorting
gridConfig = { sortable: false };

// Enable sorting (default) - individual columns still need sortable: true
gridConfig = { sortable: true };
```

---

#### `resizable`

Grid-wide resizing toggle.
When false, disables column resizing for all columns regardless of their individual `resizable` setting.
When true (default), columns with `resizable: true` (or resizable not set, since it defaults to true) can be resized.

This affects:
- Resize handle visibility in header cells
- Double-click to auto-size behavior

**Default:** `true`

```typescript
// Disable all column resizing
gridConfig = { resizable: false };

// Enable resizing (default) - individual columns can opt out with resizable: false
gridConfig = { resizable: true };
```

---

#### `rowHeight`

Row height in pixels for virtualization calculations.
The virtualization system assumes uniform row heights for performance.

If not specified, the grid measures the first rendered row's height,
which respects the CSS variable `--tbw-row-height` set by themes.

Set this explicitly when:
- Row content may wrap to multiple lines (also set `--tbw-cell-white-space: normal`)
- Using custom row templates with variable content
- You want to override theme-defined row height
- Rows have different heights based on content (use function form)

**Variable Row Heights**: When a function is provided, the grid enables variable height
virtualization. Heights are measured on first render and cached by row identity.
The function is never called for plugin loading placeholders (ServerSide rows whose
block has not loaded); they use the default row height.

**Numeric form**: the value is written to the `--tbw-row-height` custom property on the host
element (overriding the theme) and is never replaced by a measured height, even when a plugin
enables variable-height virtualization.

**Default:** `Auto-measured from first row (respects --tbw-row-height CSS variable)`

```ts
// Fixed height for all rows
gridConfig = { rowHeight: 56 };

// Variable height based on content
gridConfig = {
  rowHeight: (row, index) => row.hasDetails ? 80 : 40,
};

// Return undefined to trigger DOM auto-measurement
gridConfig = {
  rowHeight: (row) => row.isExpanded ? undefined : 40,
};
```

---

#### `plugins`

```ts
plugins: [
  new SelectionPlugin({ mode: 'range' }),
  new MultiSortPlugin(),
  new FilteringPlugin({ debounceMs: 150 }),
]
```

---

#### `features`

Declarative feature configuration.
Alternative to manually creating plugin instances in `plugins`.
Features are resolved using the core feature registry.

Import feature modules as side effects to register them:
```ts
import '@toolbox-web/grid/features/selection';
import '@toolbox-web/grid/features/filtering';
```

Then configure declaratively:
```ts
gridConfig = {
  features: {
    selection: 'range',
    filtering: { debounceMs: 200 },
    editing: 'dblclick',
  },
};
```

Both `features` and `plugins` can be used together — features-generated plugins
are created first, then manual `plugins` are appended. Duplicates are skipped
(manual `plugins` take precedence).

---

#### `icons`

Grid-wide icon configuration.

The grid uses a **CSS-first hybrid icon system**:
- **Default (CSS):** Icons render via `--tbw-icon-*` CSS custom properties on `tbw-grid`.
  Override them in your theme CSS — no JavaScript needed.
- **JS override:** Setting `gridConfig.icons` takes precedence over CSS for any key provided.
  Use this for dynamic icons, icon libraries, or `HTMLElement` instances.

All icons are optional — sensible defaults are used when not specified.
Plugins will use these by default but can override with their own config.

---

#### `sortHandler`

Custom sort handler for the entire grid.

:::caution
**Prefer BaseColumnConfig.sortComparator over `sortHandler`.**

`sortHandler` is a low-level escape hatch with significant limitations:
- Only consulted by the **single-column** sort path (core header click,
  `TreePlugin` per-level sort, `ServerSidePlugin` `sortMode: 'local'`).
- **Bypassed entirely** when `MultiSortPlugin` is loaded.
- Owns ALL columns at once — your handler must implement field/direction
  dispatch and null handling for every sortable column itself.

For per-column custom sort logic, use BaseColumnConfig.sortComparator
instead. It is honored by every sort code path in the grid (core, multi-sort,
tree, server-side) and is composable across columns.

For server-side sort, prefer `ServerSideConfig.dataSource` — the
`sortModel` is shipped to your `getRows` handler so the backend can return
pre-sorted blocks.
:::

Use `sortHandler` only when you need to replace the grid's sort engine
wholesale (e.g. integrating a third-party sort library that operates on
the full row array, or routing every sort through a single async pipeline).

The handler receives:
- `rows`: Current row array to sort
- `sortState`: Sort field and direction (1 = asc, -1 = desc)
- `columns`: Column configurations (for accessing sortComparator)

Return the sorted array (sync) or a Promise that resolves to it (async).

```ts
// Replace the entire client-side sort engine with a custom stable sort
sortHandler: (rows, state) => stableSort(rows, state.field, state.direction);
```

**See also:** `BaseColumnConfig.sortComparator` — recommended per-column override · `ServerSideConfig.dataSource` — recommended server-side sort path

---

#### `initialSort`

Initial sort state applied when the grid first renders.

Equivalent to calling `grid.sort(field, direction)` after the grid is created,
but avoids the imperative call and extra render cycle.

```ts
gridConfig = {
  initialSort: { field: 'salary', direction: 'desc' },
};
```

**See also:** `DataGridElement.sort` for runtime sorting · `DataGridElement.sortModel` for reading current sort state

---

#### `getRowId`

Function to extract a unique identifier from a row.
Used by `updateRow()`, `getRow()`, and ID-based tracking.

If not provided, falls back to `row.id` or `row._id` if present.
Rows without IDs are silently skipped during map building.
Only throws when explicitly calling `getRowId()` or `updateRow()` on a row without an ID.

Never called for plugin loading placeholders (ServerSide blocks or grouped rows in
flight). The grid gives those an internal id: `__loading:<index>` for ServerSide
blocks, `__loading:group:<groupKey>` for GroupingRows groups.

```ts
// Simple field
getRowId: (row) => row.id

// Composite key
getRowId: (row) => `${row.voyageId}-${row.legNumber}`

// UUID field
getRowId: (row) => row.uuid
```

---

#### `typeDefaults`

Type-level renderer and editor defaults.

Keys can be:
- Built-in types: `'string'`, `'number'`, `'date'`, `'boolean'`, `'select'`
- Custom types: `'currency'`, `'country'`, `'status'`, etc.

Resolution order (highest priority first):
1. Column-level (`column.renderer` / `column.editor`)
2. Grid-level (`gridConfig.typeDefaults[column.type]`)
3. App-level (Angular `GridTypeRegistry`, React `GridTypeProvider`)
4. Built-in (checkbox for boolean, select for select, etc.)
5. Fallback (plain text / text input)

```typescript
typeDefaults: {
  date: { editor: myDatePickerEditor },
  country: {
    renderer: (ctx) => {
      const span = document.createElement('span');
      span.innerHTML = `<img src="/flags/${ctx.value}.svg" /> ${ctx.value}`;
      return span;
    },
    editor: (ctx) => createCountrySelect(ctx)
  }
}
```

---

#### `gridAriaLabel`

Accessible label for the grid.
Sets `aria-label` on the grid's internal table element for screen readers.

If not provided and `shell.header.title` is set, the title is used automatically.

If [`gridAriaLabelledBy`](#gridarialabelledby) is also set, `aria-labelledby`
takes precedence per WAI-ARIA accessible-name computation and `aria-label`
is omitted.

```ts
gridConfig = { gridAriaLabel: 'Employee data' };
```

---

#### `gridAriaLabelledBy`

ID of an element that labels the grid.
Sets `aria-labelledby` on the grid's internal table element so screen
readers can use the referenced element's text as the accessible name —
useful when the grid already sits next to a heading.

Per WAI-ARIA accessible-name precedence, `aria-labelledby` takes priority
over `aria-label` and over the auto-derived shell title. When this option
is set, the grid omits `aria-label` to avoid conflicting names.

```html
<h2 id="grid-heading">Employees</h2>
<tbw-grid></tbw-grid>
```
```ts
gridConfig = { gridAriaLabelledBy: 'grid-heading' };
```

---

#### `gridAriaDescribedBy`

```html
<p id="grid-desc">This table shows all active employees.</p>
<tbw-grid></tbw-grid>
```
```ts
gridConfig = { gridAriaDescribedBy: 'grid-desc' };
```

---

#### `gridAriaRoleDescription`

Override the screen-reader-announced role name for the grid via
`aria-roledescription`. Useful for localization (e.g. `"Tabell"` in
Norwegian) or domain-specific naming (e.g. `"Employee table"`).

:::caution
Per [WAI-ARIA 1.2](https://www.w3.org/TR/wai-aria-1.2/#aria-roledescription),
the value should still describe a grid-like widget. Overriding with an
unrelated label confuses assistive-technology users about the available
interactions (cell navigation, sort, etc.). Leave unset to use the
default role name announced by the AT.
:::

```ts
gridConfig = { gridAriaRoleDescription: 'Employee table' };
```

---

#### `a11y`

Accessibility configuration for screen reader announcements.

The grid automatically announces state changes (sort, filter, selection, etc.)
via an `aria-live` region. Use this config to toggle announcements or override
message text for internationalization.

```ts
// Disable all announcements
gridConfig = { a11y: { announcements: false } };

// Custom messages for i18n
gridConfig = {
  a11y: {
    messages: {
      sortApplied: (col, dir) => `Trié par ${col}, ${dir}`,
      filterApplied: (col) => `Filtre appliqué sur ${col}`,
    },
  },
};
```

---

#### `locale`

Translations for the built-in UI chrome rendered by plugins — filter panels,
the column visibility panel, the pivot panel, context-menu items, and the
print button.

Keys are namespaced per plugin (`filter.apply`, `columns.showAll`,
`pivot.removeField`, …). Any key you omit falls back to its English default,
so a partial map is valid. Unknown keys are ignored.

ARIA live-region announcements are configured separately via
A11yConfig.messages, because those are functions of runtime values.

```ts
gridConfig = {
  locale: {
    'filter.apply': 'Appliquer',
    'filter.clear': 'Effacer le filtre',
    'filter.search': 'Rechercher…',
    'columns.showAll': 'Tout afficher',
  },
};
```

---

#### `emptyOverlay`

Where the empty-state overlay is mounted.

- `'rows'` (default) — overlays the `.rows-container`. Headers stay
  visible so users can clear filters or see the column schema.
- `'grid'` — overlays the `.tbw-grid-root`. Hides headers and any
  shell/toolbar content too.

---

#### `editOn`

Edit trigger mode. Requires `EditingPlugin` to be loaded.

Configure via `new EditingPlugin({ editOn: 'click' })` or set on gridConfig.
Plugin config takes precedence over gridConfig.

- `'click'`: Single click to edit
- `'dblclick'`: Double-click to edit (default)
- `'manual'`: Only via programmatic API (beginEdit)
- `false`: Disable editing entirely

---

#### `rowEditable`

Row-level editability gate. Requires `EditingPlugin` to be loaded.

When provided, this function is called **before** the column-level
`editable` check. If it returns `false` for a given row, **no cell** in
that row can be edited regardless of the column configuration.

Omitting this property (or returning `true`) defers to per-column
`editable` settings.

Keep the callback fast — it is invoked on every editability check
(click, keyboard, grid-mode render, tab navigation).

```typescript
// Block editing for archived rows
gridConfig = {
  rowEditable: (row) => !row.archived,
  columns: [
    { field: 'name', editable: true },
    { field: 'price', editable: (row) => row.status === 'draft' },
  ],
};
```

---

#### `filterable`

Grid-wide filtering toggle. Requires `FilteringPlugin` to be loaded.

When `false`, disables filtering for all columns regardless of their individual `filterable` setting.
When `true` (default), columns with `filterable: true` (or not explicitly set to false) can be filtered.

This affects:
- Filter button visibility in headers
- Filter panel accessibility
- Filter keyboard shortcuts

**Default:** `true`

```typescript
// Disable all filtering at runtime
grid.gridConfig = { ...grid.gridConfig, filterable: false };

// Re-enable filtering
grid.gridConfig = { ...grid.gridConfig, filterable: true };
```

---

#### `columnGroups`

```ts
columnGroups: [
  { id: 'personal', header: 'Personal Info', children: ['firstName', 'lastName', 'email'] },
  { id: 'work', header: 'Work Info', children: ['department', 'title', 'salary'] },
]
```

---

#### `selectable`

Grid-wide selection toggle. Requires `SelectionPlugin` to be loaded.

When `false`, disables all selection interactions while keeping the plugin loaded.
When `true` (default), selection works according to the plugin's mode configuration.

This affects:
- Click/drag selection
- Keyboard selection (arrows, Shift+arrows, Ctrl+A)
- Checkbox column clicks (if enabled)

**Default:** `true`

```typescript
// Disable all selection at runtime
grid.gridConfig = { ...grid.gridConfig, selectable: false };

// Re-enable selection
grid.gridConfig = { ...grid.gridConfig, selectable: true };
```

---

#### `shell`

Shell configuration for header bar and tool panels.
When configured, adds an optional wrapper with title, toolbar, and collapsible side panels.

Provided via module augmentation by the built-in `ShellPlugin` (#370), mirroring how
feature plugins augment `FeatureConfig`. Import the `ShellConfig` type from
`@toolbox-web/grid/plugins/shell`.

---

#### `emptyRenderer`

Custom empty-state renderer shown when the grid has no rows and is not
loading. Can be:
- A vanilla function `(ctx: EmptyContext) => HTMLElement | string`
- A Vue component receiving `sourceRowCount` and `filteredOut` props
- A Vue render function `(ctx: EmptyContext) => VNode`

Set explicitly to `null` to suppress the built-in default message.

---
