2.3.2 • Published 6 months ago

@tvaliasek/vue-datatable v2.3.2

Weekly downloads
71
License
MIT
Repository
-
Last release
6 months ago

Simple Bootstrap 5 and Vue 3 data table

Very naive and simple data table for Bootstrap 5 and Vue 3. For Vue 2 use version 1.x., now without the dependency on bootstrap-vue-next.

Install

npm install @tvaliasek/vue-datatable

# peer dependencies
npm install bootstrap
import { createApp } from 'vue'
import { DataTablePlugin } from '@tvaliasek/vue-datatable'

import 'bootstrap/dist/css/bootstrap.css'
import '@tvaliasek/vue-datatable/dist/data-table.css'

const app = createApp(App)
app.use(DataTablePlugin)

app.mount('#app')

Usage

Define columns (header prop) and provide dataset as array of objects. See the example on ./src/App.vue

DataTable component props

propertytyperequireddefaultusage
langStringnoundefined / 'en_US'ISO language code of translation, as defined in src/Langs
i18nObjectno{}Override for language strings, object { key: string }
autoUpdateBooleannofalseToggle auto update feature
loadingBooleannofalseToggle loading state
headerArrayyesundefinedDefinition of columns (described below)
dataArrayno[]Array of row data objects
actionsBooleannotrueToggle display of actions column
buttonsArrayno[]Definition of available row actions/buttons
disableButtonsBooleannofalseToggle disabled state of all actions/buttons
pagingBooleannofalseToggle pagination
pagingOptionsArrayno 15, 30, 60, 100 Rows per page variants
responsiveBoolean or stringnonullresponsive css class suffix
actionsOnLeftBooleannofalseset to true for render actions cell in first column
selectableRowsBooleannofalseSet to true to enable selectability of table rows. Do not forget to set v-model and "selectableRowsTrackBy" property.
selectableRowsCheckboxesBooleannofalseSet to true to perform selection of rows trough checkboxes displayed in first cell of rows. Please note that using this feature automatically disable selection of rows trough clicking on any data cell.
selectableRowsTrackByStringnoidUnique data property of flattened row which should be used as tracking id for row selection.
selectableRowsClassStringnovue-datatable-selected-rowCSS class added to selected rows (on TR tag).
exportableBooleannofalseShow export button
stateSavingBooleannofalseEnable internal state saving feature. State is saved in sessionStorage under specified key
stateSavingUniqueKeyStringnovueDataTablea unique key under which the internal state will be stored
tableUniqueKeyStringnogenerated from _uidcustom unique key for table
remoteDataModeBooleannofalseset to true to enable remote data mode
remoteDataTotalRowsNumberno0required for pagination to work when remote data mode is enabled, total number of rows in remote dataset
rowClassString, Functionnoundefinedcss class to apply on all rows, or callback (row: Record<string, any) => string or null

DataTable column definition

Columns are defined as Array of objects

propertytyperequireddefaultusage
textStringyesundefinedText displayed as caption of column
dataStringyesundefinedName of property in row data object, for nested objects it should be in dot notation ex: 'person.name'
sortableBooleannofalseToggles sorting on column, data is by default sorted naturally
filterableBooleannofalseToggles filtering on column
formatFunctionnoundefinedCustom cell data format function. (value, row) => value
sortFnFunctionnoundefinedCustom sort function sort(a, b)
filterFnFunctionnoundefinedCustom filter function filter(cellValue, filterValue, rowData)
customComponentFunctionnoundefinedFunction which returns custom component instance or name, component will receive whole data row in prop named row and data key from header definition in prop named dataIndex
cellStyleStringnoundefinedCSS style rules to apply on column data cells
cellClassnamesArrayno[]Array of css class names to apply on column data cells
aggregateFunctionnoundefinedArray reducer function for aggregation of filtered and flattened data. Whole flattened row is obtained as reducer currentValue. See Array.reduce
aggregateInitialValueAnynoundefinedValue to use as aggregation (reducer) initial value.
aggregateTextStringnoundefinedText to place before aggregation result.
clickToSelectBooleannotrueSet to false to disable click to select row function for this column

DataTable actions definition

Actions are defined as Array of objects, each action generates button and emits two events, common action event and event named as is defined in definition

propertytyperequireddefaultusage
textStringyesundefinedText displayed as caption of button
eventStringnoundefinedName of emitted event
variantStringnoundefinedBootstrap variant of button ex: 'primary', 'danger'
confirmBooleannofalseEnable confirmation when button is clicked
confirmTextStringnoundefinedText to show on confirmation prompt
customComponentFunctionnoundefinedFunction which returns custom component instance or name, component will receive whole data row in prop named row
visibleIfFunctionnoundefinedFunction which returns boolean to indicate if button should be visible, function will receive whole data row as first parameter
customTextComponentString or functionnoundefinedCustom component for default slot of button, can be combined with text
customTextComponentPropsRecord<string, any>noundefinedObject with props which will be passed to customTextComponent
hrefStringnoundefinedpass string if the button should be a common link
hrefCallbackFunctionnosame as for href, but you can provide a factory function for link, function will receive whole processed row as a first parameter

Events

eventdatausage
refreshundefinedEmitted on update tick when auto update feature is enabled
action{ event: nameOfEvent, row: object }Emitted on click to any action button
as defined in action{ ...row }Emitted on click to any action button
export{ cellDataProperty: cellContent }Emitted on click to export button
remote-data-refresh{ filter: {key: filterQuery}[], sortBy: string, sortDirection: string, currentPage: number, currentPageLimit: number }Emitted on any display settings change during remote data mode, automatically debounced

Run demo

# clone repo using your favourite git client
gh repo clone tvaliasek/vue-datatable ./vue-datatable
cd vue-datatable
npm install
npm run dev
2.3.2

6 months ago

2.3.0

6 months ago

2.3.1

6 months ago

2.2.2

8 months ago

2.2.1

2 years ago

2.2.0

2 years ago

2.1.2

2 years ago

2.1.1

2 years ago

2.1.4

2 years ago

2.1.3

2 years ago

2.1.5

2 years ago

2.1.0

2 years ago

2.0.3

2 years ago

2.0.2

2 years ago

2.0.1

2 years ago

2.0.0

3 years ago

1.2.7

3 years ago

1.2.6

3 years ago

1.2.5

3 years ago

1.2.4

3 years ago

1.2.3

3 years ago

1.2.0

3 years ago

1.2.1

3 years ago

1.1.16

3 years ago

1.1.15

3 years ago

1.1.12

3 years ago

1.1.11

3 years ago

1.1.14

3 years ago

1.1.13

3 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.0

5 years ago

0.1.0

5 years ago