Skip to content

Commit ac5e981

Browse files
committed
feat: row buttons
1 parent c68b327 commit ac5e981

File tree

2 files changed

+68
-4
lines changed

2 files changed

+68
-4
lines changed

docs/examples/row-buttons.md

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
---
2+
id: row-buttons
3+
title: Row buttons
4+
keywords:
5+
- javascript
6+
- table
7+
- javascript table
8+
- gridjs
9+
- grid js
10+
- action buttons
11+
---
12+
13+
import { LiveExample } from "../../lib/liveExample.js";
14+
15+
You can get access to the cell or the entire row using the `formatter` function. In this example, we are adding a button
16+
to each row which has an `onClick` handler function that can read the entire row.
17+
18+
Import the `h` function first:
19+
20+
```js
21+
import { Grid, h } from "gridjs";
22+
```
23+
24+
Then you can use that in `formatter` function or directly in `data` array:
25+
26+
<LiveExample children={
27+
`
28+
const grid = new Grid({
29+
columns: [
30+
{
31+
name: 'Name',
32+
},
33+
'Email',
34+
{
35+
name: 'Actions',
36+
formatter: (cell, row) => {
37+
return h('button', {
38+
className: 'py-2 mb-4 px-4 border rounded-md text-white bg-blue-600',
39+
onClick: () => alert(\`Editing "\${row.cells[0].data}\" "\${row.cells[1].data}"\`)
40+
}, 'Edit');
41+
}
42+
},
43+
],
44+
data: Array(5).fill().map(x => [
45+
faker.name.findName(),
46+
faker.internet.email(),
47+
null
48+
])
49+
});
50+
`
51+
} />
52+
53+
<br/>
54+
55+
:::tip
56+
It is also possible to bind callback functions to `cellClick` or `rowClick` events.
57+
See [Events](./event-handler.md) for more details.
58+
:::

sidebars.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,23 @@ module.exports = {
6767
]
6868
}, {
6969
type: 'category',
70-
label: 'Advanced',
70+
label: 'Customizing',
7171
items: [
72-
'examples/force-render',
7372
'examples/cell-formatting',
73+
'examples/row-buttons',
7474
'examples/html-cells',
7575
'examples/html-header-cells',
76-
'examples/virtual-dom',
7776
'examples/react-cells',
77+
'examples/i18n',
78+
]
79+
}, {
80+
type: 'category',
81+
label: 'Advanced',
82+
items: [
83+
'examples/force-render',
84+
'examples/virtual-dom',
7885
'examples/multi-sort',
7986
'examples/custom-sort',
80-
'examples/i18n',
8187
'examples/stock-market',
8288
'examples/event-handler',
8389
]

0 commit comments

Comments
 (0)