Skip to content

Commit e039faf

Browse files
committed
Merge branch 'master' of github.com:grid-js/website
2 parents cd5f1fc + 6935bc6 commit e039faf

File tree

1 file changed

+114
-64
lines changed

1 file changed

+114
-64
lines changed

docs/integrations/vue.md

+114-64
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,30 @@ Grid.js has a native Vue wrapper which can be used to create a Grid.js instance
1313
npm install gridjs-vue
1414
```
1515

16-
## Component Registration
16+
### Component Registration
1717

18-
### Global Registration
18+
#### Local Registration
1919

20-
```js
21-
/* in `main.js` or wherever you specify your global components */
22-
import Grid from 'gridjs-vue'
20+
```html
21+
<script>
22+
import Grid from 'gridjs-vue'
2323
24-
Vue.use(Grid)
24+
export default {
25+
components: {
26+
Grid
27+
}
28+
}
29+
</script>
2530
```
2631

27-
### Local Registration
32+
#### Global Registration
2833

29-
```html
30-
<script>
34+
In `main.js` or wherever you specify your global components:
35+
36+
```js
3137
import Grid from 'gridjs-vue'
3238

33-
export default {
34-
components: {
35-
Grid
36-
}
37-
}
38-
</script>
39+
Vue.use(Grid)
3940
```
4041

4142
## Usage
@@ -44,65 +45,35 @@ Pass `cols` (an array of column headers) and either `rows`, `from`, or `server`
4445

4546
Refer to [Grid.js documentation](./config.md) for specific configuration options.
4647

47-
### Example
48+
### Basic Example
4849

49-
```vue
50+
```html
5051
<template>
51-
<grid
52-
:auto-width="autoWidth"
53-
:cols="cols"
54-
:from="from"
55-
:language="language"
56-
:pagination="pagination"
57-
:rows="rows"
58-
:search="search"
59-
:server="server"
60-
:sort="sort"
61-
:width="width"
62-
></grid>
52+
<grid :cols="cols" :rows="rows"></grid>
6353
</template>
6454

6555
<script>
66-
import Grid from 'gridjs-vue'
67-
68-
export default {
69-
name: 'MyTable',
70-
components: {
71-
Grid
72-
},
73-
data() {
74-
return {
75-
// REQUIRED:
76-
cols: ['col 1', 'col 2'], // array containing strings of column headers
77-
// AND EITHER an array containing row data
78-
rows: [
79-
['row 1 col 1', 'row 1 col 2'],
80-
['row 2 col 1', 'row 2 col 2']
81-
],
82-
// OR a string of an HTML table selector to import
83-
from: '.my-element'
84-
// OR a server settings object
85-
server() ({
86-
url: 'https://api.com/search?q=my%20query',
87-
then: res => res.data.map(col => [col1.data, col2.data, col3.data, col4.data]),
88-
handle: res => res.status === 404 ? { data: [] } : res.ok ? res.json() : new Error('Something went wrong')
89-
}),
90-
91-
// OPTIONAL:
92-
autoWidth: true / false, // boolean to automatically set table width
93-
language: {}, // localization dictionary object
94-
pagination: true / false || {}, // boolean or pagination settings object
95-
search: true / false || {}, // boolean or search settings object
96-
sort: true / false || {}, // boolean or sort settings object
97-
theme: 'mermaid', // string with name of theme or 'none' to disable
98-
width: '100%', // string with css width value
56+
import Grid from 'gridjs-vue'
57+
58+
export default {
59+
name: 'Cars',
60+
components: {
61+
Grid
62+
},
63+
data() {
64+
return {
65+
cols: ['Make', 'Model', 'Year', 'Color'],
66+
rows: [
67+
['Ford', 'Fusion', '2011', 'Silver'],
68+
['Chevrolet', 'Cruz', '2018', 'White']
69+
]
70+
}
9971
}
10072
}
101-
}
10273
</script>
10374
```
10475

105-
### Default options
76+
### Default Options
10677

10778
```json
10879
{
@@ -119,3 +90,82 @@ export default {
11990
"width": "100%"
12091
}
12192
```
93+
94+
### Extended Options
95+
96+
```html
97+
<template>
98+
<grid
99+
:auto-width="autoWidth"
100+
:cols="cols"
101+
:from="from"
102+
:language="language"
103+
:pagination="pagination"
104+
:rows="rows"
105+
:search="search"
106+
:server="server"
107+
:sort="sort"
108+
:width="width"
109+
></grid>
110+
</template>
111+
112+
<script>
113+
import Grid from 'gridjs-vue'
114+
115+
export default {
116+
name: 'MyTable',
117+
components: {
118+
Grid
119+
},
120+
data() {
121+
return {
122+
// REQUIRED:
123+
124+
// An array containing strings of column headers
125+
cols: ['col 1', 'col 2'],
126+
127+
// AND EITHER an array containing row data
128+
rows: [
129+
['row 1 col 1', 'row 1 col 2'],
130+
['row 2 col 1', 'row 2 col 2']
131+
],
132+
133+
// OR a string of an HTML table selector to import
134+
from: '.my-element'
135+
136+
// OR a server settings object
137+
server() ({
138+
url: 'https://api.com/search?q=my%20query',
139+
then: res => res.data.map(col => [col1.data, col2.data]),
140+
handle: res => res.status === 404
141+
? { data: [] } : res.ok
142+
? res.json() : new Error('Something went wrong')
143+
}),
144+
145+
// OPTIONAL:
146+
147+
// Boolean to automatically set table width
148+
autoWidth: true / false,
149+
150+
// Localization dictionary object
151+
language: {},
152+
153+
// Boolean or pagination settings object
154+
pagination: true / false || {},
155+
156+
// Boolean or search settings object
157+
search: true / false || {},
158+
159+
// Boolean or sort settings object
160+
sort: true / false || {},
161+
162+
// String with name of theme or 'none' to disable
163+
theme: 'mermaid',
164+
165+
// String with css width value
166+
width: '100%',
167+
}
168+
}
169+
}
170+
</script>
171+
```

0 commit comments

Comments
 (0)