Skip to content

Commit 1e46b5c

Browse files
authored
More documentation updates (#371)
1 parent 77d97ee commit 1e46b5c

File tree

6 files changed

+175
-5
lines changed

6 files changed

+175
-5
lines changed

CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ All notable changes to this project will be documented in this file. Dates are d
44

55
## [Unreleased]
66

7+
- All new documentation af3db2b
8+
- Update README.md 40da820
9+
- update devdeps 17626e7
10+
- Rework new helper function f2cf99b
11+
- Add ready event f88802d
12+
- To the moon and back a5d40d7
13+
- Update table on window resize ea93940
14+
- Change attribute names to match GridJS API 995c66b
15+
- Update attributes.json abdaa15
16+
717
## [5.0.1] - 2021-06-08
818

919
- Major update!

docs/examples.md

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ functionality in Vue using this component. These examples mirror those found in
6969
- [Stock Market](../examples/advanced/stock-market.mjs)
7070
- [Events](../examples/advanced/events.mjs)
7171
- [Vue Events](../examples/advanced/vue-events.mjs)
72+
- [Global Event Bus](../examples/advanced/global-event-bus.mjs)
7273

7374
[Preview](../examples/advanced.html)
7475

docs/using_with_components.md

+83-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Using with Vue components
22

3-
`gridjs-vue` comes with a [helper method](helpers.md), `$gridjs.helper()`, with which you can insert a Vue component directly into a
4-
table cell or row.
3+
`gridjs-vue` comes with a [helper method](helpers.md), `$gridjs.helper()`, with which you can insert a Vue component
4+
directly into a table cell or row.
55

66
```html
77
<template>
@@ -48,7 +48,7 @@ table cell or row.
4848
## Handling child component events
4949

5050
If the Vue component you are inserting into the Grid.js instance has events that bubble up, you can handle them by
51-
passing a `methods` object to `$gridjs.helper()` containing your event handler.
51+
passing `methods` to `$gridjs.helper()` containing your event handler, just as you would normally.
5252

5353
```html
5454
<template>
@@ -98,4 +98,84 @@ passing a `methods` object to `$gridjs.helper()` containing your event handler.
9898
</script>
9999
```
100100

101+
## Using A Global Event Bus
102+
103+
Because it is instantiating within a Preact component, each Vue component becomes its own Vue instance and therefore cannot
104+
communicate back with the main Vue application unless using a separate global event bus, as shown in the following implementation.
105+
106+
```js
107+
import Emittery from 'https://cdn.skypack.dev/emittery'
108+
import faker from 'https://cdn.skypack.dev/faker'
109+
import { Grid } from '../../dist/index.esm.js'
110+
111+
window.emitter = new Emittery()
112+
113+
const TestComponent = {
114+
name: 'TestComponent',
115+
props: {
116+
content: {
117+
type: String,
118+
default: 'Hello, world!'
119+
},
120+
emitter: {
121+
type: Object,
122+
default: null
123+
}
124+
},
125+
data() {
126+
return {
127+
styling: 'color: #f00;'
128+
}
129+
},
130+
methods: {
131+
emit(args) {
132+
return window.emitter.emit(args)
133+
}
134+
},
135+
template: `
136+
<div>
137+
<div :style="styling" v-html="content" @click="emit('sayHello')"></div>
138+
</div>
139+
`
140+
}
141+
142+
export default {
143+
name: 'SharedEventBus',
144+
components: {
145+
Grid
146+
},
147+
data() {
148+
return {
149+
emitter: window.emitter,
150+
columns: [
151+
{
152+
name: 'Name',
153+
formatter: cell => {
154+
return this.$gridjs.helper({
155+
components: { TestComponent },
156+
template: `<test-component :content="content"></test-component>`,
157+
data() {
158+
return {
159+
content: `🥳 ${cell}`
160+
}
161+
}
162+
})
163+
}
164+
},
165+
'Email'
166+
],
167+
rows: Array(5)
168+
.fill()
169+
.map(() => [faker.name.findName(), faker.internet.email()])
170+
}
171+
},
172+
mounted() {
173+
this.emitter.on('sayHello', () => console.log('hello'))
174+
},
175+
template: `
176+
<div><grid :columns="columns" :rows="rows"></grid></div>
177+
`
178+
}
179+
```
180+
101181
[< Back to contents](index.md)

examples/advanced.html

+8-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import StockMarket from './advanced/stock-market.mjs'
1717
import Events from './advanced/events.mjs'
1818
import VueEvents from './advanced/vue-events.mjs'
19+
import GlobalEventBus from './advanced/global-event-bus.mjs'
1920

2021
new window.Vue({
2122
el: '#app',
@@ -28,7 +29,8 @@
2829
CustomSort,
2930
StockMarket,
3031
Events,
31-
VueEvents
32+
VueEvents,
33+
GlobalEventBus
3234
},
3335
template: `
3436
<div>
@@ -72,6 +74,11 @@ <h2>Events</h2>
7274
<h2>Vue Events</h2>
7375
<vue-events></vue-events>
7476
</div>
77+
78+
<div>
79+
<h2>Global Event Bus</h2>
80+
<global-event-bus></global-event-bus>
81+
</div>
7582
</div>
7683
`
7784
})
+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import Emittery from 'https://cdn.skypack.dev/emittery'
2+
import faker from 'https://cdn.skypack.dev/faker'
3+
import { Grid } from '../../dist/index.esm.js'
4+
5+
window.emitter = new Emittery()
6+
7+
const TestComponent = {
8+
name: 'TestComponent',
9+
props: {
10+
content: {
11+
type: String,
12+
default: 'Hello, world!'
13+
},
14+
emitter: {
15+
type: Object,
16+
default: null
17+
}
18+
},
19+
data() {
20+
return {
21+
styling: 'color: #f00;'
22+
}
23+
},
24+
methods: {
25+
emit(args) {
26+
return window.emitter.emit(args)
27+
}
28+
},
29+
template: `
30+
<div>
31+
<div :style="styling" v-html="content" @click="emit('sayHello')"></div>
32+
</div>
33+
`
34+
}
35+
36+
export default {
37+
name: 'SharedEventBus',
38+
components: {
39+
Grid
40+
},
41+
data() {
42+
return {
43+
emitter: window.emitter,
44+
columns: [
45+
{
46+
name: 'Name',
47+
formatter: cell => {
48+
return this.$gridjs.helper({
49+
components: { TestComponent },
50+
template: `<test-component :content="content"></test-component>`,
51+
data() {
52+
return {
53+
content: `🥳 ${cell}`
54+
}
55+
}
56+
})
57+
}
58+
},
59+
'Email'
60+
],
61+
rows: Array(5)
62+
.fill()
63+
.map(() => [faker.name.findName(), faker.internet.email()])
64+
}
65+
},
66+
mounted() {
67+
this.emitter.on('sayHello', () => console.log('hello'))
68+
},
69+
template: `
70+
<div><grid :columns="columns" :rows="rows"></grid></div>
71+
`
72+
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "gridjs-vue",
33
"description": "A Vue.js wrapper component for Grid.js",
4-
"version": "5.0.1",
4+
"version": "5.0.2-0",
55
"license": "MIT",
66
"private": false,
77
"authors": [

0 commit comments

Comments
 (0)