Skip to content

Commit a5d40d7

Browse files
committed
To the moon and back
- Added support for height, resizable, and fixedHeader - Killed off $gridjs.render in favor of new and improved $gridjs.helper function - Fixed style overrides - Fixed per-table stylesheets - Moved most dependencies to Skypack - Added code examples matching those on Grid.js website that also serve as test proofs Signed-off-by: Daniel Sieradski <[email protected]>
1 parent ea93940 commit a5d40d7

Some content is hidden

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

56 files changed

+1809
-197
lines changed

.eslintrc.js

Lines changed: 2 additions & 7 deletions
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',

README.md

Lines changed: 60 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ A Vue wrapper component for [Grid.js](https://gridjs.io).
1212
npm install gridjs-vue
1313
```
1414

15+
Also available on unpkg and Skypack!
16+
1517
### Component Registration
1618

1719
#### Local Registration
@@ -47,7 +49,7 @@ Refer to [Grid.js documentation](https://gridjs.io/docs/config/) for specific co
4749

4850
```html
4951
<template>
50-
<grid :columns="columns" :rows="rows"></grid>
52+
<grid :columns="columns" :rows="rows" ref="myTable"></grid>
5153
</template>
5254

5355
<script>
@@ -78,9 +80,12 @@ Refer to [Grid.js documentation](https://gridjs.io/docs/config/) for specific co
7880
"autoWidth": true,
7981
"className": undefined,
8082
"columns": [""],
83+
"fixedHeader": false,
8184
"from": undefined,
85+
"height": undefined,
8286
"language": undefined,
8387
"pagination": false,
88+
"resizable": true,
8489
"rows": undefined,
8590
"search": false,
8691
"server": undefined,
@@ -99,9 +104,12 @@ Refer to [Grid.js documentation](https://gridjs.io/docs/config/) for specific co
99104
:auto-width="autoWidth"
100105
:class-name="className"
101106
:columns="columns"
107+
:fixed-header="fixedHeader"
102108
:from="from"
109+
:height="height"
103110
:language="language"
104111
:pagination="pagination"
112+
:resizable="resizable"
105113
:rows="rows"
106114
:search="search"
107115
:server="server"
@@ -187,28 +195,37 @@ Refer to [Grid.js documentation](https://gridjs.io/docs/config/) for specific co
187195
// Boolean to automatically set table width
188196
autoWidth: true / false,
189197
190-
// Object with CSS class names
198+
// Object with CSS class definitions (see Grid.js API)
191199
className: {},
192200
193-
// Localization dictionary object
201+
// Boolean to fix positioning of table header
202+
fixedHeader: true / false,
203+
204+
// CSS string setting explicit table height
205+
height: '500px',
206+
207+
// Localization dictionary object (see Grid.js API)
194208
language: {},
195209
196210
// Boolean or pagination settings object
197211
pagination: true / false || {},
198212
199-
// Boolean
213+
// Boolean to enable column resizing
214+
resizable: true / false || {}
215+
216+
// Boolean to enable search bar
200217
search: true / false || {},
201218
202219
// Boolean or sort settings object
203220
sort: true / false || {},
204221
205-
// Object with CSS styles
206-
style: {},
222+
// Object with CSS styles (see Grid.js API)
223+
styles: {},
207224
208225
// String with name of theme or 'none' to disable
209226
theme: 'mermaid' || 'none',
210227
211-
// String with css width value
228+
// CSS string setting explicit table width
212229
width: '100%',
213230
}
214231
}
@@ -218,39 +235,38 @@ Refer to [Grid.js documentation](https://gridjs.io/docs/config/) for specific co
218235

219236
### Helper Functions
220237

221-
If you install the component globally, rather than importing it locally, the following helpers are added to the Vue prototype and are available globally.
222-
223-
#### \$gridjs.uuid
238+
#### \$gridjs.helper
224239

225-
Returns a unique identifier that can be used to reference the current cell.
240+
Simplifies use of Vue components in table formatters.
226241

227242
Usage:
228243

229244
```js
230-
const ref = this.$gridjs.uuid()
231-
```
232-
233-
#### \$gridjs.h
245+
const components = { MyComponent }
246+
const template = `<my-component :content="content"></my-component>`
247+
const data = {
248+
content: '🥳'
249+
}
234250

235-
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?
251+
this.$gridjs.helper(components, template, data)
252+
```
236253

237-
Usage:
254+
Example:
238255

239256
```js
240-
this.columns = [
241-
{
242-
name: 'Actions',
243-
formatter: (cell, row) => {
244-
return this.$gridjs.h('button', {
245-
onClick: () => alert(`
246-
Editing "${row.cells[0].data}"
247-
`)
248-
}, 'Edit')
257+
export default {
258+
data() {
259+
return {
260+
columns: [
261+
{
262+
name: 'Name',
263+
formatter: cell =>
264+
this.$gridjs.helper({ MyComponent }, `<my-component :content="content"></my-component>`, { content: cell })
265+
}
266+
]
249267
}
250-
},
251-
{ ... },
252-
{ ... }
253-
]
268+
}
269+
}
254270
```
255271

256272
#### \$gridjs.html
@@ -264,47 +280,33 @@ this.columns = [
264280
{
265281
name: 'Model',
266282
formatter: cell => this.$gridjs.html(`<b>${cell}</b>`)
267-
},
268-
{ ... },
269-
{ ... }
283+
}
270284
]
271285
```
272286

273-
#### \$gridjs.render
287+
#### \$gridjs.h
274288

275-
Renders a Vue component. Refer to [Vue documentation](https://vuejs.org/v2/guide/render-function.html#createElement-Arguments) for advanced options.
289+
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?
276290

277291
Usage:
278292

279293
```js
280-
this.$gridjs.render(ref, component, { props }, { options })
281-
```
282-
283-
Example:
284-
285-
```js
286-
import FormatterComponent from './FormatterComponent.vue'
287-
288-
[...]
289-
290294
this.columns = [
291295
{
292-
name: 'Model',
293-
formatter: cell => {
294-
const current = this.$gridjs.uuid()
295-
this.$gridjs.render(
296-
`[data-ref="${current}"]`,
297-
FormatterComponent,
296+
name: 'Actions',
297+
formatter: (cell, row) => {
298+
return this.$gridjs.h(
299+
'button',
298300
{
299-
content: cell,
300-
otherProp: true
301-
}
301+
onClick: () =>
302+
alert(`
303+
Editing "${row.cells[0].data}"
304+
`)
305+
},
306+
'Edit'
302307
)
303-
return this.$gridjs.html(`<div data-ref="${current}"></div>`)
304308
}
305-
},
306-
{ ... },
307-
{ ... }
309+
}
308310
]
309311
```
310312

attributes.json

Lines changed: 10 additions & 2 deletions
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"

examples/advanced.html

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<title>Grid.js Vue Component Test</title>
5+
<script src="https://unpkg.com/vue"></script>
6+
</head>
7+
<body>
8+
<div id="app"></div>
9+
10+
<script type="module">
11+
import NestedHeader from './advanced/nested-header.mjs'
12+
import ForceRender from './advanced/force-render.mjs'
13+
import VirtualDom from './advanced/virtual-dom.mjs'
14+
import MultiColumnSort from './advanced/multi-column-sort.mjs'
15+
import CustomSort from './advanced/custom-sort.mjs'
16+
import StockMarket from './advanced/stock-market.mjs'
17+
import Events from './advanced/events.mjs'
18+
19+
new window.Vue({
20+
el: '#app',
21+
name: 'GridTestAdvanced',
22+
components: {
23+
NestedHeader,
24+
ForceRender,
25+
VirtualDom,
26+
MultiColumnSort,
27+
CustomSort,
28+
StockMarket,
29+
Events
30+
},
31+
template: `
32+
<div>
33+
<div>
34+
<h2>Nested Header</h2>
35+
<nested-header></nested-header>
36+
</div>
37+
38+
<div>
39+
<h2>Force Render</h2>
40+
<p>This component is reactive and updates itself when you change the component's data or options in Vue. Interacting with the Grid.js instance directly should not be necessary but remains optional.</p>
41+
<force-render></force-render>
42+
</div>
43+
44+
<div>
45+
<h2>Virtual DOM</h2>
46+
<virtual-dom></virtual-dom>
47+
</div>
48+
49+
<div>
50+
<h2>Multi-column Sort</h2>
51+
<multi-column-sort></multi-column-sort>
52+
</div>
53+
54+
<div>
55+
<h2>Custom Sort</h2>
56+
<custom-sort></custom-sort>
57+
</div>
58+
59+
<div>
60+
<h2>Stock Market</h2>
61+
<stock-market></stock-market>
62+
</div>
63+
64+
<div>
65+
<h2>Events</h2>
66+
<events></events>
67+
</div>
68+
</div>
69+
`
70+
})
71+
</script>
72+
</body>
73+
</html>

examples/advanced/custom-sort.mjs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { Grid } from '../../dist/index.esm.js'
2+
3+
export default {
4+
name: 'CustomSort',
5+
components: {
6+
Grid
7+
},
8+
data() {
9+
return {
10+
columns: [
11+
'Name',
12+
'Email',
13+
{
14+
name: 'Phone Number',
15+
sort: {
16+
compare: (a, b) => {
17+
const code = x => x.split(' ')[0]
18+
19+
if (code(a) > code(b)) {
20+
return 1
21+
} else if (code(b) > code(a)) {
22+
return -1
23+
} else {
24+
return 0
25+
}
26+
}
27+
}
28+
}
29+
],
30+
sort: true,
31+
rows: [
32+
['John', '[email protected]', '+353 40 222 3333'],
33+
['Mark', '[email protected]', '+1 22 888 4444'],
34+
['Eoin', '[email protected]', '+355 10 878 5554'],
35+
['Nisen', '[email protected]', '+313 333 1923']
36+
]
37+
}
38+
},
39+
template: `
40+
<div><grid :columns="columns" :rows="rows" :sort="sort"></grid></div>
41+
`
42+
}

0 commit comments

Comments
 (0)