0.1.0 • Published 3 years ago

vjs-datatable v0.1.0

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

vjs-datatable

Datatable component for Vue 2.x

Features

  • Provides a simple to advanced tabular data
  • Supports dot notation in field props
  • Sorting
    • Typed sorting
    • Has no-sort sorting direction/order
    • Initial sorting
    • Reverse sorting
  • Pagination
    • Per page options
    • Setting initial per page
    • Setting initial page
    • Goto page input
    • Page details
  • Search
  • Row select
  • Row detail
  • Default and Customizable Style

Install

npm install vjs-datatable --save

Import

Global

import Vue from "vue";
import App from "./App.vue";
import DataTable from "vjs-datatable";

Vue.use(DataTable);

new Vue({
  render: (h) => h(App),
}).$mount("#app");

Component

<script>
import DataTable from "vjs-datatable";

export default {
  components: {
    DataTable
  }
};
</script>

CDN

<!-- peer dependency -->
<script src="https://cdn.jsdelivr.net/npm/vue@^2.6.11/dist/vue.min.js"></script>
<!-- vjs-datatable -->
<script src="https://cdn.jsdelivr.net/npm/vjs-datatable@0.1.0/dist/vjs-datatable.umd.min.js"></script>

<script>
  new Vue({
    el: "#app",
    components: {
      DataTable: window["vjs-datatable"]
    }
  });
</script>

Usage

SFC

<template>
  <DataTable :data="rows" :columns="columns" />
</template>

DOM

<body>
  <data-table :data="rows" :columns="columns"></data-table>
</body>

Props

NameTypeDefaultDescription
dataArrayShould array of objects accepts non-uniform data structure as long as defined field(s) is/are present.
columnsArrayArray of objects describing a column
columns[].fieldStringPath to an obj key and slot name for providing alternative content
columns[].labelStringfield valueHeader name Note: If field is in dot notation then the default value is the root level
columns[].sortableBooleanfalseAllow a column to be sorted
columns[].typeString(string|number|date)stringSpecify data type to be sorted
columns[].searchableBooleanfalseMake a column searchable Note: Searchable columns are all affected by search filter Note: Search will filter the original data, disregard the transformation made by slot content
columns[].formatFunctionA function that modifies a data in a specific column Note: Formatted data affects the sort and search filter Crit: Be careful of changing the data type if you're going to use a sort feature. If you have a column with type option defined to number and suddenly formats a data to any valid type, then sort might not work
initialSortObjectObject specifying the field and order of column to be sorted initially
initialSort.fieldStringA sortable column field that going to initially sorted Note: Specifying the field that didn't set sortable key to true, will not work.
initialSort.dirStringA sorting direction Note: Even though you didn't specify or skip or emptied or supply invalid value on either fields, it will not throw an error, but initial sorting will not work.
reverseSortBooleanfalseReverse the sort direction, desc to asc
allowNoSortBooleanfalseBoolean specifies the none sort order Info: None sort order returns the original order of data
rowSelectBooleanfalseAllows the rows to be selected via checkbox
rowDetailBooleanfalseSpecifying the ability to provide additional content(accordion) by means of slot(v-slot:row-detail="{row}")
dtClassesObjectAn object specifying a class names to be customized
mergeDefaultBooleantrueA boolean that determines whether to merge a default class if classes(dtClasses, pagClasses) prop is partially supplied or not
noRecordMessageStringNo records to showA message to be display if rows are empty
paginationObjectObject specifying the initial page, per page options and per page value
pagination.initialPageNumber1Page number on which the data will start
pagination.perPageOptionsArray10, 25, 50Array of per page
pagination.perPageNumber10Number of row per page
pagination.pageGotoBooleanfalseSpecify whether to show/hide pageGoto feature
pagination.pagClassesObjectAn object specifying a class names to be customized

Events

NameDataDescription
on-searchsearchKey, rowCountFires when a search input value change
on-sortfield, dirFires when a sortable header toggle
on-selectrow, isSelectedFires when row checkbox value change
on-select-allrowsFires when select all row checkbox value change
on-row-detail-changerow, isRowDetailOpenFires when row toggle button click
on-page-changepageNumberFires when page change
on-page-option-changeperPageFires when per page dropdown change

Slots

NameSlot PropsDescription
field.nameOfFieldrowAn alternative content for each cell on a particular column Can be use to provide actions
row-detailrowAn accordion content for every row Note: Can only be use if rowDetail option is set to true

Project setup

npm install

Compiles and hot-reloads for development

npm run serve

Compiles and minifies for production

npm run build

Lints and fixes files

npm run lint

Customize configuration

See Configuration Reference.