vue-el-datatables
Vue2.0 Datatables
Based on elemnet-ui, ES6
Install
npm install element-ui vue-el-datatables -save
Get Started
import ElementUI from 'element-ui'
import DataTables from 'vue-el-datatables'
Vue.use(ElementUI)
Vue.component(DataTables.name, DataTables)
or
import { Row, Col, Card, Table, TableColumn, Input } from 'element-ui'
import DataTables from 'vue-el-datatables'
Vue.use(Row)
Vue.use(Col)
Vue.use(Table)
Vue.use(TableColumn)
Vue.use(Input)
Vue.component(DataTables.name, DataTables)
Usage
对于服务器接口返回数据形式,数据会建立本地缓存,已获取的分页数据将不会进行重新请求,但为了保证搜索功能数据的完整性,使用搜索时将进行接口请求,而清除搜索条件后表格会自动回到分页缓存数据
<template>
<DataTables :columnHead="columnHead" :tableData="tableData" :serverApi="serverApi" :searchBar="true" @apiError="apiError">
<el-button type="primary" slot="toolBar">add User</el-button>
<template scope="props">
<el-button v-if="props.columnID === 'action'" @click.stop="apiError(props.ev.row.id)">Edit</el-button>
<div v-if="props.columnID === 'status'" :class="formatStatus(props.ev.row.status)[0]">{{formatStatus(props.ev.row.status)[1]}}</div>
</template>
</DataTables>
</template>
slot
DataTables 内容可使用分发内容
toolBar 分发至表格顶部工具区域
template 内部分发至表格数据行内容,可通过scope="props",获取当前行的数据,并进行格式化数据
Attributes
Property | Type | Desc | Default values | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
columnHead | Array |
表格头设置:
|
|||||||||||||||||||||||||||||||||||||
tableData | Array | 数据表值,使用serverApi参数时该项无用,结构:[{prop1: value, prop2: value}] | |||||||||||||||||||||||||||||||||||||
serverApi | Function | 服务器数据获取接口方法,当使用该选项时,组件会调用该方法,传递参数:
|
|||||||||||||||||||||||||||||||||||||
useStore | Boolean | 是否使用缓存模式 | false | ||||||||||||||||||||||||||||||||||||
searchBar | Boolean | 是否显示模糊搜索框 | false | ||||||||||||||||||||||||||||||||||||
rowClick | Function | 行点击事件,见element-ui文档 | () => {} | ||||||||||||||||||||||||||||||||||||
rowContextmenu | Function | 行右键点击事件,见element-ui文档 | () => {} | ||||||||||||||||||||||||||||||||||||
rowDblclick | Function | 行双击事件,见element-ui文档 | () => {} | ||||||||||||||||||||||||||||||||||||
apiError | String | 监控数据表调用接口返回错误结果,msg => {console.log(msg)} | |||||||||||||||||||||||||||||||||||||
reload | Functon | 通过this.$refs['ref'].reload调用,如果是接口模式该方法将重新获取当前页面数据并请求返回数据总数,如果是非接口模式将重载页面并回到第一页 |
Contact
The project's website is located at https://github.com/Dess-Li/vue-el-datatables
Dependencies
Dependencies
autoprefixer: ^6.7.2babel-core: ^6.26.0babel-eslint: ^7.1.1babel-helper-vue-jsx-merge-props: ^2.0.2babel-loader: ^6.2.10babel-plugin-component: ^0.9.1babel-plugin-syntax-jsx: ^6.18.0babel-plugin-transform-runtime: ^6.22.0babel-plugin-transform-vue-jsx: ^3.5.0babel-preset-env: ^1.6.1babel-preset-es2015: ^6.24.1babel-preset-stage-2: ^6.22.0babel-register: ^6.26.0body-parser: ^1.18.2chalk: ^1.1.3connect-history-api-fallback: ^1.5.0copy-webpack-plugin: ^4.2.3css-loader: ^0.28.7element-ui: ^2.0.0eslint: ^3.19.0eslint-config-standard: ^6.2.1eslint-friendly-formatter: ^2.0.7eslint-loader: ^1.7.1eslint-plugin-html: ^2.0.0eslint-plugin-promise: ^3.6.0eslint-plugin-standard: ^2.0.1eventsource-polyfill: ^0.9.6express: ^4.16.2extract-text-webpack-plugin: ^2.1.2file-loader: ^0.11.2friendly-errors-webpack-plugin: ^1.1.3html-webpack-plugin: ^2.30.1http-proxy-middleware: ^0.17.3less: ^2.7.3less-loader: ^4.0.4loader-utils: ^1.1.0mockjs: ^1.0.1-beta3nodemon: ^1.12.5opn: ^4.0.2optimize-css-assets-webpack-plugin: ^1.3.2ora: ^1.3.0rimraf: ^2.6.2semver: ^5.4.1shelljs: ^0.7.8url-loader: ^0.5.9vue-loader: ^11.3.4vue-router: ^2.8.1vue-style-loader: ^2.0.5vue-template-compiler: ^2.5.9webpack: ^2.7.0webpack-bundle-analyzer: ^2.9.1webpack-dev-middleware: ^1.12.2webpack-hot-middleware: ^2.21.0webpack-merge: ^4.1.1yaml-loader: ^0.4.0