nx-table v0.2.22
Datatable
Vue verson of datatable
Features
- Render a table
- Select row
- Reoreder row
- Order column
Notes
- https://datatables.net/reference/index
- https://medium.com/justfrontendthings/how-to-create-and-publish-your-own-vuejs-component-library-on-npm-using-vue-cli-28e60943eed3
- https://cli.vuejs.org/guide/cli-service.html#vue-cli-service-build
Installation
For vue, use the nx-table plugin from nx-table.
import NxTable from 'nx-table';
Vue.use(NxTable);
For css, import the datatable default css and nx-table css.
@import "~datatables.net-dt/css/jquery.dataTables.min.css";
@import "~datatables.net-select-dt/css/select.dataTables.min.css";
@import "~datatables.net-responsive-dt/css/responsive.dataTables.min.css";
@import "~datatables.net-rowreorder-dt/css/rowReorder.dataTables.min.css";
@import "~nx-table/dist/nx-table.css";
Usage
<template>
<div class="example-table">
<nx-table :rows="rows" :stripe-classes="['odd', 'even']">
<nx-table-column title="Name" data="name" />
<nx-table-column title="Salary" data="salary" />
<nx-table-column title="Age" data="age" width="20px" />
<nx-table-column title="Action" defaultContent="">
<button>test</button>
</nx-table-column>
</nx-table>
</div>
</template>
<script>
export default {
name: "ExampleTable",
data() {
return {
rows: [],
};
},
created() {
this.rows = [
{
name: "John",
salary: 1000,
age: 10,
},
{
name: "Peter",
salary: 2000,
age: 20,
},
];
},
};
</script>
nx-table
Props
rows {Array}
Define the rows data to show.
serverSide {Boolean}
Set to true, to disable datatable internal sorting. It is useful when you need to do server side sorting.
processing {Boolean}
Show loading indicator.
select {Boolean, String, Object}
Select configuration object.
selected {Array}
Select certain rows. The array's element is any row data. Use together with
sync
modifier to get back the selected rows.<v-datatable :rows="rows" :select="{ style: 'os' }" :selected.sync="selected" />
rowReorder {Boolean, Object}
Enable row reorder. You may also need to listen for row reorder event.
See Datatable rowReorder option
Related: RowReorder listener
stripeClasses {Array}
Set the zebra stripe class names for the rows in the table. Default value is no stripe class. To enable it just like the official style, set its value to
['odd', 'even']
.order {Array}
Order the table.
Listeners
rowReorder
Rows have been reordered by the end user.
New properties
reorderedRow {Array}
: the reordered rows.
order
Define the event listener for order.
New properties
ordCols {Array}
: the ordered columnsordStr {String}
: the ordered columns in query string format
nx-table-column
Define the table column. Should be the direct child of the nx-table component.
Noted that not all datatable props are supported.
See Datatable column
Props
title {String}
Define the column's title.
data {String}
Define the column's data. Make sure either
data
ordefaultContent
is defined.width {String}
Define the column's width. It takes any CSS value.
defaultContent {String}
Define the default content of the cell if data is undefined. Make sure either
data
ordefaultContent
is defined.
orderable {Boolean}
Indicate whether the column is orderable or not.
className {String}
Indicate the css class value
visible {Boolean}
Indicate a column is visible
Scoped slots (default)
cellData {String}
The cell data.
rowData {Object}
Reactive row data. Useful in display custom data.
rowIndex {Number}
The row number.
colIndex {Number}
The column number.
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago