ColumnDef API Reference
Complete reference for the ColumnDef interface used to configure grid columns.
Interface
interface ColumnDef<T = Row> {
// Basic properties
field?: keyof T | string
title?: string
width?: number | string
// Features
sortable?: boolean
filterable?: boolean
editable?: boolean | ((row: T) => boolean)
resizable?: boolean
reorderable?: boolean
// Formatting
format?: string | ((value: any, row: T) => string)
type?: 'string' | 'number' | 'boolean' | 'date'
encoded?: boolean // HTML encode (default: true)
// Templates
template?: ColumnTemplateFn<T>
cell?: (ctx: { value: any; row: T; rowIndex: number }) => any
headerTemplate?: string | ((column: ColumnDef<T>) => string)
footerTemplate?: string | ((aggregates: Record<string, any>) => string)
groupHeaderTemplate?: string | ((group: GroupInfo) => string)
groupHeaderColumnTemplate?: string | ((group: GroupInfo, column: ColumnDef<T>) => string)
groupFooterTemplate?: string | ((group: GroupInfo) => string)
// Editor
editor?: (container: HTMLElement, options: { field: string; value: any; row: T }) => void | HTMLElement
// Validation
validation?: {
required?: boolean
min?: number
max?: number
pattern?: RegExp | string
validator?: (value: any, row: T) => boolean | string
[key: string]: any
}
// Positioning
pinned?: boolean | 'left' | 'right'
locked?: boolean | 'left' | 'right'
lockable?: boolean
// Visibility
hidden?: boolean
media?: string // Media query string
minScreenWidth?: number
// Sorting
sortableAllowUnsort?: boolean
sortableCompare?: (a: any, b: any, descending?: boolean) => number
sortableInitialDirection?: 'asc' | 'desc'
// Grouping
groupable?: boolean
groupableSortCompare?: (a: any, b: any) => number
groupableSortDir?: 'asc' | 'desc'
// Aggregates
aggregates?: AggregateName[]
// Filtering
filterableMode?: 'row' | 'menu' | false
filterableMulti?: boolean
filterableExtra?: boolean
filterableOperator?: FilterDescriptor['operator']
filterableDefaultOperator?: FilterDescriptor['operator']
filterableDataSource?: any[] | (() => any[])
filterableSearch?: boolean
filterableCheckAll?: boolean
filterableItemTemplate?: (item: any, field: string) => string | VNode
filterableUI?: 'textbox' | 'numeric' | 'date' | 'boolean' | 'dropdown' | Function
filterableOperators?: Record<string, Record<string, string>>
filterableOptions?: Array<{ value: any; label: string }> | (() => Array<{ value: any; label: string }>)
filterableIgnoreCase?: boolean
filterableCellDelay?: number
filterableCellMinLength?: number
filterableCellOperator?: string
filterableCellShowOperators?: boolean
filterableCellDataSource?: any[] | (() => any[]) | Record<string, any>
filterableCellDataTextField?: string
filterableCellInputWidth?: number
filterableCellSuggestionOperator?: 'startswith' | 'endswith' | 'contains'
filterableCellEnabled?: boolean
filterableCellTemplate?: (element: HTMLElement, options: { field: string; dataSource: any }) => void
// Commands
command?: ('edit' | 'destroy' | 'save' | 'cancel')[] | CommandDef[] | CommandDef
// Column groups
columns?: ColumnDef<T>[]
// Attributes
attributes?: Record<string, string | number | boolean>
headerAttributes?: Record<string, string | number | boolean>
footerAttributes?: Record<string, string | number | boolean>
// Other
slot?: string
selectable?: boolean
values?: Array<{ text: string; value: any }>
menu?: boolean
minResizableWidth?: number
}Properties
Basic Properties
field
Field name from row data.
field?: keyof T | stringExample:
{ field: 'name' }
{ field: 'product.price' } // Nested fieldtitle
Column header title.
title?: stringExample:
{ field: 'name', title: 'Product Name' }width
Column width in pixels or CSS value.
width?: number | stringExample:
{ field: 'id', width: 80 }
{ field: 'name', width: '200px' }
{ field: 'description' } // Flexible widthFeature Properties
sortable
Enable sorting for this column.
sortable?: booleanExample:
{ field: 'price', sortable: true }filterable
Enable filtering for this column.
filterable?: booleanExample:
{ field: 'category', filterable: true }editable
Enable editing for this column.
editable?: boolean | ((row: T) => boolean)Example:
{ field: 'name', editable: true }
{ field: 'price', editable: (row) => row.status === 'active' }resizable
Allow column resizing.
resizable?: booleanDefault: true
reorderable
Allow column reordering.
reorderable?: booleanDefault: true
Formatting Properties
format
Format function or format string.
format?: string | ((value: any, row: T) => string)Example:
{ field: 'price', format: (v) => `$${v.toFixed(2)}` }
{ field: 'date', format: 'date' }type
Column data type.
type?: 'string' | 'number' | 'boolean' | 'date'Example:
{ field: 'price', type: 'number' }
{ field: 'createdAt', type: 'date' }encoded
HTML encode column value.
encoded?: booleanDefault: true
Template Properties
template
Custom cell template function.
template?: ColumnTemplateFn<T>Example:
{
field: 'status',
template: ({ value }) => {
return h('span', {
class: value === 'active' ? 'text-green-500' : 'text-red-500'
}, value)
}
}cell
Custom cell renderer.
cell?: (ctx: { value: any; row: T; rowIndex: number }) => anyExample:
{
field: 'rating',
cell: ({ value }) => '⭐'.repeat(Math.floor(value))
}headerTemplate
Custom header template.
headerTemplate?: string | ((column: ColumnDef<T>) => string)Example:
{
field: 'name',
headerTemplate: (col) => `<strong>${col.title}</strong>`
}footerTemplate
Custom footer template (for aggregates).
footerTemplate?: string | ((aggregates: Record<string, any>) => string)Example:
{
field: 'price',
footerTemplate: (aggs) => `Total: $${aggs.price_sum?.toFixed(2)}`
}Positioning Properties
pinned
Pin column to left or right.
pinned?: boolean | 'left' | 'right'Example:
{ field: 'id', pinned: 'left' }
{ field: 'actions', pinned: 'right' }locked
Lock column position.
locked?: boolean | 'left' | 'right'Example:
{ field: 'id', locked: 'left' }lockable
Allow locking/unlocking.
lockable?: booleanDefault: true
Visibility Properties
hidden
Hide column.
hidden?: booleanExample:
{ field: 'internal', hidden: true }media
Media query for responsive visibility.
media?: stringExample:
{ field: 'description', media: '(min-width: 768px)' }minScreenWidth
Hide column below this width.
minScreenWidth?: numberExample:
{ field: 'description', minScreenWidth: 768 }Sorting Properties
sortableCompare
Custom sort function.
sortableCompare?: (a: any, b: any, descending?: boolean) => numberExample:
{
field: 'name',
sortableCompare: (a, b, desc) => {
const result = a.localeCompare(b)
return desc ? -result : result
}
}sortableInitialDirection
Initial sort direction.
sortableInitialDirection?: 'asc' | 'desc'Example:
{ field: 'price', sortableInitialDirection: 'desc' }sortableAllowUnsort
Allow unsorting this column.
sortableAllowUnsort?: booleanDefault: Inherits from grid prop
Grouping Properties
groupable
Allow grouping by this column.
groupable?: booleanDefault: true
groupableSortCompare
Custom group sort function.
groupableSortCompare?: (a: any, b: any) => numbergroupableSortDir
Group sort direction.
groupableSortDir?: 'asc' | 'desc'Filtering Properties
filterableMode
Filter UI mode.
filterableMode?: 'row' | 'menu' | falseExample:
{ field: 'category', filterableMode: 'menu' }filterableUI
Filter input type.
filterableUI?: 'textbox' | 'numeric' | 'date' | 'boolean' | 'dropdown' | FunctionExample:
{ field: 'category', filterableUI: 'dropdown' }
{ field: 'active', filterableUI: 'boolean' }filterableOptions
Options for dropdown filter.
filterableOptions?: Array<{ value: any; label: string }> | (() => Array<{ value: any; label: string }>)Example:
{
field: 'status',
filterableUI: 'dropdown',
filterableOptions: [
{ value: 'active', label: 'Active' },
{ value: 'inactive', label: 'Inactive' }
]
}filterableOperator
Default filter operator.
filterableOperator?: FilterDescriptor['operator']Example:
{ field: 'name', filterableOperator: 'startswith' }filterableMulti
Allow multiple filter criteria.
filterableMulti?: booleanfilterableExtra
Allow second filter criterion.
filterableExtra?: booleanfilterableIgnoreCase
Case-insensitive filtering.
filterableIgnoreCase?: booleanCommand Properties
command
Command buttons configuration.
command?: ('edit' | 'destroy' | 'save' | 'cancel')[] | CommandDef[] | CommandDefExample:
// Simple
{ field: 'command', command: ['edit', 'destroy'] }
// Custom
{
field: 'command',
command: {
name: 'custom',
text: 'Custom Action',
click: (e, row) => console.log(row)
}
}Column Groups
columns
Nested columns for multi-level headers.
columns?: ColumnDef<T>[]Example:
{
title: 'Product Info',
columns: [
{ field: 'name', title: 'Name' },
{ field: 'price', title: 'Price' }
]
}Aggregates
aggregates
Aggregate functions for this column.
aggregates?: AggregateName[]Example:
{ field: 'price', aggregates: ['sum', 'avg'] }Validation
validation
Validation rules.
validation?: {
required?: boolean
min?: number
max?: number
pattern?: RegExp | string
validator?: (value: any, row: T) => boolean | string
[key: string]: any
}Example:
{
field: 'price',
validation: {
required: true,
min: 0,
max: 10000,
validator: (value) => {
if (value < 0) return 'Price cannot be negative'
return true
}
}
}Editor
editor
Custom editor function.
editor?: (container: HTMLElement, options: { field: string; value: any; row: T }) => void | HTMLElementExample:
{
field: 'category',
editor: (container, options) => {
const select = document.createElement('select')
select.innerHTML = '<option>Electronics</option><option>Clothing</option>'
select.value = options.value || ''
container.appendChild(select)
return select
}
}Attributes
attributes
HTML attributes for cells.
attributes?: Record<string, string | number | boolean>Example:
{ field: 'email', attributes: { 'data-type': 'email' } }headerAttributes
HTML attributes for header.
headerAttributes?: Record<string, string | number | boolean>footerAttributes
HTML attributes for footer.
footerAttributes?: Record<string, string | number | boolean>Other Properties
slot
Slot name for custom rendering.
slot?: stringselectable
Make this a selectable checkbox column.
selectable?: booleanvalues
Value mapping (for enum-like fields).
values?: Array<{ text: string; value: any }>Example:
{
field: 'status',
values: [
{ text: 'Active', value: 1 },
{ text: 'Inactive', value: 0 }
]
}menu
Show in column menu.
menu?: booleanDefault: true
minResizableWidth
Minimum width for resizing.
minResizableWidth?: numberComplete Example
const columns: ColumnDef[] = [
{
field: 'id',
title: 'ID',
width: 80,
pinned: 'left',
locked: 'left',
sortable: true,
filterable: true
},
{
field: 'name',
title: 'Product Name',
width: 200,
sortable: true,
filterable: true,
editable: true,
validation: {
required: true
}
},
{
field: 'price',
title: 'Price',
width: 120,
type: 'number',
sortable: true,
filterable: true,
editable: true,
format: (v) => `$${v.toFixed(2)}`,
aggregates: ['sum', 'avg'],
validation: {
required: true,
min: 0
}
},
{
field: 'status',
title: 'Status',
filterable: true,
filterableUI: 'dropdown',
filterableOptions: [
{ value: 'active', label: 'Active' },
{ value: 'inactive', label: 'Inactive' }
],
template: ({ value }) => {
const color = value === 'active' ? 'green' : 'red'
return `<span style="color: ${color}">${value}</span>`
}
},
{
field: 'command',
title: 'Actions',
width: 150,
command: ['edit', 'destroy']
}
]See Also
- PantanalGrid API - Main component reference
- GridProps API - All props interface
- Column Management Guide - Usage guide