Skip to content

Commit ade4907

Browse files
committed
2 parents dd7a859 + 43f7f3b commit ade4907

114 files changed

Lines changed: 5439 additions & 460 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

css/datagrid/datagrid.css

Lines changed: 149 additions & 113 deletions
Large diffs are not rendered by default.

docs/dashboards/grid-migration.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ Some API options have been renamed or removed. For the full list, make sure to c
2828
},
2929
columnDefaults: {
3030
cells: {
31-
editable: true,
31+
editMode: {
32+
enabled: true
33+
},
3234
events: {
3335
afterEdit: function () {
3436
// Callback action

docs/grid/cell-content.md

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
---
2+
tags: ["grid-pro"]
3+
---
4+
5+
# Cell content
6+
7+
The data type determines how the cell content is rendered.
8+
9+
Note: Customizing cell content is not part of Highcharts Grid Lite, so refer to [install instructions](https://www.highcharts.com/docs/dashboards/grid-standalone) for the full version to enable this functionality.
10+
11+
Highcharts Grid supports different cell renderers to provide interactive data presentation inside table cells. You can define the renderer property for each column in the `columns[].cells` configuration object to specify how each cell should be displayed or interacted with.
12+
13+
Renderers can be used to control how values are displayed `cells.renderer` and how they behave in [edit mode](https://www.highcharts.com/docs/grid/cell-editing) `cells.editMode.renderer`. This allows you to, for example, show plain text by default and present a checkbox or input field when a cell becomes editable.
14+
15+
## Renderers types
16+
17+
In the [renderer](https://api.highcharts.com/grid/#interfaces/Grid_Core_Options.ColumnOptions#renderer) API option, you can set the default cell renderer for view and edit modes. If not specified, it is determined by the `dataType` option.
18+
19+
Some renderers can be used specifically as cell edit mode renderers, which is recommended because they also support [validation](https://www.highcharts.com/docs/grid/cell-editing#validation) in such cases.
20+
For example, you can render a date as text in view mode, and use the `dateInput` renderer only when the cell is in edit mode.
21+
22+
| Renderer Key | Description | Edit Mode |
23+
|---|---|---|
24+
| [`checkbox`](https://api.highcharts.com/grid/#classes/Grid_Pro_CellRendering_Renderers_CheckboxRenderer.CheckboxRenderer-1) | Checkbox input element ||
25+
| [`dateInput`](https://api.highcharts.com/grid/#classes/Grid_Pro_CellRendering_Renderers_DateInputRenderer.DateInputRenderer-1) | Date input element ||
26+
| [`select`](https://api.highcharts.com/grid/#classes/Grid_Pro_CellRendering_Renderers_SelectRenderer.SelectRenderer-1) | Select element ||
27+
| [`sparkline`](https://api.highcharts.com/grid/#classes/Grid_Pro_CellRendering_Renderers_SparklineRenderer.SparklineRenderer-1) | Highcharts minified chart ||
28+
| [`text`](https://api.highcharts.com/grid/#classes/Grid_Pro_CellRendering_Renderers_TextRenderer.TextRenderer-1) | Text or custom static html content, default for most data types ||
29+
| [`textInput`](https://api.highcharts.com/grid/#classes/Grid_Pro_CellRendering_Renderers_TextInputRenderer.TextInputRenderer-1) | Text input element ||
30+
31+
### Text input
32+
Renders an editable text field for the value. It can also render static HTML elements. This is the default renderer for most cases.
33+
34+
```js
35+
{
36+
id: 'username', // column id
37+
dataType: 'string',
38+
cells: {
39+
renderer: {
40+
type: 'input'
41+
},
42+
editable: true
43+
}
44+
}
45+
```
46+
47+
### Checkbox input
48+
Renders a native checkbox input element.
49+
50+
```js
51+
{
52+
id: 'active', // column id
53+
dataType: 'boolean',
54+
cells: {
55+
renderer: {
56+
type: 'checkbox'
57+
}
58+
}
59+
}
60+
```
61+
62+
### Date input
63+
Renders a native date input that supports HTML datepicker.
64+
65+
```js
66+
{
67+
id: 'date_date', // column id
68+
dataType: 'datetime',
69+
cells: {
70+
renderer: {
71+
type: 'dateInput'
72+
}
73+
}
74+
}
75+
```
76+
77+
### Select
78+
Renders a dropdown select menu for predefined options.
79+
80+
```js
81+
{
82+
id: 'country', // column id
83+
dataType: 'string',
84+
cells: {
85+
renderer: {
86+
type: 'select',
87+
options: [
88+
{ value: 'NO', label: 'Norway' },
89+
{ value: 'NL', label: 'Netherlands' },
90+
{ value: 'PL', label: 'Poland' },
91+
{ value: 'EC', label: 'Ecuador' }
92+
]
93+
}
94+
}
95+
}
96+
```
97+
98+
### Sparkline
99+
Renders an inline miniature chart (e.g. bar, line) inside a cell using Highcharts.
100+
101+
You can configure chart by the `chartOptions` API option, that supports all Highcharts configurations.
102+
103+
```js
104+
{
105+
id: 'trend', // column id
106+
cells: {
107+
renderer: {
108+
type: 'sparkline',
109+
chartOptions: {
110+
chart: {
111+
type: 'bar'
112+
},
113+
plotOptions: {
114+
series: {
115+
dataLabels: {
116+
enabled: true
117+
},
118+
negativeColor: "#f00"
119+
}
120+
}
121+
}
122+
}
123+
}
124+
}
125+
```
126+
127+
Please note that you should include the `highcharts.js` file before including the Grid library. If you do it the other way around, or use ES Modules, you should connect Highcharts manually using: `Grid.CellRendererRegistry.types.sparkline.useHighcharts(Highcharts);`
128+
129+
Go to [Sparkline](https://www.highcharts.com/docs/grid/sparkline) to read more about Grid Sparkline structure and configuration options.
130+
131+
132+
133+
## View the Result
134+

docs/grid/cell-editing.md

Lines changed: 126 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,42 +6,147 @@ tags: ["grid-pro"]
66

77
Note: cell editing is not part of Highcharts Grid Lite, so refer to [install instructions](https://www.highcharts.com/docs/dashboards/grid-standalone) for the full version to enable this functionality.
88

9-
End users can edit data in cells if cell editing is enabled by setting the `columnDefaults.cells.editable` and/or `columns[].cells.editable` API options:
9+
End users can edit data in cells if cell edit mode is enabled by setting the `columnDefaults.cells.editMode.enabled` and/or `columns[].cells.editMode.enabled` API options:
1010

1111
```js
1212
columnDefaults: {
1313
cells: {
14-
editable: true,
15-
},
14+
editMode: {
15+
enabled: true
16+
}
17+
}
1618
},
17-
columns: [
18-
{
19+
columns: [{
1920
id: "firstName",
2021
cells: {
21-
editable: false,
22+
editMode: {
23+
enabled: false
24+
}
25+
}
26+
}]
27+
```
28+
29+
In the example above cell editing is enabled for ALL columns, expect the `firstName` column. The reverse can be achived by not setting `columnDefaults` and `columns[].cells.editMode.enabled: true` instead.
30+
31+
32+
## Validation
33+
34+
### Predefined Validation Rules
35+
36+
The following validation rules are available out of the box:
37+
- `notEmpty`
38+
- `boolean`
39+
- `number`
40+
- `datetime`
41+
42+
Each column has a specific `dataType`, which can be set explicitly by the user or inferred from the data. All data types can accept `null` values by default. Each `dataType` comes with its own set of predefined validation rules, for example, columns with the `number` type will automatically reject `NaN` values.
43+
44+
To prevent users from entering `null` or empty string values in any column, add the `notEmpty` validation rule:
45+
46+
```ts
47+
columns: [{
48+
id: 'notEmptyColumn',
49+
dataType: 'number',
50+
cells: {
51+
editMode: {
52+
validationRules: ['notEmpty']
53+
}
54+
}
55+
}]
56+
```
57+
58+
### Custom Validation Rules
59+
60+
You can define custom validation rules and error messages directly in the column options:
61+
62+
```ts
63+
columns: [{
64+
id: 'emails',
65+
dataType: 'string',
66+
cells: {
67+
editMode: {
68+
validationRules: ['notEmpty', {
69+
validator: function({ value }) {
70+
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value);
71+
},
72+
notification: 'Value must be a valid email address.'
73+
}]
74+
}
75+
}
76+
}]
77+
```
78+
79+
Note that a validator is a callback function that receives an object as its first argument. This object represents the cell content and contains two important properties: `value` and `rawValue`.
80+
81+
- `value`: Returns the parsed value according to the specified `dataType`.
82+
- `rawValue`: Always returns the original string entered by the user in the input field, regardless of the column's `dataType`.
83+
84+
This distinction allows you to implement validation logic based on either the parsed value or the raw user input, depending on your requirements. For example, you might want to validate the format of the input string (`rawValue`) before parsing, or check the parsed value (`value`) for business logic constraints.
85+
86+
### Registering Custom Validators
87+
88+
You can also register custom validators globally in the `Validator.rulesRegistry` and then reference them by name in your columns:
89+
90+
```ts
91+
Validator.rulesRegistry['email'] = {
92+
validator: function({ value }) {
93+
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value);
2294
},
23-
},
24-
],
95+
notification: 'Value must be a valid email address.'
96+
};
97+
98+
columns: [{
99+
id: 'emails',
100+
dataType: 'string',
101+
cells: {
102+
editMode: {
103+
validationRules: ['notEmpty', 'email']
104+
}
105+
}
106+
}]
107+
```
108+
109+
This approach allows you to reuse custom validation logic across multiple columns.
110+
111+
112+
## Edit Mode Renderers
113+
114+
Edit mode renderers define how the cell input is displayed and interacted with when editing is enabled. You can use built-in renderers such as text fields, select dropdowns, or implement custom renderers to match your application's requirements. This allows for flexible editing experiences tailored to different data types and use cases.
115+
116+
You can read more about cell renderers in [this article](https://www.highcharts.com/docs/grid/cell-content).
117+
118+
```ts
119+
columns: [{
120+
id: "role",
121+
cells: {
122+
editMode: {
123+
enabled: true,
124+
renderer: {
125+
type: 'select',
126+
options: [
127+
{ value: 'admin', label: 'Administrator' },
128+
{ value: 'editor', label: 'Editor' },
129+
{ value: 'viewer', label: 'Viewer' }
130+
]
131+
}
132+
}
133+
}
134+
}]
25135
```
26136

27-
In the example above cell editing is enabled for ALL columns, expect the `firstName` column. The reverse can be achived by not setting `columnDefaults` and `columns[].cells.editable: true` instead.
28137

29138
## The afterEdit event
30139

31-
The `afterEdit` event is called after a cell value is edited, and can be used to e.g. post result to server, generate feedback GUI etc:
140+
The `afterEdit` event is called after a cell value is edited using the edit mode, and can be used to e.g. post result to server, generate feedback GUI etc:
32141

33142
```js
34143
columnDefaults: {
35-
cells: {
36-
events: {
37-
afterEdit: function () {
38-
console.log(`${this.column.id} for ${this.row.data.firstName} was updated to ${this.value}`);
39-
}
40-
}
41-
},
144+
cells: {
145+
events: {
146+
afterEdit: function () {
147+
console.log(`${this.column.id} for ${this.row.data.firstName} was updated to ${this.value}`);
148+
}
149+
}
150+
},
42151
}
43152
```
44-
45-
## Cell editing roadmap
46-
47-
Cell editing is currently in development, and API support for input validation and different input mechanisms (string, number, boolean etc.) will be released in Q3 2025.

docs/grid/columns.md

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,22 +58,22 @@ You can exclude the column, including its header, from the Grid by setting `enab
5858

5959
```js
6060
{
61-
columns: [
62-
{
63-
id: "price",
64-
cells: {
65-
className: "custom_cell_class",
66-
format: "${value}",
67-
editable: true
61+
columns: [{
62+
id: "price",
63+
cells: {
64+
className: "custom_cell_class",
65+
format: "${value}",
66+
editMode: {
67+
enabled: true
6868
}
6969
}
70-
]
70+
}]
7171
}
7272
```
7373

7474
The `columns[].cells` option can configure the cells in individual columns. If needed, you can set defaults for all columns in `columnDefaults.cells`.
7575

76-
The end user can edit each cell in a column directly by setting the `editable` option to true. Read more in the [Cell editing](https://www.highcharts.com/docs/grid/cell-editing) article.
76+
The end user can edit each cell in a column directly by setting the `editMode.enabled` option to true. Read more in the [Cell editing](https://www.highcharts.com/docs/grid/cell-editing) article.
7777

7878
Note that `className` and `format` support templating as described in [Templating](https://www.highcharts.com/docs/chart-concepts/templating), and `{value}` references the cell value.
7979

@@ -242,3 +242,15 @@ columns: [
242242
}
243243
...
244244
]
245+
```
246+
247+
## Data type
248+
249+
The [dataType](https://api.highcharts.com/dashboards/#interfaces/Grid_Options.ColumnOptions#dataType) specifies the type of the column (`string`, `number`, `boolean` or `date`).
250+
The data type determines how the cell content is rendered. For example, setting the type to boolean displays a check or cross symbol based on the value.
251+
252+
If this property is not defined, the data type is automatically inferred from the first cell in the column.
253+
254+
<iframe src="https://www.highcharts.com/samples/embed/grid/basic/column-data-type" allow="fullscreen"></iframe>
255+
256+
For more details on customizing cell content, refer to the [cell content section](https://www.highcharts.com/docs/grid/cell-content).

0 commit comments

Comments
 (0)