v7.3.0

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} />

Using JSX in renderers creates a React portal for each rendered cell. For grids with many rows or frequently re-rendered views, this may impact scrolling performance compared to returning plain strings or DomConfig objects. Consider using JSX renderers primarily for cells that require complex interactive React components.

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'); }
      }]
    }
  ...
  ]
});

Columns without a width will shrink or expand to the pinnedWidth value when pinned.

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

No results

Configs

Configs are options you supply in a configuration object when creating an instance of this class
  • fitMode : 'exact'/'textContent'/'value'/'none'/null'exact'

    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 : 2 will be twice as wide as those with flex : 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 true to have the cell editor for this column inherit formula providers from the Grid's configured formulaProviders.

    Has a corresponding runtime formula property.

  • pinned : 'start'/'end'/null/false

    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 width specified, pinnedWidth will be used instead.

    Has a corresponding runtime pinnedWidth property.

  • Set this to true to not allow any type of editing in this column.

    Has a corresponding runtime readOnly property.

  • The aria-label to use for this Column`s header element

    Has a corresponding runtime ariaLabel property.

  • The aria-label to use for cells in this Column

    Has a corresponding runtime cellAriaLabel property.

  • Used by the Export feature. Set to false to omit a column from an exported dataset

    Has 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 columns

    Has a corresponding runtime collapsible property.

  • Set to false to prevent this column header from being dragged

    Has a corresponding runtime draggable property.

  • Set to false to prevent grouping by this column

    Has a corresponding runtime groupable property.

  • Allow column visibility to be toggled through UI

    Has a corresponding runtime hideable property.

  • invalidAction : 'block'/'allow'/'revert''block'

    How to handle a request to complete a cell edit in this column if the field is invalid. There are three choices:

    • block The default. The edit is not exited, the field remains focused.
    • allow Allow the edit to be completed.
    • revert The field value is reverted and the edit is completed.

    Has a corresponding runtime invalidAction property.

  • Set to false to 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.

  • sealed : Booleanfalse

    Setting this flag to true will prevent dropping child columns into a group column

    Has a corresponding runtime sealed property.

  • Allow searching in the column (respected by QuickFind and Search features)

    Has a corresponding runtime searchable property.

  • align : 'left'/'center'/'right'/'start'/'end'

    Text align. Accepts 'left'/'center'/'right' or direction neutral 'start'/'end'

    Has a corresponding runtime align property.

  • Columns hidden state. Specify true to hide the column, false to show it.

    Has a corresponding runtime hidden property.

  • locked : Booleanfalse

    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 pixels

    Has a corresponding runtime minWidth property.

  • Set to false to prevent showing a context menu on the cell elements in this column

    Has 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 X position and width to.

    Has a corresponding runtime editTargetSelector property.

  • filterType : 'text'/'date'/'number'/'duration'

    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 false disable this and allow rendering html elements

    Has a corresponding runtime htmlEncode property.

  • By default, the header text is HTML-encoded. Set this flag to false disable this and allow html elements in the column header

    Has a corresponding runtime htmlEncodeHeaderText property.

  • Set to true to have the CellEdit feature update the record being edited live upon field edit instead of when editing is finished by using Tab or Enter

    Has a corresponding runtime instantUpdate property.

  • Column settings at different responsive levels, see responsive demo under examples/

    Has a corresponding runtime responsiveLevels property.

  • Tags, may be used by ColumnPicker feature for grouping columns by tag in the menu

    Has a corresponding runtime tags 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 attribute

    Has 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
  • isColumn : Booleantrue
    READONLY
    static
    ADVANCED
    Identifies an object as an instance of Column class, or subclass thereof.
  • fitMode : 'exact'/'textContent'/'value'/'none'/null'exact'

    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 : 2 will be twice as wide as those with flex : 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.

  • allIndex : Number
    internal
    READONLY

    Index among all flattened columns

  • canSort : Boolean
    READONLY

    Returns true if this column can currently be sorted by the user. Checks both the column's own sortable config and whether the Sort feature is enabled on the grid.

  • defaultEditor : Object
    private
    READONLY

    A config object specifying the editor to use to edit this column.

  • defaults : Object
    READONLY

    Default settings for the column, applied in constructor. None by default, override in subclass.

  • editor : Field
    private
    READONLY

    The Field to use as editor for this column

    Has a corresponding editor config.

  • editorField : String
    internal
    READONLY

    Yields the name of the record field which the CellEdit feature edits when invoked on this column. This is usually this Column's field, but Column subclasses may implement this property.

  • Set to true to have the cell editor for this column inherit formula providers from the Grid's configured formulaProviders.

    Has a corresponding formula config.

  • grid : Grid
    READONLY

    Get the Grid instance to which this column belongs

  • headerText : String
    internal
    READONLY

    Returns header text based on htmlEncodeHeaderText config value.

  • headerWidgetMap : Object<String, Widget>
    internal
    READONLY

    An object which contains a map of the widgets contained in this column header keyed by their ref.

  • headerWidgetMap : Object<String, Widget>
    private
    READONLY

    An object which contains a map of the header widgets keyed by their ref.

  • pinned : 'start'/'end'/null/false

    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 width specified, pinnedWidth will be used instead.

    Has a corresponding pinnedWidth config.

  • Set this to true to not allow any type of editing in this column.

    Has a corresponding readOnly config.

  • subGrid : SubGrid
    READONLY

    Get the SubGrid to which this column belongs

  • subGridElement : HTMLElement
    private
    READONLY

    Get the element for the SubGrid to which this column belongs

  • type : String
    READONLY

    Column name alias, which you can use in the columns array of a Grid. See type

  • Set this column to be visible or not

  • The aria-label to use for this Column`s header element

    Has a corresponding ariaLabel config.

  • The aria-label to use for cells in this Column

    Has a corresponding cellAriaLabel config.

  • isColumn : Booleantrue
    READONLY
    ADVANCED
    Identifies an object as an instance of Column class, or subclass thereof.
  • Used by the Export feature. Set to false to omit a column from an exported dataset

    Has 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 columns

    Has a corresponding collapsible config.

  • Set to false to prevent this column header from being dragged

    Has a corresponding draggable config.

  • Set to false to prevent grouping by this column

    Has a corresponding groupable config.

  • Allow column visibility to be toggled through UI

    Has a corresponding hideable config.

  • invalidAction : 'block'/'allow'/'revert''block'

    How to handle a request to complete a cell edit in this column if the field is invalid. There are three choices:

    • block The default. The edit is not exited, the field remains focused.
    • allow Allow the edit to be completed.
    • revert The field value is reverted and the edit is completed.

    Has a corresponding invalidAction config.

  • Set to false to 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.

  • sealed : Booleanfalse

    Setting this flag to true will prevent dropping child columns into a group column

    Has a corresponding sealed config.

  • Allow searching in the column (respected by QuickFind and Search features)

    Has a corresponding searchable config.

  • align : 'left'/'center'/'right'/'start'/'end'

    Text align. Accepts 'left'/'center'/'right' or direction neutral 'start'/'end'

    Has a corresponding align config.

  • Columns hidden state. Specify true to hide the column, false to show it.

    Has a corresponding hidden config.

  • locked : Booleanfalse

    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 pixels

    Has a corresponding minWidth config.

  • Set to false to prevent showing a context menu on the cell elements in this column

    Has 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 X position and width to.

    Has a corresponding editTargetSelector config.

  • filterType : 'text'/'date'/'number'/'duration'

    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 false disable this and allow rendering html elements

    Has a corresponding htmlEncode config.

  • By default, the header text is HTML-encoded. Set this flag to false disable this and allow html elements in the column header

    Has a corresponding htmlEncodeHeaderText config.

  • Set to true to have the CellEdit feature update the record being edited live upon field edit instead of when editing is finished by using Tab or Enter

    Has a corresponding instantUpdate config.

  • Column settings at different responsive levels, see responsive demo under examples/

    Has a corresponding responsiveLevels config.

  • Tags, may be used by ColumnPicker feature for grouping columns by tag in the menu

    Has a corresponding tags config.

  • Column config to apply to normal config if viewed on a touch device

    Has a corresponding touchConfig config.

  • tree : Boolean
    READONLY

    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 attribute

    Has 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.

  • sum : 'sum'/'add'/'count'/'countNotEmpty'/'average'+ 1 more

    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 column
    • callbackFn - A custom function, used with store.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

    • hide( )
      ASYNC

      Hides this column.

    • Refreshes all the cells for this column

    • Rerender the header for this column

    • show( )
      ASYNC

      Shows this column.

    type: column

    Source path

    Grid/column/Column.js

    Contents