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

mk-vue3-table

v1.0.23

Published

A simple Nuxt 3 table component

Downloads

2

Readme

MkVueTable

This component allows you to create a dynamically sortable table using Vue.js. The table headers, rows, and optionally action areas can be defined dynamically.

Features

  • Dynamic Sorting: Click on the table headers to sort the rows in ascending or descending order.
  • Custom Icons: You can customize the sorting icons.
  • Action Area: Optionally, add an action area to the far right of each row where you can insert custom content using a template slot.
  • Search Area: Optionally, add search area to each column.
  • Pagination: Easily paginate your data to control the number of rows displayed per page.
  • Conditional Row Coloring: Change the background color of rows based on specific conditions.
  • Custom Column Slots: Add custom content to specific columns using template slots.

Installation

Dependencies

Ensure you have Vue 3 installed to use this component.

Usage

Include the component in your project and use it as shown in the example below:

<template>
  <MyTableComponent
    :headers="headers"
    :rows="rows"
    :sortAscIcon="'sort-asc'"
    :sortDescIcon="'sort-desc'"
    :sortDefaultIcon="'sort-default'"
    :action="true"
    :columnSearch="true"
    :perPage="5"
    :coloredRows="coloredRows"
    :defaultCss="true"
  >
    <template #action="{ row }">
      <button @click="handleAction(row)">Action</button>
    </template>
    
    <template #column-age="{ row, value }">
      <span :style="{ fontWeight: value > 30 ? 'bold' : 'normal' }">{{ value }}</span>
    </template>
    
  </MyTableComponent>
</template>

<script setup lang="ts">
import MyTableComponent from './MyTableComponent.vue';

const headers = [
  { text: 'Name', value: 'name' },
  { text: 'Age', value: 'age' },
  { text: 'Country', value: 'country' }
];

const rows = [
  { name: 'John Doe', age: 30, country: 'USA' },
  { name: 'Jane Smith', age: 25, country: 'Canada' },
  { name: 'Sam Green', age: 35, country: 'UK' }
];

const handleAction = (row) => {
  alert(`Action clicked for ${row.name}`);
};
</script>

Props

headers (Array, Required)

Defines the table headers. Each header should be an object with text (header label) and value (key for table data) properties.

Example:

const headers = [
  { text: 'Name', value: 'name' },
  { text: 'Age', value: 'age' },
  { text: 'Country', value: 'country' }
];

rows (Array, Required)

Defines the table headers. Each header should be an object with text (header label) and value (key for table data) properties.

Example:

const rows = [
    { name: 'John Doe', age: 30, country: 'USA' },
    { name: 'Jane Smith', age: 25, country: 'Canada' },
    { name: 'Sam Green', age: 35, country: 'UK' }
];

headerClass (String, Optional)

Adds a CSS class to the table header row.

headerStyle (Object, Optional)

Applies styles to the table header row.

Example:

const headerStyle = {
    backgroundColor: '#f1f1f1',
    color: '#333'
};

sortAscIcon (String, Required)

CSS class for the ascending sort icon.

Example:

<span class="sort-asc"></span>

sortDescIcon (String, Required)

CSS class for the descending sort icon.

Example:

<span class="sort-desc"></span>

sortDefaultIcon (String, Required)

CSS class for the default sort icon.

Example:

<span class="sort-default"></span>

action (Boolean, Optional)

If true, adds an action area to the far right of each row. Default is false.

columnSearch (Boolean, Optional)

If true, there is a search field under each column.

perPage (Number, Required)

Number of records to show on one page

coloredRows (Array, Optional)

Defines conditions to color the rows based on specific key-value pairs. Each condition is an object with a key, value, and color property.

Example:

const coloredRows = [
    { key: 'age', value: '30', color: 'lightblue' },
    { key: 'country', value: 'Canada', color: 'lightgreen' }
];

defaultCss (Boolean, Optional)

If true, css works. If not the table works without css.

Slots

action

You can define custom content for the action area of each row using a template slot named action.

Example:

<template #action="{ row }">
  <button @click="handleAction(row)">Action</button>
</template>

column-[header.value]

You can define custom content for a specific column using a slot named column-[header.value], where [header.value] is the value of the header.

Example:

<template #column-age="{ row, value }">
  <span :style="{ fontWeight: value > 30 ? 'bold' : 'normal' }">{{ value }}</span>
</template>
Usage Notes:
  • Custom Column Slots: To add custom content to a specific column, use a slot named column-[header.value], replacing [header.value] with the value of the column header. This allows you to insert custom elements or apply custom styling based on the data in that column.

Methods

handleAction

A method to handle actions for a specific row. You can define this method in your component and pass it to the table component.

Example:

const handleAction = (row) => {
    alert(`Action clicked for ${row.name}`);
};