2.0.1 • Published 3 years ago

@kriptiko/vue-table v2.0.1

Weekly downloads
82
License
MIT
Repository
github
Last release
3 years ago

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

PropTypeDefaultDescription
checkableObject{ display: false, attribute: null }Show/hide checkboxes for bulk operations. See the Checkable API for more info.
columnsArray[]The table columns. See the Columns API for more info.
data-keyString'data'The path to the data in the server's JSON response.
localeStringenSets the locale. Supported values: en, es, fr, pt.
meta-keyStringnullThe path to the pagination meta in the server's JSON response.
paginateBooleantruePaginates the records and enables the pages links.
per-pageNumber20Number of items displayed per page. Supported values: 20, 50, 100.
orderableBooleanfalseWhen set to true, the rows can be reorder by dragging them.
row-classString or Function''The row CSS classes. It can be a String or a callback Function.
sortingArray[]The columns' sorting directions. See the Sorting API for more info.
table-classString'table table-striped'The CSS classes of the table.
uriStringnullData 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

PropertyTypeDefaultDescription
headerClassesStringnullThe CSS classes that will be assigned to the table headers.
nameString""The column's attribute name.
valueString, ArraynullThe column's default value.
slotNameString""The name of the slot to be rendered.
rowClassesString""The CSS classes that will be assigned to the table rows.
searchableBooleanfalseDetermines whether the column is searchable.
sortableBooleanfalseDetermines whether the column is sortable.
titleString""The column's header title.
visibleBooleantrueDetermines whether the column is visible.
render()functionfalseCallback for transforming the column's data.

Sorting API

PropertyTypeDescription
columnStringThe name of the column to be sorted. Must be an existing column.
directionStringThe 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

PropertyTypeDescription
displayBooleanDetermines whether the checkboxes are displayed or not.
attributeStringThe 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.

2.0.1

3 years ago

2.0.0

3 years ago

1.7.1

3 years ago

1.7.0

3 years ago

1.6.1

3 years ago

1.6.0

3 years ago

1.5.1

3 years ago

1.4.2

3 years ago

1.4.1

3 years ago

1.5.0

3 years ago

1.4.0

3 years ago

1.3.0

3 years ago

1.2.0

3 years ago

1.1.13

4 years ago

1.1.12

4 years ago

1.1.11

4 years ago

1.1.10

4 years ago

1.1.9

4 years ago

1.1.8

4 years ago

1.1.7

4 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

1.0.0-beta

4 years ago