0.3.2 • Published 2 years ago
vue2-sticky-table v0.3.2
vue2-sticky-table
Vue's table component with vertical and horizontal scrolling, horizontal resizing, and sticky functions.
Features
This library does not implement sorting, pagination, or other item manipulation features, but focuses on table basic features.
- Fixing the table header
- Fixing the table footer
- Fixing of any column
- Resizing of any column
- Horizontal and vertical scrolling
Installation
yarn add vue-sticky-table
Usage
Options
Option | Type | Description | Default |
---|---|---|---|
width | Number | The width of the table. If you specify 0, 100% will be set, so if you want to fit the parent element, set 0. | 0 |
height | Number | The height of the table. If you specify 0, 100% will be set, so if you want to fit the parent element, set 0. | 0 |
fps | Number | The frame per second of the resizing process. | 30 |
defaultColumnWidth | Number | The width of the column to be set if no width is specified. | 200 |
columnOptions | Array | An array of options for each column. It is not required to set them for all columns. | [] |
columnOptions[].nth | Number (required) | The column number. | |
columnOptions[].width | Number | The width of the column. | |
columnOptions[].fixed | Boolean | If true, the column will be set to a sticky column. | false |
columnOptions[].resizable | Boolean | If true, the column will be set to a resizable column. | false |
Example
import VueStickyTable from 'vue-sticky-table';
export default {
name: 'App',
components: {
VueStickyTable,
},
data() {
return {
options: [
// First column options.
{
nth: 1,
fixed: true,
resizable: true,
width: 120,
},
// Third column options.
{
nth: 3,
resizable: true,
},
],
// [{guid,name,phone,email,date,address}...]
items: []
};
},
methods: {
resize(value) {
// You can receive the width and offset values of
// all header columns in the resize event.
console.debug(value);
},
},
};
<vue-sticky-table
:fps="45" :width="600" :height="400"
:column-options="options" :default-column-width="150"
@resize="resize">
<template #thead>
<tr>
<th>Guid</th>
<th>Name</th>
<th>Phone</th>
<th>Email</th>
<th>Date of Birth</th>
<th>Address</th>
</tr>
</template>
<template #tbody>
<tr v-for="item in items"
:key="item.guid">
<td>{{ item.guid }}</td>
<td>{{ item.name }}</td>
<td>{{ item.phone }}</td>
<td>{{ item.email }}</td>
<td>{{ item.date }}</td>
<td>{{ item.address }}</td>
</tr>
</template>
<template #tfoot>
<tr>
<th>Guid</th>
<th>Name</th>
<th>Phone</th>
<th>Email</th>
<th>Date of Birth</th>
<th>Address</th>
</tr>
</template>
</vue-sticky-table>
License
0.3.2
2 years ago