Multi-Column Headers
Pantanal Grid supports multi-column headers by nesting column definitions, allowing you to create complex header structures.
Basic Multi-Column Headers
Nest columns by using the columns property of a column definition. The Product Details column contains nested columns.
ID | Product Details | Unit Price | Units In Stock | |
|---|---|---|---|---|
ID | Product Name | Category | Unit Price | Units In Stock |
Nested Column Groups
You can nest column groups to create multiple levels of headers. In this example, Product Details contains Pricing which has nested columns.
ID | Product Details | Supplier | |||
|---|---|---|---|---|---|
Product Name | Pricing | Category | |||
ID | Product Name | Unit Price | Stock | Category | Supplier |
Multi-Column Headers with Sorting and Filtering
Multi-column headers support all standard grid features. You can sort and filter by leaf columns (columns with field property).
ID | Product Details | Unit Price | Units In Stock | |
|---|---|---|---|---|
ID | Product Name | Category | Unit Price | Units In Stock |
Basic Multi-Column Headers
Nest columns by using the columns property of a column definition:
<script setup lang="ts">
import { PantanalGrid, type ColumnDef } from '@pantanal/grid'
const columns: ColumnDef[] = [
{ field: 'id', title: 'ID', width: 80 },
{
title: 'Product Details',
columns: [
{ field: 'productName', title: 'Product Name', width: 200 },
{ field: 'category', title: 'Category', width: 150 },
]
},
{ field: 'unitPrice', title: 'Unit Price', width: 120 },
{ field: 'unitsInStock', title: 'Units In Stock', width: 140 },
]
</script>
<template>
<PantanalGrid
:rows="rows"
:columns="columns"
key-field="id"
/>
</template>Nested Column Groups
You can nest column groups to create multiple levels of headers:
<script setup lang="ts">
const columns: ColumnDef[] = [
{ field: 'id', title: 'ID', width: 80 },
{
title: 'Product Details',
columns: [
{ field: 'productName', title: 'Product Name', width: 200 },
{
title: 'Pricing',
columns: [
{ field: 'unitPrice', title: 'Unit Price', width: 120 },
{ field: 'unitsInStock', title: 'Stock', width: 100 },
]
},
{ field: 'category', title: 'Category', width: 150 },
]
},
{ field: 'supplier', title: 'Supplier', width: 150 },
]
</script>With Sorting and Filtering
Multi-column headers support all standard grid features. You can sort and filter by leaf columns (columns with field property):
<script setup lang="ts">
const columns: ColumnDef[] = [
{ field: 'id', title: 'ID', width: 80, sortable: true, filterable: true },
{
title: 'Product Details',
columns: [
{ field: 'productName', title: 'Product Name', width: 200, sortable: true, filterable: true },
{ field: 'category', title: 'Category', width: 150, sortable: true, filterable: true },
]
},
{ field: 'unitPrice', title: 'Unit Price', width: 120, sortable: true, filterable: true },
]
</script>
<template>
<PantanalGrid
:rows="rows"
:columns="columns"
key-field="id"
:sortable="true"
:show-filter-row="true"
/>
</template>With Column Menu
The column menu works with leaf columns in multi-column headers:
<PantanalGrid
:rows="rows"
:columns="columns"
key-field="id"
:column-menu="true"
:column-menu-columns="true"
/>With Grouping
You can group by leaf columns in multi-column headers:
<script setup lang="ts">
import { ref } from 'vue'
import { PantanalGrid, type GroupDescriptor } from '@pantanal/grid'
const group = ref<GroupDescriptor[]>([
{ field: 'category', dir: 'asc' }
])
</script>
<template>
<PantanalGrid
:rows="rows"
:columns="columns"
key-field="id"
:group="group"
/>
</template>Alignment
Multi-column headers are automatically aligned with the body columns below. The grid ensures that:
- Header cells align perfectly with their corresponding data cells
- Column widths are consistent between headers and body
- The alignment is maintained even when columns are resized or reordered
Important Notes
- Leaf columns only: Only columns with a
fieldproperty can be sorted, filtered, or grouped - Header columns: Columns without a
fieldare header-only and cannot have data operations - Nesting depth: You can nest columns to any depth
- Column width: Parent column width is calculated from child columns
- Alignment: Headers are automatically aligned with body columns for perfect visual consistency
See Also
- ColumnDef API - Complete column definition reference
- Grouping Guide - Grouping with multi-column headers