TemplateColumn

A column that uses a template for cell content. Any function can be used as template, and the function is passed { value, record, field } properties. It should return a string which will be rendered in the cell.

Default editor is a TextField.

new Grid({
    appendTo : document.body,

    columns : [
        { type: 'template', field: 'age', template: ({value}) => `${value} years old` }
    ]
});

Template column
//<code-header>
fiddle.title = 'Template column';
//</code-header>
// grid with TemplateColumn
const grid = new Grid({
    appendTo : targetElement,

    // makes grid as high as it needs to be to fit rows
    autoHeight : true,
    rowHeight  : 100,
    readOnly   : true,
    data       : [
        { id : 1, name : 'Sweden', population : 10.3, flagImg : 'data/Core/images/flag/swe.png' },
        { id : 2, name : 'Denmark', population : 5.8, flagImg : 'data/Core/images/flag/den.png' },
        { id : 3, name : 'Norway', population : 5.3, flagImg : 'data/Core/images/flag/nor.png' },
        { id : 4, name : 'Finland', population : 5.5, flagImg : 'data/Core/images/flag/fin.png' },
        { id : 5, name : 'Iceland', population : 0.3, flagImg : 'data/Core/images/flag/ice.png' }
    ],

    columns : [
        {
            type     : 'template',
            text     : 'Template Column',
            width    : 200,
            field    : 'name',
            align    : 'center',
            template : ({ record }) => `<div style="display: flex; flex-direction: column">
                <img alt="${record.name}'s flag" src="${record.flagImg}" height="45px" style="box-shadow : var(--b-elevation-1)"/>
                <div style="margin-top: .5em;font-weight:bold">${record.name}</div>
                </div>`
        },
        { field : 'population', type : 'number', text : 'Population', flex : 1, renderer : ({ value }) => value + 'M' }
    ]
});

Configs

81

Common

Template function used to generate a value displayed in the cell. Called with arguments { value, record, field }

ParameterTypeDescription
dataObject

An object that contains data about the cell being rendered.

data.value*

The value (only present when you set a field on the column)

data.recordModel

The record representing the row

data.fieldString

The column field name

Returns: DomConfig | String | null -

String or DomConfig object representing the HTML markup

autoWidthColumn
fieldColumn
fitModeColumn
flexColumn
listenersEvents
maxWidthColumn
textColumn
widthColumn

Accessibility

ariaLabelColumn

Export

Integration

vueColumn

Interaction

collapsedColumn
draggableColumn
editorColumn
groupableColumn
hideableColumn
resizableColumn
sealedColumn
sortableColumn

Layout

alignColumn
hiddenColumn
lockedColumn
minWidthColumn
regionColumn

Menu

Merge cells

mergeableColumn

Misc

localeClassLocalizable
localizableLocalizable
tagsColumn
treeColumn

Other

formulaColumn
pinnedColumn
readOnlyColumn

Rendering

cellClsColumn
clsColumn
iconColumn
rendererColumn
tooltipColumn

Summary

sumColumn
summariesColumn

Properties

151

Common

Template function used to generate a value displayed in the cell. Called with arguments { value, record, field }

ParameterTypeDescription
dataObject

An object that contains data about the cell being rendered.

data.value*

The value (only present when you set a field on the column)

data.recordModel

The record representing the row

data.fieldString

The column field name

Returns: DomConfig | String | null -

String or DomConfig object representing the HTML markup

autoWidthColumn
fieldColumn
fitModeColumn
flexColumn
maxWidthColumn
textColumn
widthColumn

Class hierarchy

isTemplateColumn: Boolean= truereadonly
Identifies an object as an instance of TemplateColumn class, or subclass thereof.
isTemplateColumn: Boolean= truereadonlystatic
Identifies an object as an instance of TemplateColumn class, or subclass thereof.
isColumnColumn
isEventsEvents
isLocalizableLocalizable
isModelModel
isModelLinkModelLink
isModelStmModelStm
isTreeNodeTreeNode

Accessibility

ariaLabelColumn

Editing

copyOfModel
isValidModel

Export

Fields

allFieldsstaticModel
autoExposeFieldsstaticModel
childrenFieldstaticModel
fieldMapstaticModel
fieldsstaticModel
idFieldstaticModel

Grouping

Identification

keyModel

Integration

vueColumn

Interaction

collapsedColumn
draggableColumn
editorColumn
groupableColumn
hideableColumn
resizableColumn
sealedColumn
sortableColumn

JSON

jsonModel

Layout

alignColumn
hiddenColumn
lockedColumn
minWidthColumn
regionColumn

Lifecycle

configBase

Linked records

hasLinksModelLink
isLinkedModelLink
recordLinksModelLink

Menu

Merge cells

mergeableColumn

Misc

localeHelperLocalizable
localeManagerLocalizable
stmModelStm
tagsColumn
treeColumn

Other

$namestaticModel
defaultsColumn
elementColumn
formulaColumn
gridColumn
pinnedColumn
readOnlyColumn
relationsstaticModel
subGridColumn
typestaticColumn
visibleColumn

Parent & children

allChildrenTreeNode
childLevelTreeNode
firstChildTreeNode
isLeafTreeNode
isLoadedTreeNode
isParentTreeNode
isRootTreeNode
lastChildTreeNode
nextSiblingTreeNode
parentTreeNode
parentIdTreeNode

Rendering

cellClsColumn
clsColumn
iconColumn
rendererColumn
tooltipColumn

Summary

sumColumn
summariesColumn

Functions

76

Configuration

applyDefaultsstaticBase

Editing

copyModel
getDataModel
removeModel
setModel

Events

Fields

addFieldstaticModel
getModel
processFieldstaticModel
removeFieldstaticModel

Identification

asIdstaticModel

JSON

toJSONModel

Lifecycle

destroystaticBase

Misc

equalsModel
initClassstaticBase
isOfTypeNamestaticBase
linkModelLink
mixinstaticBase
optionalLstaticLocalizable

Other

hideColumn
LstaticLocalizable
onEvents
relayAllEvents
showColumn
toggleColumn
triggerEvents
unEvents

Parent & children

appendChildTreeNode
bubbleTreeNode
bubbleWhileTreeNode
containsTreeNode
isExpandedTreeNode
removeChildTreeNode
traverseTreeNode

Events

5

Event handlers

5

Typedefs

2