@@ -13,29 +13,30 @@ Grid.js has a native Vue wrapper which can be used to create a Grid.js instance
13
13
npm install gridjs-vue
14
14
```
15
15
16
- ## Component Registration
16
+ ### Component Registration
17
17
18
- ### Global Registration
18
+ #### Local Registration
19
19
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'
23
23
24
- Vue .use (Grid)
24
+ export default {
25
+ components: {
26
+ Grid
27
+ }
28
+ }
29
+ </script >
25
30
```
26
31
27
- ### Local Registration
32
+ #### Global Registration
28
33
29
- ``` html
30
- <script >
34
+ In ` main.js ` or wherever you specify your global components:
35
+
36
+ ``` js
31
37
import Grid from ' gridjs-vue'
32
38
33
- export default {
34
- components: {
35
- Grid
36
- }
37
- }
38
- </script >
39
+ Vue .use (Grid)
39
40
```
40
41
41
42
## Usage
@@ -44,65 +45,35 @@ Pass `cols` (an array of column headers) and either `rows`, `from`, or `server`
44
45
45
46
Refer to [ Grid.js documentation] ( ./config.md ) for specific configuration options.
46
47
47
- ### Example
48
+ ### Basic Example
48
49
49
- ``` vue
50
+ ``` html
50
51
<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 >
63
53
</template >
64
54
65
55
<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
+ }
99
71
}
100
72
}
101
- }
102
73
</script >
103
74
```
104
75
105
- ### Default options
76
+ ### Default Options
106
77
107
78
``` json
108
79
{
@@ -119,3 +90,82 @@ export default {
119
90
"width" : " 100%"
120
91
}
121
92
```
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