Package Exports
- vue-good-table
- vue-good-table/dist/vue-good-table.css
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (vue-good-table) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Vue-good-table
A simple, clean data table for VueJS (2.x) with essential features like sorting, column filtering, pagination etc
Hey there! coming from 1.x? find the upgrade guide here

Live Demo
Table of contents
Getting Started
Installing
Install with npm:
npm install --save vue-good-table@alphaImport into project:
import Vue from 'vue';
import VueGoodTable from 'vue-good-table';
// import the styles
import 'vue-good-table/dist/vue-good-table.css'
Vue.use(VueGoodTable);Example Usage
<template>
<div>
<vue-good-table
:columns="columns"
:rows="rows"
:paginate="true"/>
</div>
</template>
<script>
export default {
name: 'my-component',
data(){
return {
columns: [
{
label: 'Name',
field: 'name',
filterable: true,
},
{
label: 'Age',
field: 'age',
type: 'number',
html: false,
filterable: true,
},
{
label: 'Created On',
field: 'createdAt',
type: 'date',
inputFormat: 'YYYYMMDD',
outputFormat: 'MMM Do YY',
},
{
label: 'Percent',
field: 'score',
type: 'percentage',
html: false,
},
],
rows: [
{id:1, name:"John",age:20,createdAt: '201-10-31:9:35 am',score: 0.03343},
{id:2, name:"Jane",age:24,createdAt: '2011-10-31',score: 0.03343},
{id:3, name:"Susan",age:16,createdAt: '2011-10-30',score: 0.03343},
{id:4, name:"Chris",age:55,createdAt: '2011-10-11',score: 0.03343},
{id:5, name:"Dan",age:40,createdAt: '2011-10-21',score: 0.03343},
{id:6, name:"John",age:20,createdAt: '2011-10-31',score: 0.03343},
{id:7, name:"Jane",age:24,createdAt: '20111031'},
{id:8, name:"Susan",age:16,createdAt: '2013-10-31',score: 0.03343},
{id:9, name:"Chris",age:55,createdAt: '2012-10-31',score: 0.03343},
{id:10, name:"Dan",age:40,createdAt: '2011-10-31',score: 0.03343},
{id:11, name:"John",age:20,createdAt: '2011-10-31',score: 0.03343},
{id:12, name:"Jane",age:24,createdAt: '2011-07-31',score: 0.03343},
{id:13, name:"Susan",age:16,createdAt: '2017-02-28',score: 0.03343},
{id:14, name:"Chris",age:55,createdAt: '',score: 0.03343},
{id:15, name:"Dan",age:40,createdAt: '2011-10-31',score: 0.03343},
{id:19, name:"Chris",age:55,createdAt: '2011-10-31',score: 0.03343},
{id:20, name:"Dan",age:40,createdAt: '2011-10-31',score: 0.03343},
],
};
},
};
</script>This should result in the screenshot seen above
Configuration
Component Options
Table
Array containing objects that describe table columns
[
{
label: 'Name',
field: 'name',
filterable: true,
}
//...
]Array containing row objects
[
{
id:1,
name:"John",
age:20
},
//...
]Enable Right-To-Left layout for the table
Show line number for each row
Add responsive class to wrapper
Sort
Enable sorting table by clicking on column
Allows specifying a default sort for the table on wakeup
{
field: 'name',
type: 'asc' //asc or desc (default: 'asc')
}Pagination
Enable Pagination for table
Add pagination on top of the table (default position is bottom)
Number of rows per page
Customize the dropdown options for the amount of items per page
Search
Allows a single search input for the whole table *Note: enabling this filter disables column filters*
Allows user to specify if they want search to trigger on enter event of the input. By default search happens on the fly
searchTrigger='enter'Allows you to specify your own search function for the global search
<vue-good-table
:columns="columns"
:rows="rows"
:searchEnabled="true"
:globalSearchFn="searchFn" />;// in js
methods: {
searchFn(row, col, cellValue, searchTerm){
return value === 'my value';
},
}Text for global search input place holder
Allows global search via your own input field
<input type="text" v-model="searchTerm" >
<vue-good-table
:columns="columns"
:paginate="true"
:externalSearchQuery="searchTerm"
:rows="rows">// and in data
data(){
return {
searchTerm: '',
// rows, columns etc...
};
}Style/Theme
Allows applying your own classes to table
other in-built classes: condensed, striped, bordered
Allows providing custom styles for rows
myStyleFn(row){
// if row has something return a specific class
if(row.fancy) {
return 'fancy-class';
}
return '';
}Allows using other themes
in-built theme: 'nocturnal'
Text
Text for pagination 'Next' link
Text for pagination 'Prev' link
Text for pagination 'Rows per page' label
Text for pagination 'x of y' label
Text for the last option in the items per page dropdown
Column Options
Each column objects can contain the following configuration options:
Text to put on column header
{
label: 'name'
}Row object property that this column corresponds to
- String
eg: 'name'- simple row property name - String
eg: 'location.lat'- nested row property name. lets say if the row had a property 'location' which was an object containing 'lat' and 'lon' - Function - a function that returns a value to be displayed based on the row object
{ field: fieldFn } // in methods fieldFn(rowObj) { // do something with the row object }
type of column. default: 'text'. This determines the formatting for the column and filter behavior as well
- number - right aligned
- decimal - right aligned, 2 decimal places
- percentage - expects a decimal like 0.03 and formats it as 3.00%
- date - expects a string representation of date eg
'20170530'. You should also specify dateInputFormat and dateOutputForamt
provide the format to parse date string
'YYYYMMDD' //where date strings are '20170530'
provide the format for output date
'MMM Do YY' //where date will be output like 'May 30th 17'
enable/disable sorting on columns. This property is higher priority than global sortable property
custom sort function. If you want to supply your own sort function you can use this property to supply it.
// in data
column: [
{
label: 'Name',
field: 'name',
sortable: true,
sortFn: this.sortFn,
}
//...
],
// in methods
methods: {
sortFn(x, y, col) {
return (x < y ? -1 : (x > y ? 1 : 0));
}
}Allows for custom format of values, function(value),
should return the formatted value to display.
formatFn: function(value) {
return '$' + value;
}indicates whether this column will require html rendering or not
htmlContent: '<button>Hello</button>', then `html: true` on the column will render a button
provide a width value for this column
width: '50px'
allow hiding a column on table
provide custom class(es) to the th
thClass: 'custom-th-class'
provide custom class(es) to the td
tdClass: 'text-center'
if true, this column will be ignored by the global search
A collection of filter specific properties
{
enabled: true, // enable filter for this column
placeholder: 'Filter This Thing', // placeholder for filter input
filterValue: 'Jane', // initial populated value for this filter
filterDropdownItems: [], // dropdown (with selected values) instead of text input
filterFn: this.columnFilterFn, //custom filter function that
}Column filter option in-depth
Some filterOption properties need a little more explanation
allows creating a dropdown for filter as opposed to an input
//array
filterOptions: ['Blue', 'Red', 'Yellow']
//or
filterOptions: [
{ value: 'n', text: 'Inactive' },
{ value: 'y', text: 'Active' },
{ value: 'c', text: 'Check' }
],Custom filter, function of two variables: function(data, filterString), should return true if data matches the filterString, otherwise false.
filterFn: function(data, filterString) {
var x = parseInt(filterString)
return data >= x-5 && data <= x+5
}
//would create a filter matching numbers within 5 of the provided value.Style Options
Vue-good-table allows providing your own css classes for the table via styleClass option but it also has in-built classes that you can make use of
.vgt-table

.vgt-table .stripped

.vgt-table .condensed

Theme
Vue-good-table currently comes in two themes
default
nocturnal theme='nocturnal'

Advanced Customization
Custom row template
vue-good-table also supports dynamic td templates where you dictate how to display the cells. Example:
<vue-good-table
:columns="columns"
:rows="rows">
<template slot="table-row" slot-scope="props">
<span v-if="props.column.field == 'age'">
age: {{props.row.age}}
</span>
<span v-else>
{{props.formattedRow[props.column.field]}}
</span>
</template>
</vue-good-table>Note:
- The original row object can be accessed via
props.row - The currently displayed table row index can be accessed via
props.index. - The original row index can be accessed via
props.row.originalIndex. You can then access the original row object by usingrow[props.row.originalIndex]. - The column object can be accessed via
props.column - You can access the formatted row data (for example - formatted date) via
props.formattedRow
Custom column headers
Sometimes you might want to use custom column formatting. You can do that in the following way
<vue-good-table
:columns="columns"
:rows="rows">
<template slot="table-column" slot-scope="props">
<span v-if="props.column.label =='Name'">
<i class="fa fa-address-book"></i> {{props.column.label}}
</span>
<span v-else>
{{props.column.label}}
</span>
</template>
</vue-good-table>Empty state slot
You can provide html for empty state slot as well. Example:
<vue-good-table
:columns="columns"
:rows="rows">
<div slot="emptystate">
This will show up when there are no columns
</div>
</vue-good-table>Authors
License
This project is licensed under the MIT License - see the LICENSE.md file for details