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-datatables-182

v0.0.7

Published

Datatables component for Vue 2.7

Downloads

689

Readme

Vue Datatables 182

Vue Datatables 182 is a component that provides a table with enhanced capabilities. This component supports:

  • Searching
  • Remote data
  • Pagination
  • Customizing with slots

Get started

Install:

npm i vue-datatables-182

In main Vue file:

import { DataTable, DataTableColumn } from 'vue-datatables-182'
import "vue-datatables-182/dist/style.css"

Vue.component('data-table', DataTable)
Vue.component('data-table-column', DataTableColumn)

Or in another Vue component;

<script lang="js">
import { DataTable, DataTableColumn } from 'vue-datatables-182'
import "vue-datatables-182/dist/style.css"

export default {
  name: 'SomeComponent',
  components: { DataTable, DataTableColumn },
  data() {
    return {
      items: [
        { name: 'New-York', order: 1 },
        { name: 'Moscow', order: 2 },
        { name: 'London', order: 3 },
        { name: 'Paris', order: 4 },
        { name: 'Berlin', order: 5 },
      ],
    }
  },
}
</script>

<template>
  <!-- client data source -->
  <data-table
    source="client"
    :items="items"
    numbering
    row-selection
  >
    <data-table-column
      field="name"
      orderable
      searchable
      title="Name"
    />
    <data-table-column
      field="order"
      orderable
      text-align="center"
      title="Order"
      width="200px"
    />
  </data-table>

  <!-- server data source -->
  <data-table
    source="server"
    url="/example-table"
    numbering
    row-selection
  >
    <data-table-column
      field="name"
      orderable
      searchable
      title="Name"
    />
    <data-table-column
      field="order"
      orderable
      text-align="center"
      title="Order"
      width="200px"
    />
  </data-table>
</template>

UI element highlight

DataTable

Props

Table data

source

Source of data for the table. Available values: client and server.

source: {
  type: String,
  default: 'server',
}

url

URL for fetching data when using a server-side data source.

url: {
  type: String,
  default: null,
}

items

Array of items for client-side data.

items: {
  type: Array,
  default: () => [],
}

Pagination

pagination

Enables table pagination.

pagination: {
  type: Boolean,
  default: true,
}

rowsPerPageOptions

Number of rows per page.

rowsPerPageOptions: {
  type: Array,
  default: () => [5, 10, 25, 50, 100],
}

rowsPerPageCount

Number of rows per page. The value must be present in the rowsPerPageOptions array.

rowsPerPageCount: {
  type: Number,
  default: 10,
}

Search

searching

Enables the search functionality.

searching: {
  type: Boolean,
  default: true,
}

Order

orderBy

Column by which the data is ordered.

orderBy: {
  type: String,
  default: null,
}

orderDirection

Direction of ordering (ascending or descending). Available values: asc and desc.

orderDirection: {
  type: String,
  default: 'asc',
}

Fixed Columns

scrollX

Enables horizontal scrolling for the table.

scrollX: {
  type: Boolean,
  default: false,
}

fixedColumnsStart

Number of columns fixed at the start of the table.

fixedColumnsStart: {
  type: Number,
  default: 0,
}

fixedColumnsEnd

Number of columns fixed at the end of the table.

fixedColumnsEnd: {
  type: Number,
  default: 0,
}

Other

rowSelection

Enables row selection functionality.

rowSelection: {
  type: Boolean,
  default: false,
}

actions

Enables actions column.

actions: {
  type: Boolean,
  default: false,
}

numbering

Enables numbering for rows

numbering: {
  type: Boolean,
  default: false,
}

rowsClickable

Enables clickable rows.

rowsClickable: {
  type: Boolean,
  default: false,
}

Events

row-click

Triggered when a row is clicked and the rowsClickable prop is true. The event passed to the handler contains the clicked row data.

Handler

const handleClickRow = (row) => {
  // to do smth.
}

Table

<data-table
  source="client"
  :items="items"
  rows-clickable
  @row-click="handleClickRow"
>

update:selected-rows

Triggered when the selected rows array changes. The event passed to the handler contains the updated selected rows array. The rowSelection prop must be set to true.

Handler

const handleUpdateSelectedRows = (rows) => {
  // to do smth.
}

Table

<data-table
  source="client"
  :items="items"
  row-selection
  @update:selected-rows="handleUpdateSelectedRows"
>

Slots

topLeftBeforeActions

This slot is used to display content on the left side above the table, to the left of the search field.

<template #topLeftBeforeActions>
  <div>Content here</div>
</template>

topLeftAfterActions

This slot is used to display content on the left side above the table, to the right of the search field.

<template #topLeftAfterActions>
  <div>Content here</div>
</template>

topRight

This slot is used to display content on the right side above the table.

<template #topRight>
  <div>Content here</div>
</template>

actions

This slot is used to display content in the action column cells. The slot provides the row's value.

Note: @click.stop is necessary to prevent the row click event.

<template #actions="{ row }">
  <div @click.stop>
    <div>Actions for row #{{ row.number }}:</div>
    <button id="delete" :data-id="row.item.id"></button>
  </div>
</template>

cell

This slot is used to display content in the custom column cells. The slot provides the row's value.

<data-table-column
  field="name"
  orderable
  searchable
  title="Name"
>
  <template #cell="{ row }">
    <div>
      <div>This is row #{{ row.number }}</div>
      <div>Title: {{ row.item.title }}</div>
    </div>
  </template>
</data-table-column>