UNPKG

31.2 kBMarkdownView Raw
1# Vue-good-table
2
3[![npm](https://img.shields.io/npm/dm/vue-good-table.svg?style=flat-square)](https://www.npmjs.com/package/vue-good-table)
4[![npm](https://img.shields.io/github/package-json/v/xaksis/vue-good-table.svg?style=flat-square)](https://github.com/xaksis/vue-good-table/releases)
5[![npm](https://img.shields.io/github/license/xaksis/vue-good-table.svg?style=flat-square)](https://github.com/xaksis/vue-good-table/blob/master/LICENSE)
6[![](https://data.jsdelivr.com/v1/package/npm/vue-good-table/badge)](https://www.jsdelivr.com/package/npm/vue-good-table)
7
8An easy to use, clean and powerful data table for VueJS with essential features like sorting, column filtering, pagination and much more - [xaksis.github.io/vue-good-table/](https://xaksis.github.io/vue-good-table/)
9
10Did vue-good-table just save you a bunch of time? Use some of them extra minutes to spread the joy!
11
12<a href="https://www.buymeacoffee.com/68BUXR1d9" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/purple_img.png" alt="Buy Me A Coffee" style="height: auto !important;width: auto !important;" ></a>
13
14**Follow the project progress live** - [Vue-good-table Project on TimerBit](https://timerbit.com/#/public/YN3UZqeorFGRKI1h03d5)
15
16<!--
17### Basic Table
18![Basic Screenshot](README/images/vgt-table.regular.png) -->
19
20<!-- ## Recipes
21Some example recipes for inspiration
22[vue-good-table Recipes](https://github.com/xaksis/vue-good-table/wiki/Vue-good-table-Recipes-(vue-good-table-2.x)) -->
23<!--
24## Table of contents -->
25
26<!-- START doctoc generated TOC please keep comment here to allow auto update -->
27<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
28
29<!--
30- [Getting Started](#getting-started)
31 - [Installing](#installing)
32 - [Example Usage](#example-usage)
33- [Configuration](#configuration)
34 - [Component Options](#component-options)
35 - [Table](#table)
36 - [Sort Options](#sort-options)
37 - [Pagination Options](#pagination-options)
38 - [Search Options](#search-options)
39 - [Checkbox Table](#checkbox-table)
40 - [Grouped Row Options](#grouped-row-options)
41 - [Style/Theme](#styletheme)
42 - [Column Options](#column-options)
43 - [Column filter option in-depth](#column-filter-option-in-depth)
44 - [Table Events](#table-events)
45 - [@on-row-click](#on-row-click)
46 - [@on-cell-click](#on-cell-click)
47 - [@on-row-mouseenter](#on-row-mouseenter)
48 - [@on-row-mouseleave](#on-row-mouseleave)
49 - [@on-search](#on-search)
50 - [@on-page-change](#on-page-change)
51 - [@on-per-page-change](#on-per-page-change)
52 - [@on-sort-change](#on-sort-change)
53 - [@on-select-all](#on-select-all)
54 - [@on-column-filter](#on-column-filter)
55 - [@on-selected-rows-change](#on-selected-rows-change)
56 - [Style Options](#style-options)
57 - [.vgt-table](#vgt-table)
58 - [.vgt-table .stripped](#vgt-table-stripped)
59 - [.vgt-table .condensed](#vgt-table-condensed)
60- [Themes](#themes)
61 - [default](#default)
62 - [nocturnal `theme='nocturnal'`](#nocturnal-themenocturnal)
63 - [black-rhino `theme='black-rhino'`](#black-rhino-themeblack-rhino)
64- [Advanced Customization](#advanced-customization)
65 - [Custom row template](#custom-row-template)
66 - [Custom column headers](#custom-column-headers)
67 - [Grouped Rows](#grouped-rows)
68 - [Remote Mode](#remote-mode)
69 - [Table Actions Slot](#table-actions-slot)
70 - [Empty state slot](#empty-state-slot)
71- [Authors](#authors)
72- [License](#license) -->
73
74<!-- END doctoc generated TOC please keep comment here to allow auto update -->
75
76## Installing
77
78Install with npm:
79```bash
80npm install --save vue-good-table
81```
82
83Import globally in app:
84
85```javascript
86import VueGoodTablePlugin from 'vue-good-table';
87
88// import the styles
89import 'vue-good-table/dist/vue-good-table.css'
90
91Vue.use(VueGoodTablePlugin);
92```
93
94Import into your component
95```js
96import { VueGoodTable } from 'vue-good-table';
97
98// add to component
99components: {
100 VueGoodTable,
101}
102```
103
104
105##### Example table with grouped rows and column filters
106![Advanced Screenshot](README/images/vgt-table.advanced.png)
107
108## Features
109* [Table Search](https://xaksis.github.io/vue-good-table/guide/configuration/search-options.html)
110* [Sorting](https://xaksis.github.io/vue-good-table/guide/configuration/sort-options.html)
111* [Column Filtering](https://xaksis.github.io/vue-good-table/guide/configuration/column-filter-options.html#filteroptions)
112* [Pagination](https://xaksis.github.io/vue-good-table/guide/configuration/pagination-options.html)
113* [Highly Customizable](https://xaksis.github.io/vue-good-table/guide/advanced/#custom-row-template)
114* [Checkbox Table](https://xaksis.github.io/vue-good-table/guide/advanced/checkbox-table.html)
115* [Grouped Rows Table](https://xaksis.github.io/vue-good-table/guide/advanced/grouped-table.html)
116* [Server Powered Table](https://xaksis.github.io/vue-good-table/guide/advanced/remote-workflow.html#why-remote-mode)
117* [Customizable Style and Themes](https://xaksis.github.io/vue-good-table/guide/style-configuration/)
118
119## Upgrade Guide
120Hey there! coming from 1.x? find the [upgrade guide here](https://github.com/xaksis/vue-good-table/wiki/Guide-to-upgrade-from-1.x-to-v2.0)
121
122<!--
123### Example Usage
124```html
125<template>
126 <div>
127 <vue-good-table
128 :columns="columns"
129 :rows="rows"
130 :search-options="{
131 enabled: true,
132 }"
133 :pagination-options="{
134 enabled: true,
135 perPage: 5,
136 }"
137 styleClass="vgt-table striped bordered"/>
138 </div>
139</template>
140
141<script>
142export default {
143 name: 'my-component',
144 data(){
145 return {
146 columns: [
147 {
148 label: 'Name',
149 field: 'name',
150 filterOptions: {
151 enabled: true,
152 },
153 },
154 {
155 label: 'Age',
156 field: 'age',
157 type: 'number',
158 },
159 {
160 label: 'Created On',
161 field: 'createdAt',
162 type: 'date',
163 dateInputFormat: 'YYYY-MM-DD',
164 dateOutputFormat: 'MMM Do YY',
165 },
166 {
167 label: 'Percent',
168 field: 'score',
169 type: 'percentage',
170 },
171 ],
172 rows: [
173 { id:1, name:"John", age: 20, createdAt: '201-10-31:9: 35 am',score: 0.03343 },
174 { id:2, name:"Jane", age: 24, createdAt: '2011-10-31', score: 0.03343 },
175 { id:3, name:"Susan", age: 16, createdAt: '2011-10-30', score: 0.03343 },
176 { id:4, name:"Chris", age: 55, createdAt: '2011-10-11', score: 0.03343 },
177 { id:5, name:"Dan", age: 40, createdAt: '2011-10-21', score: 0.03343 },
178 { id:6, name:"John", age: 20, createdAt: '2011-10-31', score: 0.03343 },
179 { id:7, name:"Jane", age: 24, createdAt: '20111031' },
180 { id:8, name:"Susan", age: 16, createdAt: '2013-10-31', score: 0.03343 },
181 ],
182 };
183 },
184};
185</script>
186``` -->
187<!--
188## Configuration
189### Component Options
190#### Table
191These options relate to the table as a whole
192
193##### columns `Array`
194
195Array containing objects that describe table columns. The column object itself can contain many [configurable properties](#column-options).
196```javascript
197[
198 {
199 label: 'Name',
200 field: 'name',
201 filterable: true,
202 }
203 //...
204]
205```
206
207##### rows `Array`
208
209Array containing row objects. Each row object contains data that will be displayed in the table row.
210```javascript
211[
212 {
213 id:1,
214 name:"John",
215 age:20
216 },
217 //...
218]
219```
220> for **grouped rows**, you need a nested format. Refer to [Grouped Rows](#grouped-rows) for an example.
221
222##### rtl `Boolean (default: false)`
223
224Enable Right-To-Left layout for the table
225```html
226<vue-good-table
227 :columns="columns"
228 :rows="rows"
229 :rtl="true">
230</vue-good-table>
231```
232
233##### lineNumbers `Boolean (default: false)`
234Show line number for each row
235```html
236<vue-good-table
237 :columns="columns"
238 :rows="rows"
239 :lineNumbers="true">
240</vue-good-table>
241```
242
243##### mode `String`
244Set mode=`remote` to allow sorting/filtering etc to be powered by server side instead of client side. Setting mode to remote, expects the following workflow:
245
246* pagination, sort, filter, search will emit [Table Events](#table-events) (loading div appears)
247* setup handlers for each event
248* in the handler call backend endpoints with the table params
249* update rows object with the returned response ( the loading div will disappear once you update the rows object)
250
251for a detailed workflow example check out [The remote mode workflow wiki](https://github.com/xaksis/vue-good-table/wiki/Remote-Mode-Workflow)
252
253```html
254<vue-good-table
255 :columns="columns"
256 :rows="rows"
257 mode="remote">
258</vue-good-table>
259```
260
261
262#### Sort Options
263---
264Set of options related to table sorting
265```html
266<vue-good-table
267 :columns="columns"
268 :rows="rows"
269 :sort-options="{
270 enabled: true,
271 initialSortBy: {field: 'name', type: 'asc'}
272 }">
273</vue-good-table>
274```
275
276##### sortOptions.enabled `Boolean (default: true)`
277Enable/disable sorting on table as a whole.
278```html
279<vue-good-table
280 :columns="columns"
281 :rows="rows"
282 :sort-options="{
283 enabled: true,
284 }">
285</vue-good-table>
286```
287
288##### sortOptions.initialSortBy `Object`
289Allows specifying a default sort for the table on wakeup
290```html
291<vue-good-table
292 :columns="columns"
293 :rows="rows"
294 :sort-options="{
295 enabled: true,
296 initialSortBy: {field: 'name', type: 'asc'}
297 }">
298</vue-good-table>
299```
300
301```javascript
302// in data
303defaultSort: {
304 field: 'name',
305 type: 'asc' //asc or desc (default: 'asc')
306}
307```
308
309#### Pagination Options
310---
311A set of options that are related to table pagination. Each of these are optional and reasonable defaults will be used if you leave off the property.
312```html
313<vue-good-table
314 :columns="columns"
315 :rows="rows"
316 :paginationOptions="{
317 enabled: true,
318 perPage: 5,
319 position: 'top',
320 perPageDropdown: [3, 7, 9],
321 dropdownAllowAll: false,
322 setCurrentPage: 2,
323 nextLabel: 'next',
324 prevLabel: 'prev',
325 rowsPerPageLabel: 'Rows per page',
326 ofLabel: 'of',
327 allLabel: 'All',
328 }">
329</vue-good-table>
330```
331Options explained below
332##### paginationOptions.enabled `Boolean (default: false)`
333Enable Pagination for table. By default the paginator is created at the bottom of the table.
334```html
335<vue-good-table
336 :columns="columns"
337 :rows="rows"
338 :paginationOptions="{
339 enabled: true
340 }">
341</vue-good-table>
342```
343
344##### paginationOptions.position `String (default: 'bottom')`
345Add pagination on `'top'` or `'bottom'` (top and bottom) of the table (default position is bottom)
346```html
347<vue-good-table
348 :columns="columns"
349 :rows="rows"
350 :paginationOptions="{
351 enabled: true,
352 position: 'top'
353 }">
354</vue-good-table>
355```
356
357##### paginationOptions.perPage `Integer (default: 10)`
358Number of rows to show per page
359```html
360<vue-good-table
361 :columns="columns"
362 :rows="rows"
363 :paginationOptions="{
364 enabled: true,
365 perPage: 5
366 }">
367</vue-good-table>
368```
369
370##### paginationOptions.perPageDropdown `Array (default: [10,20,30,40,50])`
371Customize the dropdown options for the amount of items per page
372```html
373<vue-good-table
374 :columns="columns"
375 :rows="rows"
376 :paginationOptions="{
377 enabled: true,
378 perPageDropdown: [3, 7, 9]
379 }">
380</vue-good-table>
381```
382
383##### paginationOptions.dropdownAllowAll `Boolean (default: true)`
384enables/disables 'All' in the per page dropdown.
385```html
386<vue-good-table
387 :columns="columns"
388 :rows="rows"
389 :paginationOptions="{
390 enabled: true,
391 perPageDropdown: [3, 7, 9],
392 dropdownAllowAll: false,
393 }">
394</vue-good-table>
395```
396
397##### paginationOptions.setCurrentPage `Number`
398set current page programmatically.
399> There's no validation for number of pages so please be careful using this.
400```html
401<vue-good-table
402 :columns="columns"
403 :rows="rows"
404 :paginationOptions="{
405 enabled: true,
406 setCurrentPage: 2,
407 }">
408</vue-good-table>
409```
410
411##### pagination label/text options
412you can change one or more of the texts shown on pagination by overriding the labels in the following way:
413```html
414<vue-good-table
415 :columns="columns"
416 :rows="rows"
417 :paginationOptions="{
418 enabled: true,
419 nextLabel: 'next',
420 prevLabel: 'prev',
421 rowsPerPageLabel: 'Rows per page',
422 ofLabel: 'of',
423 allLabel: 'All',
424 }">
425</vue-good-table>
426```
427
428#### Search Options
429---
430Set of search related options. These options pertain to the global table search.
431```html
432<vue-good-table
433 :columns="columns"
434 :rows="rows"
435 :searchOptions="{
436 enabled: true,
437 trigger: 'enter',
438 searchFn: mySearchFn,
439 placeholder: 'Search this table',
440 externalQuery: searchQuery
441 }">
442</vue-good-table>
443```
444
445Search options explained below
446
447##### searchOptions.enabled `Boolean (default: false)`
448
449Allows a single search input for the whole table
450
451>Note: enabling this option disables column filters
452```html
453<vue-good-table
454 :columns="columns"
455 :rows="rows"
456 :searchOptions="{
457 enabled: true
458 }">
459</vue-good-table>
460```
461
462##### searchOptions.trigger `String (default: '')`
463Allows you to specify if you want search to trigger on 'enter' event of the input. By default table searches on key-up.
464
465```html
466<vue-good-table
467 :columns="columns"
468 :rows="rows"
469 :searchOptions="{
470 enabled: true,
471 trigger: 'enter'
472 }">
473</vue-good-table>
474```
475
476##### searchOptions.searchFn `Function`
477
478Allows you to specify your own search function for the global search
479
480```html
481<vue-good-table
482 :columns="columns"
483 :rows="rows"
484 :searchOptions="{
485 enabled: true,
486 searchFn: myFunc
487 }">
488</vue-good-table>
489```
490```javascript
491// in js
492methods: {
493 myFunc(row, col, cellValue, searchTerm){
494 return cellValue === 'my value';
495 },
496}
497```
498
499##### searchOptions.placeholder `String (default: 'Search Table')`
500Text for global search input place holder
501```html
502<vue-good-table
503 :columns="columns"
504 :rows="rows"
505 :searchOptions="{
506 enabled: true,
507 placeholder: 'Search this table',
508 }">
509</vue-good-table>
510```
511
512##### searchOptions.externalQuery `String`
513
514If you want to use your own input for searching the table, you can use this property
515
516```html
517<input type="text" v-model="searchTerm" >
518<vue-good-table
519 :columns="columns"
520 :rows="rows"
521 :searchOptions="{
522 enabled: true,
523 externalQuery: searchTerm
524 }">
525</vue-good-table>
526```
527```javascript
528// and in data
529data(){
530 return {
531 searchTerm: '',
532 // rows, columns etc...
533 };
534}
535```
536
537#### Checkbox Table
538Creating table with selectable rows (checkboxes) is easier than ever.
539![Checkbox Screenshot](README/images/vgt-table.checkbox.png)
540
541##### selectOptions `Object`
542Object containing select options
543```html
544<vue-good-table
545 @on-select-all="allSelected"
546 @on-selected-rows-change="onSelectedRowsChange"
547 @on-row-click="rowSelected"
548 :columns="columns"
549 :rows="rows"
550 :selectOptions="{
551 enabled: true,
552 selectOnCheckboxOnly: true, // only select when checkbox is clicked instead of the row
553 selectionInfoClass: 'custom-class',
554 selectionText: 'rows selected',
555 clearSelectionText: 'clear',
556 }">
557 ```
558
559 you can get the selectedRows listening the [@on-selected-rows-change](#on-selected-rows-change) event.
560
561
562#### Grouped Row Options
563---
564Sometimes you have a hierarchy in table and you want to group rows under subheadings, vue-good-table allows you to do that as well. Following properties relate to row grouping
565
566##### groupOptions `Object`
567Object containing group related options.
568```html
569<vue-good-table
570 :columns="columns"
571 :rows="rows"
572 :group-options="{
573 enabled: true,
574 headerPosition: 'bottom'
575 }">
576 ```
577> rows are formatted differently for grouped tables, refer to [Grouped Rows](#grouped-rows) section.
578
579#### Style/Theme
580---
581Style options for table
582
583##### styleClass `String (default: 'vgt-table bordered')`
584Allows applying your own classes to table. Other in-built classes: condensed, striped, bordered
585```html
586<vue-good-table
587 :columns="columns"
588 :rows="rows"
589 styleClass="vgt-table bordered striped">
590</vue-good-table>
591```
592
593##### rowStyleClass `String or Function`
594
595Allows providing custom styles for rows. It can be a string: 'my-class' or a function.
596```html
597<vue-good-table
598 :columns="columns"
599 :rows="rows"
600 :rowStyleClass="myStyleFn">
601</vue-good-table>
602```
603```javascript
604// in methods
605myStyleFn(row){
606 // if row has something return a specific class
607 if(row.fancy) {
608 return 'fancy-class';
609 }
610 return '';
611}
612```
613
614##### theme `String`
615Allows using other themes.
616Included themes:
617* [nocturnal](#nocturnal-themenocturnal)
618* [black-rhino](#black-rhino-themeblack-rhino)
619
620```html
621<vue-good-table
622 :columns="columns"
623 :rows="rows"
624 theme="nocturnal">
625</vue-good-table>
626```
627
628
629### Column Options
630---
631Each column objects can contain the following configuration options:
632
633
634##### label `String`
635Text to put on column header.
636
637```javascript
638columns: [
639 {
640 label: 'name'
641 },
642 // ...
643]
644```
645
646##### field `String`
647
648Row object property that this column corresponds to. This can be:
649
650* String <code>eg: 'name'</code> - simple row property name
651* String <code>eg: 'location.lat'</code>- nested row property name. lets say if the row had a property 'location' which was an object containing 'lat' and 'lon'
652* Function - a function that returns a value to be displayed based on the row object
653```javascript
654columns: [
655 {
656 label: 'name',
657 field: this.fealdFn,
658 },
659 // ...
660]
661// in methods
662fieldFn(rowObj) {
663 return rowObj.name;
664}
665```
666
667##### type `String`
668
669type of column. default: 'text'. This determines the formatting for the column and filter behavior as well. Possible values:
670* _number_ - right aligned
671* _decimal_ - right aligned, 2 decimal places
672* _percentage_ - expects a decimal like 0.03 and formats it as 3.00%
673* _boolean_ - right aligned
674* _date_ - expects a string representation of date eg `'20170530'`. You should also specify [dateInputFormat](#dateinputformat) and [dateOutputFormat](dateoutputformat)
675
676```javascript
677columns: [
678 {
679 label: 'joined On',
680 field: 'createdAt',
681 type: 'date',
682 dateInputFormat: 'YYYY-MM-DD', // expects 2018-03-16
683 dateOutputFormat: 'MMM Do YYYY', // outputs Mar 16th 2018
684 },
685 // ...
686]
687```
688
689##### dateInputFormat `String`
690provide the format to parse date string
691
692##### dateOutputFormat `String`
693provide the format for output date
694
695##### sortable `Boolean`
696enable/disable sorting on columns. This property is higher priority than global sortable property
697```javascript
698columns: [
699 {
700 label: 'name',
701 field: 'user_name',
702 sortable: false,
703 },
704 // ...
705]
706```
707
708##### sortFn `Function`
709
710custom sort function. If you want to supply your own sort function you can use this property.
711
712```javascript
713// in data
714columns: [
715 {
716 label: 'Name',
717 field: 'name',
718 sortable: true,
719 sortFn: this.sortFn,
720 }
721 //...
722],
723// in methods
724methods: {
725 sortFn(x, y, col, rowX, rowY) {
726 // x - row1 value for column
727 // y - row2 value for column
728 // col - column being sorted
729 // rowX - row object for row1
730 // rowY - row object for row2
731 return (x < y ? -1 : (x > y ? 1 : 0));
732 }
733}
734```
735
736##### formatFn `Function`
737Allows for custom format of values, <code>function(value)</code>, should return the formatted value to display.
738
739```javascript
740// in data
741columns: [
742 {
743 label: 'Salary',
744 field: 'salary',
745 sortable: true,
746 formatFn: this.formatFn,
747 }
748 //...
749],
750// in methods
751formatFn: function(value) {
752 return '$' + value;
753}
754```
755
756##### html `Boolean`
757indicates whether this column will require html rendering.
758> The preferred way of creating columns that have html is by [using slots](#custom-row-template)
759```javascript
760// in data
761columns: [
762 {
763 label: 'Action',
764 field: 'btn',
765 html: true,
766 }
767 //...
768],
769rows: [
770 {
771 btn: '<button>My Action</button>',
772 // ...
773 }
774]
775```
776
777##### width `Number`
778provide a width value for this column
779
780```javascript
781columns: [
782 {
783 label: 'name',
784 field: 'user_name',
785 width: '50px',
786 },
787 // ...
788]
789```
790
791##### hidden `Boolean`
792hide a column
793```javascript
794columns: [
795 {
796 label: 'name',
797 field: 'user_name',
798 hidden: true,
799 },
800 // ...
801]
802```
803
804##### thClass `String`
805provide custom class(es) to the table header
806```javascript
807columns: [
808 {
809 label: 'name',
810 field: 'user_name',
811 thClass: 'custom-th-class',
812 },
813 // ...
814]
815```
816
817##### tdClass `String`
818provide custom class(es) to the table cells
819```javascript
820columns: [
821 {
822 label: 'name',
823 field: 'user_name',
824 tdClass: 'text-center',
825 },
826 // ...
827]
828```
829
830##### globalSearchDisabled `Boolean (default: false)`
831if true, this column will be ignored by the global search
832```javascript
833columns: [
834 {
835 label: 'name',
836 field: 'user_name',
837 globalSearchDisabled: true,
838 },
839 // ...
840]
841```
842
843##### filterOptions `Object`
844A collection of filter specific properties. You can find more about these properties in [column filter options section](#column-filter-option-in-depth)
845
846```javascript
847columns: [
848 {
849 label: 'name',
850 field: 'user_name',
851 filterOptions: {
852 enabled: true, // enable filter for this column
853 placeholder: 'Filter This Thing', // placeholder for filter input
854 filterValue: 'Jane', // initial populated value for this filter
855 filterDropdownItems: [], // dropdown (with selected values) instead of text input
856 filterFn: this.columnFilterFn, //custom filter function that
857 trigger: 'enter', //only trigger on enter not on keyup
858 },
859 },
860 // ...
861]
862```
863
864#### Column filter option in-depth
865---
866Some filterOption properties need a little more explanation
867
868##### filterDropdownItems `Array of strings or Array of objects`
869allows creating a dropdown for filter as opposed to an input
870
871```javascript
872//array
873filterDropdownItems: ['Blue', 'Red', 'Yellow']
874//or
875filterDropdownItems: [
876 { value: 'n', text: 'Inactive' },
877 { value: 'y', text: 'Active' },
878 { value: 'c', text: 'Check' }
879],
880```
881
882##### filterFn `Function`
883Custom filter, function of two variables: <code>function(data, filterString)</code>, should return true if data matches the filterString, otherwise false
884
885```javascript
886filterFn: function(data, filterString) {
887 var x = parseInt(filterString)
888 return data >= x - 5 && data <= x + 5;
889}
890// would create a filter matching numbers within 5 of the provided value
891```
892
893### Table Events
894
895#### @on-row-click
896event emitted on table row click
897```html
898<vue-good-table
899 :columns="columns"
900 :rows="rows"
901 @on-row-click="onRowClick">
902 ```
903 ```javascript
904 methods: {
905 onRowClick(params) {
906 // params.row - row object
907 // params.pageIndex - index of this row on the current page.
908 // params.selected - if selection is enabled this argument
909 // indicates selected or not
910 // params.event - click event
911 }
912 }
913 ```
914
915 #### @on-cell-click
916event emitted on table cell click
917```html
918<vue-good-table
919 :columns="columns"
920 :rows="rows"
921 @on-cell-click="onCellClick">
922 ```
923 ```javascript
924 methods: {
925 onCellClick(params) {
926 // params.row - row object
927 // params.column - column object
928 // params.rowIndex - index of this row on the current page.
929 // params.event - click event
930 }
931 }
932 ```
933
934 #### @on-row-mouseenter
935event emitted on row mouseenter
936```html
937<vue-good-table
938 :columns="columns"
939 :rows="rows"
940 @on-row-mouseenter="onRowMouseover">
941 ```
942 ```javascript
943 methods: {
944 onRowMouseover(params) {
945 // params.row - row object
946 // params.pageIndex - index of this row on the current page.
947 }
948 }
949 ```
950
951 #### @on-row-mouseleave
952event emitted on table row mouseleave
953```html
954<vue-good-table
955 :columns="columns"
956 :rows="rows"
957 @on-row-mouseleave="onRowMouseleave">
958 ```
959 ```javascript
960 methods: {
961 onRowMouseleave(row, pageIndex) {
962 // row - row object
963 // pageIndex - index of this row on the current page.
964 }
965 }
966 ```
967
968#### @on-search
969event emitted on global search (when global search is enabled)
970```html
971<vue-good-table
972 :columns="columns"
973 :rows="rows"
974 @on-search="onSearch">
975 ```
976 ```javascript
977 methods: {
978 onSearch(params) {
979 // params.searchTerm - term being searched for
980 // params.rowCount - number of rows that match search
981 }
982 }
983 ```
984
985#### @on-page-change
986event emitted on pagination page change (when pagination is enabled)
987```html
988<vue-good-table
989 :columns="columns"
990 :rows="rows"
991 @on-page-change="onPageChange">
992 ```
993 ```javascript
994 methods: {
995 onPageChange(params) {
996 // params.currentPage - current page that pagination is at
997 // params.currentPerPage - number of items per page
998 // params.total - total number of items in the table
999 }
1000 }
1001 ```
1002
1003#### @on-per-page-change
1004event emitted on per page dropdown change (when pagination is enabled)
1005```html
1006<vue-good-table
1007 :columns="columns"
1008 :rows="rows"
1009 @on-per-page-change="onPageChange">
1010```
1011```javascript
1012methods: {
1013 onPageChange(params) {
1014 // params.currentPage - current page that pagination is at
1015 // params.currentPerPage - number of items per page
1016 // params.total - total number of items in the table
1017 }
1018}
1019```
1020
1021#### @on-sort-change
1022event emitted on sort change
1023```html
1024<vue-good-table
1025 :columns="columns"
1026 :rows="rows"
1027 @on-sort-change="onSortChange">
1028```
1029```javascript
1030methods: {
1031 onSortChange(params) {
1032 // params.sortType - ascending or descending
1033 // params.columnIndex - index of column being sorted
1034 }
1035}
1036```
1037
1038
1039#### @on-select-all
1040event emitted when all is selected (only emitted for checkbox tables)
1041```html
1042<vue-good-table
1043 :columns="columns"
1044 :rows="rows"
1045 @on-select-all="onSelectAll">
1046 ```
1047 ```javascript
1048 methods: {
1049 onSelectAll(params) {
1050 // params.selected - whether the select-all checkbox is checked or unchecked
1051 // params.selectedRows - all rows that are selected (this page)
1052 }
1053 }
1054 ```
1055
1056 #on-selected-rows-change
1057 event emitted each time selectedRows has changed
1058 ```html
1059 <vue-good-table
1060 :columns="columns"
1061 :rows="rows"
1062 @on-selected-rows-change="onSelectedRowsChange">
1063 ```
1064 ```javascript
1065 methods: {
1066 onSelectedRowsChange(params) {
1067 // params.selectedRows - all rows that are selected (this page)
1068 }
1069 }
1070 ```
1071
1072 #### @on-column-filter
1073event emitted when column is filtered (only emitted for remote mode)
1074```html
1075<vue-good-table
1076 :columns="columns"
1077 :rows="rows"
1078 @on-column-filter="onColumnFilter">
1079 ```
1080 ```javascript
1081 methods: {
1082 onColumnFilter(params) {
1083 // params.columnFilters - filter values for each column in the following format:
1084 // {field1: 'filterTerm', field3: 'filterTerm2')
1085 }
1086 }
1087 ```
1088
1089### Style Options
1090
1091Vue-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
1092
1093#### .vgt-table
1094![Table Screenshot](README/images/vgt-table.regular.png)
1095
1096#### .vgt-table .stripped
1097![Table Bordered Striped Screenshot](README/images/vgt-table.png)
1098
1099#### .vgt-table .condensed
1100![Table Bordered Striped Screenshot](README/images/vgt-table.condensed.png)
1101
1102
1103## Themes
1104
1105### default
1106### nocturnal `theme='nocturnal'`
1107![Nocturnal Theme Screenshot](README/images/vgt-table.nocturnal.png)
1108
1109### black-rhino `theme='black-rhino'`
1110![Black Rhino Theme Screenshot](README/images/vgt-table.black-rhino.png)
1111
1112## Advanced Customization
1113
1114### Custom row template
1115vue-good-table also supports dynamic td templates where you dictate how to display the cells. Example:
1116```html
1117<vue-good-table
1118 :columns="columns"
1119 :rows="rows">
1120 <template slot="table-row" slot-scope="props">
1121 <span v-if="props.column.field == 'age'">
1122 age: {{props.row.age}}
1123 </span>
1124 <span v-else>
1125 {{props.formattedRow[props.column.field]}}
1126 </span>
1127 </template>
1128</vue-good-table>
1129```
1130**Note:**
1131* The original row object can be accessed via `props.row`
1132* The currently displayed table row index can be accessed via `props.index` .
1133* The original row index can be accessed via `props.row.originalIndex`. You can then access the original row object by using `rows[props.row.originalIndex]`.
1134* The column object can be accessed via `props.column`
1135* You can access the formatted row data (for example - formatted date) via `props.formattedRow`
1136
1137### Custom column headers
1138Sometimes you might want to use custom column formatting. You can do that in the following way
1139```html
1140<vue-good-table
1141 :columns="columns"
1142 :rows="rows">
1143 <template slot="table-column" slot-scope="props">
1144 <span v-if="props.column.label =='Name'">
1145 <i class="fa fa-address-book"></i> {{props.column.label}}
1146 </span>
1147 <span v-else>
1148 {{props.column.label}}
1149 </span>
1150 </template>
1151</vue-good-table>
1152```
1153
1154### Grouped Rows
1155To create grouped rows, you need two things.
11561. add groupOptions to table component
1157```html
1158<vue-good-table
1159 :columns="columns"
1160 :rows="rows"
1161 :groupOptions="{
1162 enabled: true
1163 }">
1164</vue-good-table>
1165```
1166
11672. make sure the rows are formatted correctly. grouped rows need to be nested with headers rows containing rows in their children property. For example:
1168
1169```javascript
1170rows: [{
1171 mode: 'span', // span means this header will span all columns
1172 label: 'Header Two', // this is the label that'll be used for the header
1173 children: [
1174 { name: 'Chris', age: 55, createdAt: '2011-10-11', score: 0.03343 },
1175 { name: 'Dan', age: 40, createdAt: '2011-10-21', score: 0.03343 },
1176 ]
1177}]
1178```
1179
11803. sometimes, you might want a summary row instead of a header row. for example if you want to show total score for your group
1181
1182```javascript
1183rows: [{
1184 name: 'Total', // this is the label that'll be used for the header
1185 age: undefined,
1186 createdAt: undefined,
1187 score: 0.3, // total score here
1188 children: [
1189 { name: 'Chris', age: 55, createdAt: '2011-10-11', score: 0.03343 },
1190 { name: 'Dan', age: 40, createdAt: '2011-10-21', score: 0.03343 },
1191 ]
1192}]
1193```
1194
11954. if you want the header/summary row to show up at the bottom of the group, you can specify that in the groupOptions property of the table.
1196```html
1197<vue-good-table
1198 :columns="columns"
1199 :rows="rows"
1200 :groupOptions="{
1201 enabled: true,
1202 headerPosition: 'bottom',
1203 }">
1204</vue-good-table>
1205```
1206
1207you can check out some live examples on the recipes page:
1208[vue-good-table Recipes](https://github.com/xaksis/vue-good-table/wiki/Vue-good-table-Recipes-(vue-good-table-2.x))
1209
1210
1211### Remote Mode
1212Sometimes you might want to power the table from the backend. Where filtering, paging, sorting etc are done serverside. In order to accomplish that you can follow [The remote mode workflow wiki](https://github.com/xaksis/vue-good-table/wiki/Remote-Mode-Workflow)
1213
1214### Table Actions Slot
1215If you want to add table specific actions like a print button for example, you can use the Table Actions Slot. If you have global search enabled, the action panel will show up to the right of that.
1216
1217```html
1218<vue-good-table
1219 :columns="columns"
1220 :rows="rows">
1221 <div slot="table-actions">
1222 This will show up on the top right of the table.
1223 </div>
1224</vue-good-table>
1225```
1226
1227
1228### Empty state slot
1229You can provide html for empty state slot as well. Example:
1230
1231```html
1232<vue-good-table
1233 :columns="columns"
1234 :rows="rows">
1235 <div slot="emptystate">
1236 This will show up when there are no columns
1237 </div>
1238</vue-good-table>
1239``` -->
1240
1241## Authors
1242
1243* [xaksis](https://github.com/xaksis)
1244* [Other Contributors](https://github.com/xaksis/vue-good-table/graphs/contributors)
1245
1246## License
1247
1248This project is licensed under the MIT License - see the [LICENSE.md](LICENSE) file for details
1249
\No newline at end of file