Skip to content

Commit 3c2c219

Browse files
committed
✨ add render function
1 parent 0c0795b commit 3c2c219

File tree

13 files changed

+258
-2580
lines changed

13 files changed

+258
-2580
lines changed

CHANGELOG.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
All notable changes to this project will be documented in this file. Dates are displayed in UTC.
44

5+
## Unreleased
6+
7+
- Incorporate ability to use Vue components as formatters
8+
59
## [0.4.1] - 2020-07-14
610

711
- Update documentation
@@ -11,12 +15,12 @@ All notable changes to this project will be documented in this file. Dates are d
1115
- Fix global import
1216
- Add createRef, h, html methods
1317

14-
## [0.3.5] - 28 June 2020
18+
## [0.3.5] - 2020-06-28
1519

1620
- :wrench: another vain attempt at getting release-it to work [`48919aa`](https://gitlab.com/selfagency/vue-gridjs/commit/48919aa36f757260ca6c15922fe2765a8b3864c5)
1721
- Release 0.3.5 [`7ca243f`](https://gitlab.com/selfagency/vue-gridjs/commit/7ca243f23db1cdb05006a873b40f4b92bc753651)
1822

19-
## 0.3.4 - 28 June 2020
23+
## 0.3.4 - 2020-06-28
2024

2125
- fix url [`#5`](https://gitlab.com/selfagency/vue-gridjs/merge_requests/5)
2226
- fix css module issue and update to latest grid.js api [`5ab77cd`](https://gitlab.com/selfagency/vue-gridjs/commit/5ab77cd6dee279618d8ef23862c85570464bc159)
@@ -26,3 +30,4 @@ All notable changes to this project will be documented in this file. Dates are d
2630
[unreleased]: https://github.com/grid-js/gridjs-vue/compare/v0.0.1...HEAD
2731
[0.4.0]: https://gitlab.com/selfagency/vue-gridjs/compare/v0.3.5...v0.4.0
2832
[0.3.5]: https://gitlab.com/selfagency/vue-gridjs/compare/v0.3.4...v0.3.5
33+
[0.3.4]: https://gitlab.com/selfagency/vue-gridjs/compare/v0.3.3...v0.3.4

README.md

Lines changed: 55 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -71,36 +71,40 @@ Refer to [Grid.js documentation](https://gridjs.io/docs/config/) for specific co
7171
</script>
7272
```
7373

74-
### Grid.js Helper Functions
74+
### Helper Functions
7575

7676
If you install the component globally, rather than importing it locally, the following helpers are added to the Vue prototype and are available globally.
7777

78-
#### `this.$gridjs.createRef`
78+
#### `this.$gridjs.uuid`
7979

80-
Returns a [reference to the Grid.js instance](https://gridjs.io/docs/examples/stock-market).
80+
Returns a unique identifier that can be used to reference the current cell.
8181

82-
Example:
82+
Usage:
8383

8484
```js
85-
const ref = this.$gridjs.createRef
85+
const ref = this.$gridjs.uuid()
8686
```
8787

8888
#### `this.$gridjs.h`
8989

9090
Renders a [Preact virtual DOM instance](https://gridjs.io/docs/examples/virtual-dom).
9191

92-
Example:
92+
Usage:
9393

9494
```js
95-
{
96-
name: 'Actions',
97-
formatter: (cell, row) => {
98-
return this.$gridjs.h('button', {
99-
className: 'py-2 mb-4 px-4 border rounded-md text-white bg-blue-600',
100-
onClick: () => alert(`Editing "${row.cells[0].data}" "${row.cells[1].data}"`)
101-
} 'Edit');
102-
}
103-
}
95+
this.cols = [
96+
{
97+
name: 'Actions',
98+
formatter: (cell, row) => {
99+
return this.$gridjs.h('button', {
100+
className: 'py-2 mb-4 px-4 border rounded-md text-white bg-blue-600',
101+
onClick: () => alert(`Editing "${row.cells[0].data}" "${row.cells[1].data}"`)
102+
} 'Edit');
103+
}
104+
},
105+
{ ... },
106+
{ ... }
107+
]
104108
```
105109

106110
#### `this.$gridjs.html`
@@ -110,10 +114,43 @@ Renders [HTML in a formatter function](https://gridjs.io/docs/examples/html-cell
110114
Example:
111115

112116
```js
113-
{
114-
name: 'Name',
117+
this.cols = [
118+
{
119+
name: 'Model',
115120
formatter: (cell) => this.$gridjs.html(`<b>${cell}</b>`)
116-
}
121+
},
122+
{ ... },
123+
{ ... }
124+
]
125+
```
126+
127+
#### `this.$gridjs.render`
128+
129+
Renders a Vue component. Refer to [Vue documentation](https://vuejs.org/v2/guide/render-function.html#createElement-Arguments) for advanced options.
130+
131+
```js
132+
this.$gridjs.render(ref, component, { props }, { options })
133+
```
134+
135+
Usage:
136+
137+
```js
138+
import FormatterComponent from './FormatterComponent.vue'
139+
140+
[...]
141+
142+
this.cols = [
143+
{
144+
name: 'Model',
145+
formatter: cell => {
146+
const current = this.$gridjs.uuid()
147+
this.$gridjs.render(`[data-ref="${current}"]`, FormatterComponent, { content: cell, otherProp: true })
148+
return this.$gridjs.html(`<div data-ref="${current}"></div>`)
149+
}
150+
},
151+
{ ... },
152+
{ ... }
153+
]
117154
```
118155

119156
### Default Options

0 commit comments

Comments
 (0)