Giter Site home page Giter Site logo

my-awesome-nuxt-table's Introduction

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.
  • No Results Message: Customize the message shown when no search results are found using a template slot.

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>

undefined-result

You can define custom content to be displayed when no search results are found using a slot named undefined-result.

Example:

<template #undefined-result>
  <div>No results found</div>
</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}`);
};

my-awesome-nuxt-table's People

Contributors

muratkiziloz avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.