Skip to content

Commit 77d97ee

Browse files
authored
To the moon and back: Breaking changes! (#368)
1 parent abdaa15 commit 77d97ee

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+2464
-484
lines changed

.eslintrc.js

+2-7
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,11 @@ module.exports = {
44
browser: true,
55
node: true
66
},
7-
extends: [
8-
'plugin:vue/essential',
9-
'eslint:recommended',
10-
'@vue/prettier',
11-
'plugin:import/errors',
12-
'plugin:import/warnings'
13-
],
7+
extends: ['plugin:vue/recommended', 'eslint:recommended', 'plugin:import/errors', 'plugin:import/warnings'],
148
parserOptions: {
159
parser: 'babel-eslint'
1610
},
11+
plugins: ['html'],
1712
rules: {
1813
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
1914
'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

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

5+
## [Unreleased]
6+
57
## [5.0.1] - 2021-06-08
68

79
- Major update!

README.md

+17-257
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,21 @@
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) ![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)
7+
[![npm](https://img.shields.io/npm/v/gridjs-vue?color=blue&label=current&style=flat-square)](https://www.npmjs.com/package/gridjs-vue)
8+
![Grid.js API
9+
version](https://img.shields.io/badge/Grid.js%20API-v5.0.1-blue?style=flat-square)
10+
![GitHub last commit](https://img.shields.io/github/last-commit/grid-js/gridjs-vue?color=41B883&style=flat-square)
11+
[![GitHub
12+
issues](https://img.shields.io/github/issues/grid-js/gridjs-vue?color=41B883&style=flat-square)](https://github.com/grid-js/gridjs-vue/issues)
13+
[![Discord](https://img.shields.io/discord/711188165850955858?color=41B883&style=flat-square&label=discord)](https://discord.com/invite/K55BwDY)
814

915
## Install
1016

1117
```sh
1218
npm install gridjs-vue
1319
```
1420

15-
### Component Registration
16-
17-
#### Local Registration
21+
Also available on [unpkg](https://unpkg.com/browse/[email protected]/dist/) and [Skypack](https://www.skypack.dev/view/gridjs-vue)!
1822

1923
```html
2024
<script>
@@ -28,26 +32,17 @@ npm install gridjs-vue
2832
</script>
2933
```
3034

31-
#### Global Registration
32-
33-
```js
34-
/* in `main.js` or wherever you specify your global components */
35-
import { GridGlobal } from 'gridjs-vue'
36-
37-
Vue.use(GridGlobal)
38-
```
39-
40-
## Usage
35+
## Basic Usage
4136

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.
37+
Pass `columns` (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.
4338

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.
39+
**[Read the full documentation](docs/index.md) for further configuration options.**
4540

46-
### Basic Example
41+
### Example
4742

4843
```html
4944
<template>
50-
<grid :cols="cols" :rows="rows"></grid>
45+
<grid :columns="columns" :rows="rows" @ready="myMethod"></grid>
5146
</template>
5247

5348
<script>
@@ -60,257 +55,22 @@ Refer to [Grid.js documentation](https://gridjs.io/docs/config/) for specific co
6055
},
6156
data() {
6257
return {
63-
cols: ['Make', 'Model', 'Year', 'Color'],
58+
columns: ['Make', 'Model', 'Year', 'Color'],
6459
rows: [
6560
['Ford', 'Fusion', '2011', 'Silver'],
6661
['Chevrolet', 'Cruz', '2018', 'White']
6762
]
6863
}
69-
}
70-
}
71-
</script>
72-
```
73-
74-
### Default Options
75-
76-
```json
77-
{
78-
"autoWidth": true,
79-
"classNames": undefined,
80-
"cols": [""],
81-
"from": undefined,
82-
"language": undefined,
83-
"pagination": false,
84-
"rows": undefined,
85-
"search": false,
86-
"server": undefined,
87-
"sort": false,
88-
"styles": undefined,
89-
"theme": "mermaid",
90-
"width": "100%"
91-
}
92-
```
93-
94-
### Extended Options
95-
96-
```html
97-
<template>
98-
<grid
99-
:auto-width="autoWidth"
100-
:class-names="classNames"
101-
:cols="cols"
102-
:from="from"
103-
:language="language"
104-
:pagination="pagination"
105-
:rows="rows"
106-
:search="search"
107-
:server="server"
108-
:sort="sort"
109-
:styles="styles"
110-
:width="width"
111-
></grid>
112-
</template>
113-
114-
<script>
115-
import Grid from 'gridjs-vue'
116-
117-
export default {
118-
name: 'MyTable',
119-
components: {
120-
Grid
12164
},
122-
data() {
123-
return {
124-
// REQUIRED:
125-
126-
// An array containing strings of column headers
127-
// `columns` in the Grid.js API
128-
cols: ['col 1', 'col 2'],
129-
130-
// OR an array containing objects defining column headers
131-
cols: [
132-
{
133-
name: 'Column 1',
134-
id: 'col1'
135-
},
136-
{
137-
name: 'Column 2',
138-
id: 'col2',
139-
formatter: (cell) => this.$gridjs.html(`<b>${cell}</b>`)
140-
}
141-
],
142-
143-
// AND EITHER an array containing row data
144-
// `data` in the Grid.js API
145-
rows: [
146-
['row 1 col 1', 'row 1 col 2'],
147-
['row 2 col 1', 'row 2 col 2']
148-
],
149-
150-
// OR an array containing JSON row data
151-
rows: [
152-
{ col1: 'row 1', col2: 'row 1' },
153-
{ col1: 'row 2', col2: 'row 2' }
154-
],
155-
156-
// OR a function returning an array of row data
157-
rows() {
158-
return [
159-
{ col1: 3 + 4, col2: 5 + 6 },
160-
{ col1: 1 * 2, col2: 7 * 8 }
161-
]
162-
},
163-
164-
// OR a string of an HTML table selector to import
165-
from: '.my-element',
166-
167-
// OR a function returning an HTML table string
168-
from() {
169-
return `
170-
<table>
171-
<tr><th>column 1</th></tr>
172-
<tr><td>${1 * 2}</td></tr>
173-
</table>
174-
`
175-
},
176-
177-
// OR a server settings function or object
178-
server() ({
179-
url: 'https://api.com/search?q=my%20query',
180-
then: res => res.data.map(col => [col1.data, col2.data]),
181-
handle: res => res.status === 404
182-
? { data: [] } : res.ok
183-
? res.json() : new Error('Something went wrong')
184-
}),
185-
186-
// OPTIONAL:
187-
188-
// Boolean to automatically set table width
189-
autoWidth: true / false,
190-
191-
// Object with CSS class names
192-
// `className` in the Grid.js API
193-
classNames: {},
194-
195-
// Localization dictionary object
196-
language: {},
197-
198-
// Boolean or pagination settings object
199-
pagination: true / false || {},
200-
201-
// Boolean
202-
search: true / false || {},
203-
204-
// Boolean or sort settings object
205-
sort: true / false || {},
206-
207-
// Object with CSS styles
208-
// `style` in the Grid.js API
209-
styles: {},
210-
211-
// String with name of theme or 'none' to disable
212-
theme: 'mermaid',
213-
214-
// String with css width value
215-
width: '100%',
65+
methods: {
66+
myMethod() {
67+
console.log("It's ready!")
21668
}
21769
}
21870
}
21971
</script>
22072
```
22173

222-
### Helper Functions
223-
224-
If you install the component globally, rather than importing it locally, the following helpers are added to the Vue prototype and are available globally.
225-
226-
#### \$gridjs.uuid
227-
228-
Returns a unique identifier that can be used to reference the current cell.
229-
230-
Usage:
231-
232-
```js
233-
const ref = this.$gridjs.uuid()
234-
```
235-
236-
#### \$gridjs.h
237-
238-
Renders a [Preact virtual DOM instance](https://gridjs.io/docs/examples/virtual-dom). Grid.js is built in Preact, so why not take advantage of it?
239-
240-
Usage:
241-
242-
```js
243-
this.cols = [
244-
{
245-
name: 'Actions',
246-
formatter: (cell, row) => {
247-
return this.$gridjs.h('button', {
248-
onClick: () => alert(`
249-
Editing "${row.cells[0].data}"
250-
`)
251-
}, 'Edit')
252-
}
253-
},
254-
{ ... },
255-
{ ... }
256-
]
257-
```
258-
259-
#### \$gridjs.html
260-
261-
Renders [HTML in a formatter function](https://gridjs.io/docs/examples/html-cells).
262-
263-
Example:
264-
265-
```js
266-
this.cols = [
267-
{
268-
name: 'Model',
269-
formatter: cell => this.$gridjs.html(`<b>${cell}</b>`)
270-
},
271-
{ ... },
272-
{ ... }
273-
]
274-
```
275-
276-
#### \$gridjs.render
277-
278-
Renders a Vue component. Refer to [Vue documentation](https://vuejs.org/v2/guide/render-function.html#createElement-Arguments) for advanced options.
279-
280-
Usage:
281-
282-
```js
283-
this.$gridjs.render(ref, component, { props }, { options })
284-
```
285-
286-
Example:
287-
288-
```js
289-
import FormatterComponent from './FormatterComponent.vue'
290-
291-
[...]
292-
293-
this.cols = [
294-
{
295-
name: 'Model',
296-
formatter: cell => {
297-
const current = this.$gridjs.uuid()
298-
this.$gridjs.render(
299-
`[data-ref="${current}"]`,
300-
FormatterComponent,
301-
{
302-
content: cell,
303-
otherProp: true
304-
}
305-
)
306-
return this.$gridjs.html(`<div data-ref="${current}"></div>`)
307-
}
308-
},
309-
{ ... },
310-
{ ... }
311-
]
312-
```
313-
31474
## 🤝 Contributing
31575

31676
Originally authored by [Daniel Sieradski](https://twitter.com/self_agency).

attributes.json

+10-2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@
55
},
66
"gridjs-vue/classNames": {
77
"type": "object",
8-
"description": "Object containing CSS class names. Default: undefined"
8+
"description": "Object containing CSS class definitions. Default: undefined"
99
},
10-
"gridjs-vue/cols": {
10+
"gridjs-vue/columns": {
1111
"type": "array",
1212
"description": "Array containing strings of column headers. Default: undefined"
1313
},
14+
"gridjs-vue/fixedHeader": {
15+
"type": "boolean",
16+
"description": "Boolean to fix position of table header. Default: false"
17+
},
1418
"gridjs-vue/from": {
1519
"type": ["string", "function"],
1620
"description": "String of HTML table selector or function returning HTML table string. Default: undefined"
@@ -27,6 +31,10 @@
2731
"type": ["boolean", "object"],
2832
"description": "Boolean or pagination settings object. Default: true"
2933
},
34+
"gridjs-vue/resizable": {
35+
"type": "boolean",
36+
"description": "Boolean activating resizable columns. Default: false"
37+
},
3038
"gridjs-vue/rows": {
3139
"type": ["array", "function"],
3240
"description": "Array containing or function returning row data. Default: undefined"

0 commit comments

Comments
 (0)