0.8.2 • Published 3 years ago

v-datatable-light v0.8.2

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

v-datatable-light

A lightweight, simple and easy data table for Vue.

Build Status GitHub open issues Npm version GitHub

Features

  • Lightweight
  • Provide a Pagination component
  • Provide a Items-per-page component
  • No dependencies
  • Event driven (all the events will be emitted to you, and you will decide how to react to them)
  • Css flexible (is possible to add classes to almost all elements generated)
  • Order by events
  • Fix header possibility
  • Custom columns
  • Custom headers
  • Row selection

Demos

CodePen using almost all features CodeSandbox using almost all features CodeSandbox 2

Install

Using npm

npm install v-datatable-light --save

Usage

<DataTable
  :header-fields="headerFields"
  :data="data"
/>
import { DataTable } from 'v-datatable-light'

export default {
  components: {
    DataTable
  }
}

DataTable Props

FieldTypeRequireddefaultDescription
headerFieldsarraytruenullDefinition of each column of the table. In each item of this array you will define how this column will behave.
dataarraytruenullArray of objects that will feed the datatable.
isLoadingbooleanfalsefalseFlag to indicate to datatable if the data is loading. If it is, your spinner slot will be show.
sortFieldstringfalsenullTo indicate by which field the datatable is sorted for.
sortstringfalsenullTo indicate by which direction the databale is sorted for ('asc' or 'desc').
notFoundMsgstringfalsenullMessage to by show when no data was found.
trackBystringfalse'id'An unique id column used for checkbox column type to compare if a field is checked or not.
cssobjectfalseStructureAn object with attributes used to add css classes to DataTable internal elements.
tableHeightstringfalsenullUsed to have fixed header in the table.
defaultColumnWidthstringfalse'150px'Set the default column with, only used when 'tableHeight' prop is informed.
onlyShowOrderedArrowbooleanfalsefalseWhen is true will only show the sorted column's current direction arrow.

DataTable Events

Event NameDescriptionParams
on-updateCalled every time the the DataTable is sortedObject with sortField and sort attributes. Where sortField is the column name and sort is the direction (eg asc, desc)
on-check-allCalled when the checkbox on the DataTable header is checked or uncheckedIf the checkbox is checked it send the DataTable data list, if it is not, an empty array
on-checked-itemCalled when a checkbox row is checkedObject with the row's data
on-unchecked-itemCalled when a checkbox row is uncheckedObject with the row's data

DataTable Header Fields Props

NameTypeRequiredDefaultDescription
namestringtruenullAttribute that the DataTable will try to retrieve the value from the data item.
labelstringtruenullAttribute that the DataTable will show on the header for the column.
sortablebooleanfalsefalseDefine if that column will be sortable or not. In case the value is true, two arrows will be show on the header.
customElementboolean or stringfalsenullIf sent a true the DataTable will render a slot with the same name attribute. To customise the slot name, send an string with the whised name
customHeaderboolean or stringfalsenullIf sent a true the DataTable will render a slot with the same name attribute plus :header, example: name:header. To customise the slot name, send an string with the whised name, without need plus :header.
formatfunctionfalsenullA function used to format a value in each line of the DataTable's body.
widthstringfalsenullString used to define column width. Only used when 'tableHeight' props is informed.
__slot:actionsstringfalsenullUsed to create a new column to be used for buttons or any kind of action. You have to inform the slot 'actions' and it will be rendered inside each line. In case you want to use more than one action in the same table, you can inform different IDs for each one, and this ID will be used as the slot ID. The format would be: __slot:actions:myActionID, in this case myActionID is the slot ID
__slot:checkboxesstringfalsenullUsed to create a column with a checkbox. Every time you check or uncheck an item an event is emited.

DataTable Css Props Structure

NameTypeRequiredDefaultDescription
tablestringfalse''Applied on the table element.
theadstringfalse''Applied on the table thead element.
theadTrstringfalse''Applied on the table thead tr elements.
theadThstringfalse''Applied on the table thead th elements.
tbodystringfalse''Applied on the table tbody element.
tbodyTrstringfalse''Applied on the table tbody tr elements.
tbodyTdstringfalse''Applied on the table tbody td elements.
tbodyTrSpinnerstringfalse''Applied on the table tbody tr element when the spinner is displayed.
tbodyTdSpinnerstringfalse''Applied on the table tbody td element when the spinner is displayed.
tfootstringfalse''Applied on the table tfoot element.
tfootTrstringfalse''Applied on the table tfoot tr element.
tfootTdstringfalse''Applied on the table tfoot td element.
footerstringfalse''Applied on the table tfoot div element wrapping the slots.
thWrapperstringfalse''Applied on div inside the table thead th element wrapping the column header content.
thWrapperCheckboxesstringfalse''Applied on div inside the table thead th element wrapping the column header content when it is a checkbox.
arrowsWrapperstringfalse''Applied on div inside the table thead th element wrapping the arrows.
arrowUpstringfalse''Applied on div inside the table thead th element where the arrow up is draw.
arrowDownstringfalse''Applied on div inside the table thead th element where the arrow down is draw.
checkboxHeaderstringfalse''Applied on the table thead checkbox element.
checkboxstringfalse''Applied on the table tbody checkbox elements.
notFoundTrstringfalse''Applied on the table tbody tr element when the data is empty.
notFoundTdstringfalse''Applied on the table tbody td element when the data is empty.

Pagination Props

NameTypeRequiredDefaultDescription
totalItemsnumbertruenullTotal of items in your storage.
itemsPerPagenumberfalse10Number of items displayed per page.
pagenumberfalse1Current page index.
moveLastPagebooleanfalsetrueFlag to show or not the button to move to the last page.
moveFirstPagebooleanfalsetrueFlag to show or not the button to move to the first page.
moveNextPagebooleanfalsetrueFlag to show or not the button to move to the next page.
movePreviousPagebooleanfalsetrueFlag to show or not the button to move to the previous page.

Pagination Events

Event NameDescriptionParams
on-updateCalled every time the user click to change page.Next page number
update-current-pageCalled every time the Pagination component change the current page. It is normally called when user increase the number of items to be shown per page and the current page does not exist anymore. In this case, the Pagination component will emit this event to let the user know which is the new current page.Next page number

ItemsPerPageDropdown Props

NameTypeRequiredDefaultDescription
listItemsPerPagearrayfalse10, 20, 30An array of numbers which the user will have the posibily to change how many items are displayed in the DataTable.
itemsPerPagenumberfalse10Current value of how many items are displayed on the DataTable.

ItemsPerPageDropdown Events

Event NameDescriptionParams
on-updateCalled every time the user change the number of items per pageNext items per page number

Installation

npm install v-datatable-light

Project setup

npm install

Compiles and hot-reloads for development

npm run serve

Compiles and minifies for production

npm run build

Run your tests

npm run test

Lints and fixes files

npm run lint

Customize configuration

See Configuration Reference.

0.8.2

3 years ago

0.8.1

4 years ago

0.8.0

5 years ago

0.7.0

5 years ago

0.6.0

5 years ago

0.5.0

5 years ago

0.4.0

5 years ago

0.3.0

5 years ago

0.2.0

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago