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

vue-listable

v0.0.7

Published

An advanced data table plugin for vue.js and nuxt.js

Downloads

13

Readme

vue-listable

Getting started

Vue-listable is an advanced data table plugin for vue.js.

Installation

Using NPM:

npm install vue-listable --save

Basic usage

Vue.js

import Vue from 'vue'
import VueListable from 'vue-listable'

Vue.use(VueListable)

Same for nuxt.js:

Nuxt.js

Create vue-listable.js in plugins directory:

import Vue from 'vue'
import VueListable from 'vue-listable'

Vue.use(VueListable)

Then in nuxt.config.js:

module.exports = {
  plugins: [
    {
      src: '~/plugins/vue-listable.js'
    }
  ]
}

Component

Inside template use listable component:

<listable />

Options

@search

Type: Function

Default: none

Executes when user is typing in any search input.

<listable @search="onSearch" />
<script>
export default {
  methods: {
    onSearch(searched) {
      console.log(searched);
    }
  }
}
</script>

@checked

Type: Function

Default: none

Executes after checkbox is checked.

<listable @checked="onCheck" />
<script>
export default {
  methods: {
    onCheck(checked) {
      console.log(checked);
    }
  }
}
</script>

@sorted

Type: Function

Default: none

Executes after column sort. Each column except clicked one is reset to default sort direction.

<listable :headings="headings" @sorted="onSort" />
<script>
export default {
  data: () => ({
    headings: [
      {
        display: "ID",
        column: "id",
        sortable: true,
        ascending: true
      },
      {
        display: "Name",
        column: "name"
      },
      {
        display: "Date",
        column: "created_at",
        sortable: true,
        ascending: false
      }
    ]
  }),
  methods: {
    onSort(sort) {
      let column = sort.column;
      let descending = sort.descending;
      let ascending = !descending;
      console.log(column);
      console.log(descending);
      console.log(ascending);
    }
  }
}
</script>

@expanded

Type: Function

Default: none

Executes after row expand.

<listable @expanded="onExpanded" />
<script>
export default {
  methods: {
    onExpanded(expanded) {
      console.log(expanded);
    }
  }
}
</script>

headings

Type: Array

Default: empty array

Array with all table headers cells.

cells: [
  {
    name: "ID",
    column: "id",
    search: false
  },
  {
    name: "Name",
    column: "name",
    search: true
  }
]

Options inside headings

name

Type: String

Default: empty string

Displayed name.

column

Type: String

Default: null

Column name inside "data" attribute.

search

Type: Boolean

Default: false

Experimental function. Shows search input in header.

sortable

Type: Boolean

Default: false

Allows user to click on header column. It emits event with information about clicked column and direction (ascending or not).

ascending

Type: Boolean

Default: true

Available when column is set to sortable. True means that sort is ascending, false means that sort is descending.

data

Type: Array

Default: empty array

Array with all table body data.

data: [
  {
    id: 1,
    name: "MacOS"
  },
  {
    id: 2,
    name: "Linux"
  },
  {
    id: 3,
    name: "Windows"
  }
]

checkbox

Type: Boolean

Default: false

If set to true, first column will contain checkbox.

<listable :checkbox="true" />

expandable

Type: Boolean

Default: false

If set to true, row may be expanded with expander slot.

<listable :expandable="true">
  <div slot="expander" slot-scope="item">
    {{ item }}
  </div>
</listable>

responsive

Type: Boolean

Default: true

If set to true, listable will handle table responsiveness.

<listable :responsive="true" />

Hooks

Hooks are handlers for each table row and each table cell. With hook it is possible to manipulate classes and styles of rows and cells in vue way.

Simple hook is to handle table cells, and rowHook is to handle table rows.

First argument of handler is always object with classes and styles applied to handled element.

Second argument is always row of currently operated data.

Third argument in simple hook is column name.

Why not refs? Refs causes update, so update for each row is slower than using handlers.

<template>
  <div>
    <listable
      :headings="headings"
      :data="items"
      :hook="onHook"
      :rowHook="onRowHook"
    />
  </div>
</template>
<script>
export default {
  data: () => ({
    headings: [
      {
        display: "ID",
        column: "id",
      },
      {
        display: "Name",
        column: "name",
        search: true
      },
      {
        display: "Paid",
        column: "is_paid"
      },
      {
        display: "New",
        column: "is_new"
      }
    ],
    items: [
      {
        id: 1,
        name: "Shoes"
        is_paid: true,
        is_new: false
      },
      {
        id: 2,
        name: "Apple"
        is_paid: false,
        is_new: true
      }
    ]
  }),
  methods: {
    onHook(calculated, row, column) {
      console.info(row);
      if (column == "id") {
        calculated.style.backgroundColor = 'rgb(225, 225, 225)';
      }
      if (column == "is_new") {
        // if row.is_new is true a class new is added
        // if row.is_new is false a class new is not added
        calculated.class['new'] = row.is_new;
      }
    },
    onRowHook(calculated, row) {
      console.info(row);
      // if row.paid is true a class paid is added
      // if row.paid is false a class paid is not added
      calculated.class['paid'] = row.is_paid;
    }
  }
}
</script>

Handle empty rows

<listable>
  <template slot="empty">
    No data
  </template>
</listable>

License

vue-listable uses the MIT License (MIT). Please see the license file for more information.