File tree 2 files changed +68
-4
lines changed
2 files changed +68
-4
lines changed Original file line number Diff line number Diff line change
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
+ :::
Original file line number Diff line number Diff line change @@ -67,17 +67,23 @@ module.exports = {
67
67
]
68
68
} , {
69
69
type : 'category' ,
70
- label : 'Advanced ' ,
70
+ label : 'Customizing ' ,
71
71
items : [
72
- 'examples/force-render' ,
73
72
'examples/cell-formatting' ,
73
+ 'examples/row-buttons' ,
74
74
'examples/html-cells' ,
75
75
'examples/html-header-cells' ,
76
- 'examples/virtual-dom' ,
77
76
'examples/react-cells' ,
77
+ 'examples/i18n' ,
78
+ ]
79
+ } , {
80
+ type : 'category' ,
81
+ label : 'Advanced' ,
82
+ items : [
83
+ 'examples/force-render' ,
84
+ 'examples/virtual-dom' ,
78
85
'examples/multi-sort' ,
79
86
'examples/custom-sort' ,
80
- 'examples/i18n' ,
81
87
'examples/stock-market' ,
82
88
'examples/event-handler' ,
83
89
]
You can’t perform that action at this time.
0 commit comments