Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
gridjs-vue
Advanced tools
A Vue wrapper component for Grid.js.
npm install gridjs-vue
<script>
import Grid from 'gridjs-vue'
export default {
components: {
Grid
}
}
</script>
/* in `main.js` or wherever you specify your global components */
import { GridGlobal } from 'gridjs-vue'
Vue.use(GridGlobal)
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.
Refer to Grid.js documentation 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.
<template>
<grid :cols="cols" :rows="rows"></grid>
</template>
<script>
import Grid from 'gridjs-vue'
export default {
name: 'Cars',
components: {
Grid
},
data() {
return {
cols: ['Make', 'Model', 'Year', 'Color'],
rows: [
['Ford', 'Fusion', '2011', 'Silver'],
['Chevrolet', 'Cruz', '2018', 'White']
]
}
}
}
</script>
If you install the component globally, rather than importing it locally, the following helpers are added to the Vue prototype and are available globally.
this.$gridjs.createRef
Returns a reference to the Grid.js instance.
Example:
const ref = this.$gridjs.createRef
this.$gridjs.h
Renders a Preact virtual DOM instance.
Example:
{
name: 'Actions',
formatter: (cell, row) => {
return this.$gridjs.h('button', {
className: 'py-2 mb-4 px-4 border rounded-md text-white bg-blue-600',
onClick: () => alert(`Editing "${row.cells[0].data}" "${row.cells[1].data}"`)
} 'Edit');
}
}
this.$gridjs.html
Renders HTML in a formatter function.
Example:
{
name: 'Name',
formatter: (cell) => this.$gridjs.html(`<b>${cell}</b>`)
}
{
"autoWidth": true,
"classNames": undefined,
"cols": [""],
"from": undefined,
"language": undefined,
"pagination": false,
"rows": undefined,
"search": false,
"server": undefined,
"sort": false,
"styles": undefined,
"theme": "mermaid",
"width": "100%"
}
<template>
<grid
:auto-width="autoWidth"
:class-names="classNames"
:cols="cols"
:from="from"
:language="language"
:pagination="pagination"
:rows="rows"
:search="search"
:server="server"
:sort="sort"
:styles="styles"
:width="width"
></grid>
</template>
<script>
import Grid from 'gridjs-vue'
export default {
name: 'MyTable',
components: {
Grid
},
data() {
return {
// REQUIRED:
// An array containing strings of column headers (`columns` in the Grid.js API)
cols: ['col 1', 'col 2'],
// OR an array containing objects defining column headers
cols: [
{
name: 'Column 1',
id: 'col1'
},
{
name: 'Column 2',
id: 'col2',
formatter: (cell) => this.$gridjs.html(`<b>${cell}</b>`)
}
],
// AND EITHER an array containing row data (`data` in the Grid.js API)
rows: [
['row 1 col 1', 'row 1 col 2'],
['row 2 col 1', 'row 2 col 2']
],
// OR an array containing JSON row data
rows: [
{ col1: 'row 1', col2: 'row 1' },
{ col1: 'row 2', col2: 'row 2' }
],
// OR a function returning an array of row data
rows() {
return [
{ col1: 3 + 4, col2: 5 + 6 },
{ col1: 1 * 2, col2: 7 * 8 }
]
},
// OR a string of an HTML table selector to import
from: '.my-element',
// OR a function returning an HTML table string
from() {
return `
<table>
<tr><th>column 1</th></tr>
<tr><td>${1 * 2}</td></tr>
</table>
`
},
// OR a server settings function or object
server() ({
url: 'https://api.com/search?q=my%20query',
then: res => res.data.map(col => [col1.data, col2.data]),
handle: res => res.status === 404
? { data: [] } : res.ok
? res.json() : new Error('Something went wrong')
}),
// OPTIONAL:
// Boolean to automatically set table width
autoWidth: true / false,
// Object with CSS class names (`className` in the Grid.js API)
classNames: {},
// Localization dictionary object
language: {},
// Boolean or pagination settings object
pagination: true / false || {},
// Boolean
search: true / false,
// Boolean or sort settings object
sort: true / false || {},
// Object with CSS styles (`style` in the Grid.js API)
styles: {},
// String with name of theme or 'none' to disable
theme: 'mermaid',
// String with css width value
width: '100%',
}
}
}
</script>
Originally authored by Daniel Sieradski.
Contributions, issues and feature requests are welcome!
Feel free to check issues page.
Give a ⭐️ if this project helped you!
FAQs
A Vue.js wrapper component for Grid.js
The npm package gridjs-vue receives a total of 860 weekly downloads. As such, gridjs-vue popularity was classified as not popular.
We found that gridjs-vue demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.