Component that controls visibility of vuetable2's columns
npm install vuetable2-column-visibilityThe component extends the vuetable2,
placing a dropdown menu that allows the user to show and hide the grid columns.
- Vue.js ^2.0.0
``bash`
$ npm install vuetable2-column-visibility --save
First we need to import and register the vue-events
plugin somewhere in our project. We can do it in every file we use vuetable2App.vue
or simply in out :
`javascript`
import Vue from 'vue'
import VueEvents from 'vue-events'
Vue.use(VueEvents)
Once registered vue-events, we can access the $events prototype object in
our Vue instance. This object is a centralized event hub that we can use
throughout the Vue instance and it provides event related functions.
Now, we must import and register vuetable2-column-visibility:
`javascript`
Notice that we told to the component to listen to the column-visibility:changedonColumnVisibilityChanged
event, and then execute . This is necessary in order tovuetable2
the re-render the columns that were shown or hidden.
Now we can use the component in our HTML:
`html`
:fields="fields">
Where the fields variable stores the grid fields, for example:
`javascript`
fields: [
{
name: 'first_name',
title: 'First name'
},
{
name: 'last_name',
title: 'Last name'
},
{
name: '__slot:id',
title: 'Actions',
showOnVisibilityMenu: false
},
],
We can define a showOnVisibilityMenu property in the column object to controlshowOnVisibilityMenu
whether the column will appear in the visibility menu or not. By default, is set to true. In this case, the first_name andlast_name columns will appear on the menu, while __slot:id` wont.