Skip to content

Commit 089146a

Browse files
committed
Fix global import, add createRef, h, html methods
Signed-off-by: Daniel Sieradski <[email protected]>
1 parent 7ca243f commit 089146a

13 files changed

+984
-1052
lines changed

release-it.json renamed to .release-it.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"git": {
3-
"commitMessage": "?? Release v${version}",
3+
"commitMessage": "Release v${version}",
44
"requireBranch": "master",
55
"requireCleanWorkingDir": false
66
},

README.md

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
A Vue wrapper component for [Grid.js](https://gridjs.io).
66

7+
[![npm](https://img.shields.io/npm/v/gridjs-vue?color=41B883&label=current&style=flat-square)](https://www.npmjs.com/package/gridjs-vue) [![Grid.js API version](https://img.shields.io/github/package-json/dependency-version/grid-js/gridjs-vue/gridjs?color=41B883&label=grid.js%20api&style=flat-square)](https://gridjs.io/docs/index) [![David](https://img.shields.io/david/grid-js/gridjs-vue?color=41B883&style=flat-square)](https://david-dm.org/grid-js/gridjs-vue) ![GitHub last commit](https://img.shields.io/github/last-commit/grid-js/gridjs-vue?color=41B883&style=flat-square) [![GitHub issues](https://img.shields.io/github/issues/grid-js/gridjs-vue?color=41B883&style=flat-square)](https://github.com/grid-js/gridjs-vue/issues) [![Discord](https://img.shields.io/discord/711188165850955858?color=41B883&style=flat-square&label=discord)](https://discord.com/invite/K55BwDY)
8+
79
## Install
810

911
```sh
@@ -30,16 +32,16 @@ npm install gridjs-vue
3032

3133
```js
3234
/* in `main.js` or wherever you specify your global components */
33-
import Grid from 'gridjs-vue'
35+
import { GridGlobal } from 'gridjs-vue'
3436

35-
Vue.use(Grid)
37+
Vue.use(GridGlobal)
3638
```
3739

3840
## Usage
3941

40-
Pass `cols` (an array of column headers) and either `rows`, `from`, or `server` as a data source to the component. Everything else is optional.
42+
Pass `cols` (an array of column headers) and either `rows`, `from`, or `server` as a data source to the component. Everything else is optional. Pass in new data to update the table.
4143

42-
Refer to [Grid.js documentation](https://gridjs.io/docs/config/) for specific configuration options.
44+
Refer to [Grid.js documentation](https://gridjs.io/docs/config/) for specific configuration options. This module may lag behind the main Grid.js module somewhat, so check the API version badge at the top of this README.
4345

4446
### Basic Example
4547

@@ -69,6 +71,45 @@ Refer to [Grid.js documentation](https://gridjs.io/docs/config/) for specific co
6971
</script>
7072
```
7173

74+
### Grid.js Helper Functions
75+
76+
If you install the component as a plugin, rather than importing it directly into your component, the following helpers are added to the Vue prototype and are available globally.
77+
78+
#### `this.$gridjs.createRef`
79+
80+
Returns a [reference to the Grid.js instance](https://gridjs.io/docs/examples/stock-market).
81+
82+
```js
83+
const ref = this.$gridjs.createRef
84+
```
85+
86+
#### `this.$gridjs.h`
87+
88+
Renders a [Preact virtual DOM instance](https://gridjs.io/docs/examples/virtual-dom).
89+
90+
```js
91+
{
92+
name: 'Actions',
93+
formatter: (cell, row) => {
94+
return this.$gridjs.h('button', {
95+
className: 'py-2 mb-4 px-4 border rounded-md text-white bg-blue-600',
96+
onClick: () => alert(`Editing "${row.cells[0].data}" "${row.cells[1].data}"`)
97+
} 'Edit');
98+
}
99+
}
100+
```
101+
102+
#### `this.$gridjs.html`
103+
104+
Renders [HTML in a formatter function](https://gridjs.io/docs/examples/html-cells).
105+
106+
```js
107+
{
108+
name: 'Name',
109+
formatter: (cell) => this.$gridjs.html(`<b>${cell}</b>`)
110+
}
111+
```
112+
72113
### Default Options
73114

74115
```json
@@ -132,9 +173,10 @@ Refer to [Grid.js documentation](https://gridjs.io/docs/config/) for specific co
132173
},
133174
{
134175
name: 'Column 2',
135-
id: 'col2'
176+
id: 'col2',
177+
formatter: (cell) => this.$gridjs.html(`<b>${cell}</b>`)
136178
}
137-
]
179+
],
138180
139181
// AND EITHER an array containing row data (`data` in the Grid.js API)
140182
rows: [
@@ -146,15 +188,15 @@ Refer to [Grid.js documentation](https://gridjs.io/docs/config/) for specific co
146188
rows: [
147189
{ col1: 'row 1', col2: 'row 1' },
148190
{ col1: 'row 2', col2: 'row 2' }
149-
]
191+
],
150192
151193
// OR a function returning an array of row data
152194
rows() {
153195
return [
154196
{ col1: 3 + 4, col2: 5 + 6 },
155197
{ col1: 1 * 2, col2: 7 * 8 }
156198
]
157-
}
199+
},
158200
159201
// OR a string of an HTML table selector to import
160202
from: '.my-element',
@@ -167,7 +209,7 @@ Refer to [Grid.js documentation](https://gridjs.io/docs/config/) for specific co
167209
<tr><td>${1 * 2}</td></tr>
168210
</table>
169211
`
170-
}
212+
},
171213
172214
// OR a server settings function or object
173215
server() ({

dist/index.esm.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)