npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vuetable2-column-visibility

v1.0.1

Published

Component that controls visibility of vuetable2's columns

Downloads

28

Readme

The component extends the vuetable2, placing a dropdown menu that allows the user to show and hide the grid columns.

Requirements

Installation

$ npm install vuetable2-column-visibility --save

Usage

First we need to import and register the vue-events plugin somewhere in our project. We can do it in every file we use vuetable2 or simply in out App.vue:

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:

<script>
import vuetable from 'vuetable-2/src/components/Vuetable'
import columnVisibility from 'vuetable2-column-visibility'

export default {
  name: "data-table",
  components: { vuetable, columnVisibility },
  methods: {
      onColumnVisibilityChanged () {
          this.$refs.vuetable.normalizeFields()
      },  
  },
  mounted() {
    this.$events.$on('column-visibility:changed', e => this.onColumnVisibilityChanged(e))
  },
}
</script>

Notice that we told to the component to listen to the column-visibility:changed event, and then execute onColumnVisibilityChanged. This is necessary in order to the vuetable2 re-render the columns that were shown or hidden.

Now we can use the component in our HTML:

<column-visibility :fields.sync="fields"></column-visibility>
<vuetable ref="vuetable"
    api-url="http://localhost:8000/path"
    :fields="fields">
</vuetable>

Where the fields variable stores the grid fields, for example:

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 control whether the column will appear in the visibility menu or not. By default, showOnVisibilityMenu is set to true. In this case, the first_name and last_name columns will appear on the menu, while __slot:id wont.

License

The MIT License