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` }
]
});
//<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
Configs
81Common
Template function used to generate a value displayed in the cell. Called with arguments { value, record, field }
| Parameter | Type | Description |
|---|---|---|
data | Object | An object that contains data about the cell being rendered. |
data.value | * | The value (only present when you set a |
data.record | Model | The record representing the row |
data.field | String | The column field name |
String or DomConfig object representing the HTML markup
Integration
Interaction
Menu
Misc
Rendering
Properties
151
Properties
151Common
Template function used to generate a value displayed in the cell. Called with arguments { value, record, field }
| Parameter | Type | Description |
|---|---|---|
data | Object | An object that contains data about the cell being rendered. |
data.value | * | The value (only present when you set a |
data.record | Model | The record representing the row |
data.field | String | The column field name |
String or DomConfig object representing the HTML markup