Column
The base class for all other grid column types, used if no type is specified on a column.
Default editor is a TextField.
const grid = new Grid({
columns : [{
field : 'name',
text : 'Name'
}, {
text : 'Hobby',
field : 'others.hobby', // reading nested field data
}, {
type : 'number', // Will use NumberColumn
field : 'age',
text : 'Age'
}]
});
Column types
Grid ships with multiple different column types. Which type to use for a column is specified by the type config. The built-in types are:
- action - displays actions (clickable icons) in the cell.
- aggregate - a column, which, when used as part of a Tree, aggregates the values of this column's descendants using a configured function which defaults to
sum. - check - displays a checkbox in the cell.
- date - displays a date in the specified format.
- number - a column for showing/editing numbers.
- percent - displays a basic progress bar.
- rating - displays a star rating.
- rownumber - displays the row number in each cell.
- template - uses a template for cell content.
- time - displays a time in the specified format.
- tree - displays a tree structure when using the tree feature.
- widget - displays widgets in the cells.
Tree columns
You can add tree rendering to any column type by configuring it with tree : true:
const grid = new TreeGrid({
columns : [
// These are equivalent:
{ type: 'tree', field: 'name' },
{ field: 'name', tree: true },
// Any column type can be a tree column:
{ type: 'check', tree: true, field: 'done' }
]
});
Grouped columns / headers
You can group headers by defining parent and children columns. A group can be dragged as a whole, or users can drag individual columns between groups. The same applies to column visibility using the column picker in the header menu, a group can be toggled as a whole or each column individually.
const grid = new Grid({
{
text : 'Parent',
children : [
{ text : 'Child 1', field : 'field1', flex : 1 },
{ text : 'Child 2', field : 'field2', flex : 1 }
]
},
...
}
Collapsible columns
By configuring a parent column with collapsible: true it is made collapsible. When collapsing all child columns except the first one are hidden. This behaviour is configurable using the collapseMode config. To make a column start collapsed, set the collapsed config to true.
Adding widgets to the column header
You can add custom widgets to the column header element using the headerWidgets config.
Cell renderers and customizing cell content
Completely controlling cell contents
To completely control what is rendered into a cell, provide a renderer function which returns a string or a DomConfig DOM configuration object.
const grid = new Grid({
columns : [
...
{
field : 'approved',
text : 'Approved',
htmlEncode : false, // allow to use HTML code
renderer({ value }) {
return value === true ? '<b>Yes</b>' : '<i>No</i>';
}
}
...
]
});
Augmenting the default rendering
To augment the default rendering of Column types which have their own special renderer, you can call the built-in renderer from your custom renderer, and use the result. For example, to highlight modified dates in a DateColumn:
new Grid({
columns : [
...
{
type : 'date',
field : 'startDate',
text : 'Start Date',
renderer({ record, value }) {
const result = this.defaultRenderer({ value });
return record.isFieldModified('startDate') ? `<span class="modified">${result}</span>` : result;
}
}
]
});
Mutating the cell element after the default rendering
You can also use the afterRenderCell callback to mutate the cell element after the default rendering.
new Grid({
columns : [
{
text : 'Name',
afterRenderCell : ({ record, row, cellElement }) => {
cellElement.classList.toggle('myClass', true);
// Add special CSS class to new rows that have not yet been saved
row.cls.newRow = record.isPhantom;
}
}
]
});
Using JSX in renderers (React)
When using the Bryntum React wrapper, renderers can return JSX elements instead of strings or DomConfig objects:
// In your React component's column config:
const columns = [
{
text : 'Name',
field : 'name',
renderer({ record }) {
return <MyCustomComponent name={record.name} />;
}
}
];
// Then pass to the wrapper:
<BryntumGrid columns={columns} />
Menus
You can add custom items to the context menu for a columns header and for its cells, using headerMenuItems and cellMenuItems. Here is an example:
const grid = new Grid({
columns : [
...
{
type : 'number',
field : 'age',
text : 'Age',
headerMenuItems: [{
text : 'My unique header item',
icon : 'fa fa-paw',
onItem() { console.log('item clicked'); }
}],
cellMenuItems: [{
text : 'My unique cell item',
icon : 'fa fa-plus',
onItem() { console.log('item clicked'); }
}]
}
...
]
});
Useful configs and functions
| Member | Description |
|---|---|
| field | Data model field to display |
| text | Column header text |
| renderer | Custom cell render function |
| editor | Cell editor config or widget type |
| width | Fixed column width in pixels |
| flex | Flex value for proportional sizing |
| hidden | Hides the column |
| sortable | Enable/disable column sorting |
| filterable | Enable/disable column filtering |
| headerMenuItems | Custom header context menu items |
| cellMenuItems | Custom cell context menu items |
See also
- ColumnStore - Store that manages column instances
- Grid - The main grid component
- ColumnReorder - Drag to reorder columns
- ColumnResize - Drag to resize columns
Configs
Configs are options you supply in a configuration object when creating an instance of this class-
Mode to use when measuring the contents of this column in calls to resizeToFitContent. Available modes are:
- 'exact' - Most precise, renders and measures all cells (Default, slowest)
- 'textContent' - Renders all cells but only measures the one with the longest
textContent - 'value' - Renders and measures only the cell with the longest data (Fastest)
- 'none'/falsy - Resize to fit content not allowed, a call does nothing
Has a corresponding runtime fitMode property.
-
Column width as a flex weight. All columns with flex specified divide the available space (after subtracting fixed widths) between them according to the flex value. Columns that have
flex : 2will be twice as wide as those withflex : 1(and so on)Has a corresponding runtime flex property.
-
Column maximal width. If value is Number, then maximal width is in pixels
Has a corresponding runtime maxWidth property.
-
The text to show in the column header. You can display text vertically by setting the headerWritingMode property.
Has a corresponding runtime text property.
-
Column width. If value is Number then width is in pixels
Has a corresponding runtime width property.
-
Set to
trueto have the cell editor for this column inherit formula providers from the Grid's configured formulaProviders.Has a corresponding runtime formula property.
-
Set to
'end'or'start'to pin the column to the respective side of the grid when PinColumns feature is enabled.Has a corresponding runtime pinned property.
-
When a column is pinned and it does not have a
widthspecified,pinnedWidthwill be used instead.Has a corresponding runtime pinnedWidth property.
-
Set this to
trueto not allow any type of editing in this column.Has a corresponding runtime readOnly property.
-
The
aria-labelto use for this Column`s header elementHas a corresponding runtime ariaLabel property.
-
The
aria-labelto use for cells in this ColumnHas a corresponding runtime cellAriaLabel property.
-
Used by the Export feature. Set to
falseto omit a column from an exported datasetHas a corresponding runtime exportable property.
-
Column type which will be used by TableExporter. See list of available types in TableExporter docs. Returns undefined by default, which means column type should be read from the record field.
Has a corresponding runtime exportedType property.
-
Flag to enable vue component rendering
Has a corresponding runtime vue property.
-
A config object used to configure an Editor which contains this Column's input field if CellEdit feature is enabled.
Has a corresponding runtime cellEditor property.
-
The collapsed state of this column, only applicable for parent columns
Has a corresponding runtime collapsed property.
-
If
true, this column will show a collapse/expand icon in its header, only applicable for parent columnsHas a corresponding runtime collapsible property.
-
Set to
falseto prevent this column header from being draggedHas a corresponding runtime draggable property.
-
Set to
falseto prevent grouping by this columnHas a corresponding runtime groupable property.
-
Allow column visibility to be toggled through UI
Has a corresponding runtime hideable property.
-
How to handle a request to complete a cell edit in this column if the field is invalid. There are three choices:
blockThe default. The edit is not exited, the field remains focused.allowAllow the edit to be completed.revertThe field value is reverted and the edit is completed.
Has a corresponding runtime invalidAction property.
-
Set to
falseto prevent the column from being drag-resized when the ColumnResize plugin is enabled.Has a corresponding runtime resizable property.
-
Setting this option means that pressing the Escape key after editing the field will revert the field to the value it had when the edit began. If the value is not changed from when the edit started, the input field's clearable behaviour will be activated. Finally, the edit will be canceled.
Has a corresponding runtime revertOnEscape property.
-
Setting this flag to
truewill prevent dropping child columns into a group columnHas a corresponding runtime sealed property.
-
Allow searching in the column (respected by QuickFind and Search features)
Has a corresponding runtime searchable property.
-
Text align. Accepts
'left'/'center'/'right'or direction neutral'start'/'end'Has a corresponding runtime align property.
-
Convenient way of putting a column in the "locked" region. Same effect as specifying region: 'locked'. If you have defined your own regions (using subGridConfigs) you should use region instead of this one.
Has a corresponding runtime locked property.
-
Column minimum width. If value is
Number, then minimal width is in pixelsHas a corresponding runtime minWidth property.
-
Set to
falseto prevent showing a context menu on the cell elements in this columnHas a corresponding runtime enableCellContextMenu property.
-
false to prevent showing a context menu on the column header element
Has a corresponding runtime enableHeaderContextMenu property.
-
Show column picker for the column
Has a corresponding runtime showColumnPicker property.
-
Set to
trueto automatically call DomHelper.sync for html returned from a renderer. Should in most cases be more performant than replacing entire innerHTML of cell and also allows CSS transitions to work. Has no effect unless htmlEncode is disabled. Returned html must contain a single root element (that can have multiple children). See PercentColumn for example usage.Has a corresponding runtime autoSyncHtml property.
-
An optional query selector to select a sub element within the cell being edited to align a cell editor's
Xposition andwidthto.Has a corresponding runtime editTargetSelector property.
-
Determines which type of filtering to use for the column. Usually determined by the column type used, but may be overridden by setting this field.
Has a corresponding runtime filterType property.
-
By default, any rendered column cell content is HTML-encoded. Set this flag to
falsedisable this and allow rendering html elementsHas a corresponding runtime htmlEncode property.
-
By default, the header text is HTML-encoded. Set this flag to
falsedisable this and allow html elements in the column headerHas a corresponding runtime htmlEncodeHeaderText property.
-
Set to
trueto have the CellEdit feature update the record being edited live upon field edit instead of when editing is finished by using Tab or EnterHas a corresponding runtime instantUpdate property.
-
Column settings at different responsive levels, see responsive demo under examples/
Has a corresponding runtime responsiveLevels property.
-
Column config to apply to normal config if viewed on a touch device
Has a corresponding runtime touchConfig property.
-
When using the tree feature, exactly one column should specify { tree: true }
Has a corresponding runtime tree property.
-
CSS class added to each cell in this column
Has a corresponding runtime cellCls property.
-
CSS class added to the header of this column
Has a corresponding runtime cls property.
-
Icon to display in header. Specifying an icon will render a
<i>element with the icon as value for the class attributeHas a corresponding runtime icon property.
-
A tooltip string to show when hovering the column header, or a config object which can reconfigure the shared tooltip by setting boolean, numeric and string config values.
Has a corresponding runtime tooltip property.
-
Summary configs, use if you need multiple summaries per column. Replaces sum and summaryRenderer configs.
Has a corresponding runtime summaries property.
Properties
Properties are getters/setters or publicly accessible variables on this class-
Identifies an object as an instance of Column class, or subclass thereof.
-
Mode to use when measuring the contents of this column in calls to resizeToFitContent. Available modes are:
- 'exact' - Most precise, renders and measures all cells (Default, slowest)
- 'textContent' - Renders all cells but only measures the one with the longest
textContent - 'value' - Renders and measures only the cell with the longest data (Fastest)
- 'none'/falsy - Resize to fit content not allowed, a call does nothing
Has a corresponding fitMode config.
-
Column width as a flex weight. All columns with flex specified divide the available space (after subtracting fixed widths) between them according to the flex value. Columns that have
flex : 2will be twice as wide as those withflex : 1(and so on)Has a corresponding flex config.
-
Column maximal width. If value is Number, then maximal width is in pixels
Has a corresponding maxWidth config.
-
The text to show in the column header. You can display text vertically by setting the headerWritingMode property.
Has a corresponding text config.
-
Column width. If value is Number then width is in pixels
Has a corresponding width config.
-
Index among all flattened columns
-
A config object specifying the editor to use to edit this column.
-
Default settings for the column, applied in constructor. None by default, override in subclass.
-
The Field to use as editor for this column
Has a corresponding editor config.
-
Set to
trueto have the cell editor for this column inherit formula providers from the Grid's configured formulaProviders.Has a corresponding formula config.
-
Get the Grid instance to which this column belongs
-
Returns header text based on htmlEncodeHeaderText config value.
-
An object which contains a map of the widgets contained in this column header keyed by their ref.
-
An object which contains a map of the header widgets keyed by their ref.
-
Set to
'end'or'start'to pin the column to the respective side of the grid when PinColumns feature is enabled.Has a corresponding pinned config.
-
When a column is pinned and it does not have a
widthspecified,pinnedWidthwill be used instead.Has a corresponding pinnedWidth config.
-
Set this to
trueto not allow any type of editing in this column.Has a corresponding readOnly config.
-
Get the SubGrid to which this column belongs
-
Get the element for the SubGrid to which this column belongs
-
Column name alias, which you can use in the
columnsarray of a Grid. See type -
Set this column to be visible or not
-
The
aria-labelto use for this Column`s header elementHas a corresponding ariaLabel config.
-
The
aria-labelto use for cells in this ColumnHas a corresponding cellAriaLabel config.
-
Identifies an object as an instance of Column class, or subclass thereof.
-
Used by the Export feature. Set to
falseto omit a column from an exported datasetHas a corresponding exportable config.
-
Column type which will be used by TableExporter. See list of available types in TableExporter docs. Returns undefined by default, which means column type should be read from the record field.
Has a corresponding exportedType config.
-
Flag to enable vue component rendering
Has a corresponding vue config.
-
A config object used to configure an Editor which contains this Column's input field if CellEdit feature is enabled.
Has a corresponding cellEditor config.
-
The collapsed state of this column, only applicable for parent columns
Has a corresponding collapsed config.
-
If
true, this column will show a collapse/expand icon in its header, only applicable for parent columnsHas a corresponding collapsible config.
-
Set to
falseto prevent this column header from being draggedHas a corresponding draggable config.
-
Set to
falseto prevent grouping by this columnHas a corresponding groupable config.
-
Allow column visibility to be toggled through UI
Has a corresponding hideable config.
-
How to handle a request to complete a cell edit in this column if the field is invalid. There are three choices:
blockThe default. The edit is not exited, the field remains focused.allowAllow the edit to be completed.revertThe field value is reverted and the edit is completed.
Has a corresponding invalidAction config.
-
Set to
falseto prevent the column from being drag-resized when the ColumnResize plugin is enabled.Has a corresponding resizable config.
-
Setting this option means that pressing the Escape key after editing the field will revert the field to the value it had when the edit began. If the value is not changed from when the edit started, the input field's clearable behaviour will be activated. Finally, the edit will be canceled.
Has a corresponding revertOnEscape config.
-
Setting this flag to
truewill prevent dropping child columns into a group columnHas a corresponding sealed config.
-
Allow searching in the column (respected by QuickFind and Search features)
Has a corresponding searchable config.
-
Text align. Accepts
'left'/'center'/'right'or direction neutral'start'/'end'Has a corresponding align config.
-
Convenient way of putting a column in the "locked" region. Same effect as specifying region: 'locked'. If you have defined your own regions (using subGridConfigs) you should use region instead of this one.
Has a corresponding locked config.
-
Column minimum width. If value is
Number, then minimal width is in pixelsHas a corresponding minWidth config.
-
Set to
falseto prevent showing a context menu on the cell elements in this columnHas a corresponding enableCellContextMenu config.
-
false to prevent showing a context menu on the column header element
Has a corresponding enableHeaderContextMenu config.
-
Show column picker for the column
Has a corresponding showColumnPicker config.
-
Set to
trueto automatically call DomHelper.sync for html returned from a renderer. Should in most cases be more performant than replacing entire innerHTML of cell and also allows CSS transitions to work. Has no effect unless htmlEncode is disabled. Returned html must contain a single root element (that can have multiple children). See PercentColumn for example usage.Has a corresponding autoSyncHtml config.
-
An optional query selector to select a sub element within the cell being edited to align a cell editor's
Xposition andwidthto.Has a corresponding editTargetSelector config.
-
Determines which type of filtering to use for the column. Usually determined by the column type used, but may be overridden by setting this field.
Has a corresponding filterType config.
-
By default, any rendered column cell content is HTML-encoded. Set this flag to
falsedisable this and allow rendering html elementsHas a corresponding htmlEncode config.
-
By default, the header text is HTML-encoded. Set this flag to
falsedisable this and allow html elements in the column headerHas a corresponding htmlEncodeHeaderText config.
-
Set to
trueto have the CellEdit feature update the record being edited live upon field edit instead of when editing is finished by using Tab or EnterHas a corresponding instantUpdate config.
-
Column settings at different responsive levels, see responsive demo under examples/
Has a corresponding responsiveLevels config.
-
Column config to apply to normal config if viewed on a touch device
Has a corresponding touchConfig config.
-
When using the tree feature, exactly one column should specify { tree: true }
Has a corresponding tree config.
-
CSS class added to each cell in this column
Has a corresponding cellCls config.
-
CSS class added to the header of this column
Has a corresponding cls config.
-
Icon to display in header. Specifying an icon will render a
<i>element with the icon as value for the class attributeHas a corresponding icon config.
-
A tooltip string to show when hovering the column header, or a config object which can reconfigure the shared tooltip by setting boolean, numeric and string config values.
Has a corresponding tooltip config.
-
Summary type (when using Summary feature). Valid types are:
'sum'- Sum of all values in the column'add'- Alias for sum'count'- Number of rows'countNotEmpty'- Number of rows containing a value'average'- Average of all values in the columncallbackFn- A custom function, used withstore.reduce. Its return value becomes the value of the accumulator parameter on the next invocation of callbackFn
Has a corresponding sum config.
-
Summary configs, use if you need multiple summaries per column. Replaces sum and summaryRenderer configs.
Has a corresponding summaries config.
Functions
Functions are methods available for calling on the class-
applyState( )private
Apply state to column, used by State mixin
-
getState( )private
Get column state, used by State mixin
-
Hides this column.
-
refreshCells( )
Refreshes all the cells for this column
-
Rerender the header for this column
-
Shows this column.