ColDef) define the structure and behavior of individual columns in your grid. Each column can be extensively customized for display, editing, filtering, and sorting.
Overview
Columns are defined using thecolumnDefs property in GridOptions:
Basic Column Properties
Identification
Unique ID for the column. If not provided, defaults to
field. Used in API methods to reference columns.The field of the row object to get data from. Supports dot notation for nested properties.
Display
The name to render in the column header. If not specified and field is set, the field name is used.
Function or expression to get the header value dynamically.
Set to true to hide this column initially.
Width Configuration
Column Sizing Options
Column Sizing Options
Initial width in pixels. Defaults to 200px if not specified.
Minimum width in pixels.
Maximum width in pixels.
Flex sizing similar to CSS flexbox. Columns with flex share available space proportionally.
Enable/disable column resizing.
Value Handling
Getting Values
Function or expression to get the cell value. Use instead of
field for computed values.Function to format values for display.
Setting Values
Function to set the cell value back into your data. Return true if data changed.
Function to parse user input for saving.
Sorting
Enable/disable sorting for this column.
Initial sort direction.
When sorting by multiple columns, specifies the order.
Custom sort comparator function.
Filtering
Enable filtering and specify the filter type.
Parameters for the filter component.
Show a floating filter for this column.
Editing
Enable editing for this column. Can be a function for conditional editing.
Specify the cell editor component.
Parameters for the cell editor.
Start editing on single click instead of double click.
Cell Rendering
Custom cell renderer component.
Parameters passed to the cell renderer.
Styling
CSS styles to apply to cells.
CSS classes to apply to cells.
Rules for applying CSS classes based on conditions.
Pinning
Pin column to left or right side of the grid.
Prevent users from pinning/unpinning this column via UI.
Column Types
Reuse column configurations with column types:Column Groups
Group related columns together:Common Patterns
Before/After: Adding Computed Columns
Before/After: Adding Custom Filtering
Before/After: Adding Custom Cell Rendering
Type Safety
Use TypeScript for type-safe column definitions:Best Practices
- Use field names - Prefer
fieldovervalueGetterwhen possible for better performance - Leverage defaultColDef - Set common properties once in
defaultColDef - Use column types - Create reusable column configurations for consistency
- Provide colId - Essential for dynamically updating column definitions
- Optimize value getters - Avoid expensive computations in
valueGetterfunctions - Type your data - Use TypeScript generics for better IDE support
Related
- GridOptions - Configure the entire grid
- Grid API - Column manipulation methods
- Row Data - Understanding row data structure