1
1
# gridjs-vue
2
2
3
- ![ gridjs-vue ] ( https://user-images.githubusercontent.com/2541728/84843482-ffc31c00-b015-11ea-95e8-dc6fb3931ad5.png )
3
+ < center >< img src = " https://user-images.githubusercontent.com/2541728/84843482-ffc31c00-b015-11ea-95e8-dc6fb3931ad5.png " alt = " gridjs-vue logo " /></ center >
4
4
5
- A [ Vue.js] ( https://vuejs.org ) wrapper component for [ Grid.js] ( https://grid.io )
6
-
7
- ### 🏠 [ Homepage] ( https://gridjs.io )
5
+ A Vue wrapper component for [ Grid.js] ( https://gridjs.io ) .
8
6
9
7
## Install
10
8
11
9
``` sh
12
- yarn install gridjs-vue || npm install gridjs-vue
10
+ npm install gridjs-vue
13
11
```
14
12
15
- ## Component Registration
13
+ ### Component Registration
16
14
17
- ### Global Registration
15
+ #### Local Registration
18
16
19
- ``` js
20
- /* in `main.js` or wherever you specify your global components */
21
- import Grid from ' gridjs-vue'
17
+ ``` html
18
+ < script >
19
+ import Grid from ' gridjs-vue'
22
20
23
- Vue .use (Grid)
21
+ export default {
22
+ components: {
23
+ Grid
24
+ }
25
+ }
26
+ </script >
24
27
```
25
28
26
- ### Local Registration
29
+ #### Global Registration
27
30
28
- ``` vue
29
- <script>
31
+ ``` js
32
+ /* in `main.js` or wherever you specify your global components */
30
33
import Grid from ' gridjs-vue'
31
34
32
- export default {
33
- components: {
34
- Grid
35
- }
36
- }
37
- </script>
35
+ Vue .use (Grid)
38
36
```
39
37
40
38
## Usage
41
39
42
- Pass ` cols ` and either ` rows ` , ` from ` , or ` server ` as a data source. Everything else is optional.
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.
43
41
44
42
Refer to [ Grid.js documentation] ( https://gridjs.io/docs/config/ ) for specific configuration options.
45
43
46
- ``` vue
44
+ ### Basic Example
45
+
46
+ ``` html
47
47
<template >
48
- <grid
49
- :auto-width="autoWidth"
50
- :cols="cols"
51
- :from="from"
52
- :language="language"
53
- :pagination="pagination"
54
- :rows="rows"
55
- :search="search"
56
- :server="server"
57
- :sort="sort"
58
- :width="width"
59
- ></grid>
48
+ <grid :cols =" cols" :rows =" rows" ></grid >
60
49
</template >
61
50
62
51
<script >
63
- import Grid from 'gridjs-vue'
64
-
65
- export default {
66
- name: 'MyTable',
67
- components: {
68
- Grid
69
- },
70
- data() {
71
- return {
72
- autoWidth: true / false, // boolean to automatically set table width
73
- cols: ['column 1', 'column 2'], // array containing strings of column headers
74
- from: '.my-element', // string of HTML table selector
75
- language: {}, // localization dictionary object
76
- pagination: true / false || {}, // boolean or pagination settings object
77
- rows: ['row 1: col 1', 'row 1: col 2'] // array containing row data
78
- search: true / false || {}, // boolean or search settings object
79
- server: {}, // server settings object
80
- sort: true / false || {}, // boolean or sort settings object
81
- theme: 'mermaid', // string with name of theme or 'none' to disable
82
- width: '100%' // string with css width value
52
+ import Grid from ' gridjs-vue'
53
+
54
+ export default {
55
+ name: ' Cars' ,
56
+ components: {
57
+ Grid
58
+ },
59
+ data () {
60
+ return {
61
+ cols: [' Make' , ' Model' , ' Year' , ' Color' ],
62
+ rows: [
63
+ [' Ford' , ' Fusion' , ' 2011' , ' Silver' ],
64
+ [' Chevrolet' , ' Cruz' , ' 2018' , ' White' ]
65
+ ]
66
+ }
83
67
}
84
68
}
85
- }
86
69
</script >
87
70
```
88
71
89
- ### Default settings
72
+ ### Default Options
90
73
91
74
``` json
92
75
{
@@ -104,6 +87,85 @@ export default {
104
87
}
105
88
```
106
89
90
+ ### Extended Options
91
+
92
+ ``` html
93
+ <template >
94
+ <grid
95
+ :auto-width =" autoWidth"
96
+ :cols =" cols"
97
+ :from =" from"
98
+ :language =" language"
99
+ :pagination =" pagination"
100
+ :rows =" rows"
101
+ :search =" search"
102
+ :server =" server"
103
+ :sort =" sort"
104
+ :width =" width"
105
+ ></grid >
106
+ </template >
107
+
108
+ <script >
109
+ import Grid from ' gridjs-vue'
110
+
111
+ export default {
112
+ name: ' MyTable' ,
113
+ components: {
114
+ Grid
115
+ },
116
+ data () {
117
+ return {
118
+ // REQUIRED:
119
+
120
+ // An array containing strings of column headers
121
+ cols: [' col 1' , ' col 2' ],
122
+
123
+ // AND EITHER an array containing row data
124
+ rows: [
125
+ [' row 1 col 1' , ' row 1 col 2' ],
126
+ [' row 2 col 1' , ' row 2 col 2' ]
127
+ ],
128
+
129
+ // OR a string of an HTML table selector to import
130
+ from: ' .my-element'
131
+
132
+ // OR a server settings object
133
+ server () ({
134
+ url: ' https://api.com/search?q=my%20query' ,
135
+ then : res => res .data .map (col => [col1 .data , col2 .data ]),
136
+ handle : res => res .status === 404
137
+ ? { data: [] } : res .ok
138
+ ? res .json () : new Error (' Something went wrong' )
139
+ }),
140
+
141
+ // OPTIONAL:
142
+
143
+ // Boolean to automatically set table width
144
+ autoWidth: true / false ,
145
+
146
+ // Localization dictionary object
147
+ language: {},
148
+
149
+ // Boolean or pagination settings object
150
+ pagination: true / false || {},
151
+
152
+ // Boolean or search settings object
153
+ search: true / false || {},
154
+
155
+ // Boolean or sort settings object
156
+ sort: true / false || {},
157
+
158
+ // String with name of theme or 'none' to disable
159
+ theme: ' mermaid' ,
160
+
161
+ // String with css width value
162
+ width: ' 100%' ,
163
+ }
164
+ }
165
+ }
166
+ </script >
167
+ ```
168
+
107
169
## 🤝 Contributing
108
170
109
171
Originally authored by [ Daniel Sieradski] ( https://twitter.com/self_agency ) .
0 commit comments