Git Product home page Git Product logo

vue-table's Introduction

Vue Table

Vue table component for rendering server-side data.

npm npm npm vue2

Main features

  • Server-side data
  • Searchable columns
  • Sortable columns
  • Filterable columns
  • Drag and drop for reordering the tables' rows
  • Store modules
  • Persist the state to local storage

Installation

# NPM
npm install @kriptiko/vue-table

# Yarn
yarn add @kriptiko/vue-table

Usage

import Vue from 'vue'
import VueTable from '@kriptiko/vue-table'

Props

Prop Type Default Description
checkable Object { display: false, attribute: null } Show/hide checkboxes for bulk operations. See the Checkable API for more info.
columns Array [] The table columns. See the Columns API for more info.
data-key String 'data' The path to the data in the server's JSON response.
locale String en Sets the locale. Supported values: en, es, fr, pt.
meta-key String null The path to the pagination meta in the server's JSON response.
paginate Boolean true Paginates the records and enables the pages links.
per-page Number 20 Number of items displayed per page. Supported values: 20, 50, 100.
orderable Boolean false When set to true, the rows can be reorder by dragging them.
row-class String or Function '' The row CSS classes. It can be a String or a callback Function.
sorting Array [] The columns' sorting directions. See the Sorting API for more info.
table-class String 'table table-striped' The CSS classes of the table.
uri String null Data source URI

Slots

Table header

For injecting HTML before the table, you can use the header slot. See the following example:

<vue-table v-bind="options" :items.sync="items" ref="vueTable">
        <template v-slot:header>
            <div class="mb-4 text-right">
                <button class="btn btn-outline-secondary btn-sm mr-1" @click="importItems()">
                    <i class="fas fa-file-import mr-1"></i> Import
                </button>

                <button class="btn btn-outline-secondary btn-sm" @click="exportItems($refs.vueTable.selectedItems)">
                    <i class="fas fa-file-export mr-1"></i> Export
                </button>
            </div>
        </template>

...

Reset button

For replacing the search button with your custom one, you can use the reset-button. See the next example:

<template v-slot:reset-button="slotProps">
    <button type="button" class="btn btn-primary" @click="slotProps.resetFilters">
        <i class="fas fa-sync-alt"></i>
    </button>
</template>

Columns API

Property Type Default Description
headerClasses String null The CSS classes that will be assigned to the table headers.
name String "" The column's attribute name.
value String, Array null The column's default value.
slotName String "" The name of the slot to be rendered.
rowClasses String "" The CSS classes that will be assigned to the table rows.
searchable Boolean false Determines whether the column is searchable.
sortable Boolean false Determines whether the column is sortable.
title String "" The column's header title.
visible Boolean true Determines whether the column is visible.
render() function false Callback for transforming the column's data.

Sorting API

Property Type Description
column String The name of the column to be sorted. Must be an existing column.
direction String The sorting direction. Allowed values: 'asc' or 'desc'.

You can set a default sorting for your table's columns by passing a prop containing an array of objects with the names of the columns and respective sorting directions. Here's an example:

sorting: [
    {
        column: "name",
        direction: "asc"
    },
    {
        column: "created_at",
        direction: "desc"
    }
],

Request payload

Whenever you sort a column, the current sorting information will be attached to the request. For the previous example, this is how the payload will look like:

sorting[0][column]: name
sorting[0][direction]: asc
sorting[1][column]: name
sorting[1][direction]: created_at

Checkable API

Property Type Description
display Boolean Determines whether the checkboxes are displayed or not.
attribute String The item's attribute to be stored on the selectedItems array

Example

checkable: {
    display: true,
    attribute: "id"
},

Filters

Filters slot

You can make use of the filters slot for placing your selectors inline with the search bar.

You can even use v-model to trigger requests and to sync the local storage.

See this example:

<vue-table>
    <template v-slot:filters="slotProps">
        <div class="col-md-3">
            <select class="form-control" v-model="slotProps.filters.city_id">
                <option>Cities</option>
                <option value="1">Abbottton</option>
                <option value="2">Camrenland</option>
                <option value="3">Delfinamouth</option>
                <option value="4">East Benborough</option>
                <option value="5">Feeneymouth</option>
                <option value="6">Sipesburgh</option>
            </select>
        </div>
    </template>
</vue-table>

License

kriptiko/vue-table is open-sourced software licensed under the MIT license.

About Kriptiko

Kriptiko is a Creative Studio specialized in web development based in Matosinhos, Portugal.

vue-table's People

Contributors

dependabot[bot] avatar jfrosorio avatar

Stargazers

 avatar

Watchers

 avatar  avatar

vue-table's Issues

Columns API: visible option

Is your feature request related to a problem? Please describe.
Make the columns visibility optional.

Describe the solution you'd like
Add a visible prop to the columns API.

Pagination not synced with filters

Describe the bug
Pagination is not in sync with the columns filters.

To Reproduce
Steps to reproduce the behavior:

  1. Go to page 2
  2. Filter by city
  3. See page with no results. This is wrong!

Expected behavior
When a filter option is selected, the page number should be reset to 1.

Pagination wrong offset

Describe the bug
Pagination is displaying the wrong page offset (or lower limit).

To Reproduce
This can be seen on any page. Take page 1, for example. It displays:

0 to x from n

It should display:

1 to x from n

Generate local storage unique keys

Is your feature request related to a problem? Please describe.
At the present moment, the component already stores the filters' module in the local storage. The problem is that the key "filters" is too generic and it might conflict with other components.

Describe the solution you'd like
Generate a UUID for the local storage key.

Catch server errors

Is your feature request related to a problem? Please describe.
At this moment, server errors are not being handled.

Add .catch() to axios requests.

Save store state

Is your feature request related to a problem? Please describe.
The component should keep its state between page visits.

Describe the solution you'd like
Save the state in local storage.

Records per page selector

Is your feature request related to a problem? Please describe.
It should be able to select the number of records per page.

Describe the solution you'd like
Add a selector to the table header section that allows the user to change the number of records per page.

Debounce search

Is your feature request related to a problem? Please describe.
Searching is an expensive operation, so it must be debounced.

Checkboxes for bulk operations

Is your feature request related to a problem? Please describe.
As a user, I must be able to select items and use the selected values.

Describe the solution you'd like
Add an option to display checkboxes that users can select to perform bulk operations.

Before table slot

Is your feature request related to a problem? Please describe.
It would be useful to inject content before the table, for example, import/export buttons.

Describe the solution you'd like
Create a new slot for this purpose.

Forget filter state

Describe the bug
After removing a filter, its state persists in the local storage.

To Reproduce
Steps to reproduce the behavior:

  1. Add a filter to the component
  2. Select a value for it gets stored
  3. Remove the filter
  4. The results are still being filtered

Expected behavior
After removing a filter, its state should be forgotten.

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.