├── docs ├── .vuepress │ ├── .gitignore │ ├── components │ │ ├── demo-block │ │ │ ├── i18n.json │ │ │ └── demo-block.vue │ │ └── example │ │ │ └── zh │ │ │ ├── fixed-header-table.vue │ │ │ ├── basis-table.vue │ │ │ ├── border-table.vue │ │ │ ├── stripe-table.vue │ │ │ ├── custom-index-table.vue │ │ │ ├── sort-table.vue │ │ │ ├── fluid-height-table.vue │ │ │ ├── status-table.vue │ │ │ ├── radio-table.vue │ │ │ ├── pagination-table.vue │ │ │ ├── multiple-table.vue │ │ │ ├── fixed-column-table.vue │ │ │ ├── multi-header-table.vue │ │ │ ├── render-header-table.vue │ │ │ ├── align-table.vue │ │ │ ├── render-table.vue │ │ │ ├── merge-row-column-table.vue │ │ │ ├── filter-table.vue │ │ │ ├── edit-dialog-table.vue │ │ │ ├── footer-total-table.vue │ │ │ ├── expand-row-table.vue │ │ │ ├── tree-table.vue │ │ │ ├── merge-table.vue │ │ │ └── edit-table.vue │ ├── enhanceApp.js │ └── config.js └── zh │ ├── README.md │ └── guide │ └── README.md ├── .browserslistrc ├── vue.config.js ├── babel.config.js ├── postcss.config.js ├── public ├── favicon.ico └── index.html ├── src ├── assets │ └── logo.png ├── views │ ├── About.vue │ └── Home.vue ├── main.js ├── components │ ├── lb-table │ │ ├── lb-render.vue │ │ ├── forced.js │ │ ├── lb-column.vue │ │ └── lb-table.vue │ └── HelloWorld.vue └── App.vue ├── .editorconfig ├── .travis.yml ├── .gitignore ├── .eslintrc.js ├── deploy.sh ├── package.json └── README.md /docs/.vuepress/.gitignore: -------------------------------------------------------------------------------- 1 | /dist 2 | -------------------------------------------------------------------------------- /.browserslistrc: -------------------------------------------------------------------------------- 1 | > 1% 2 | last 2 versions 3 | not ie <= 8 4 | -------------------------------------------------------------------------------- /vue.config.js: -------------------------------------------------------------------------------- 1 | // vue.config.js 2 | module.exports = { 3 | 4 | } 5 | -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [ 3 | '@vue/app' 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: { 3 | autoprefixer: {} 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liub1934/lb-element-table/HEAD/public/favicon.ico -------------------------------------------------------------------------------- /src/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liub1934/lb-element-table/HEAD/src/assets/logo.png -------------------------------------------------------------------------------- /src/views/About.vue: -------------------------------------------------------------------------------- 1 | 6 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | [*.{js,jsx,ts,tsx,vue}] 2 | indent_style = space 3 | indent_size = 2 4 | trim_trailing_whitespace = true 5 | insert_final_newline = true 6 | -------------------------------------------------------------------------------- /docs/.vuepress/components/demo-block/i18n.json: -------------------------------------------------------------------------------- 1 | [{ 2 | "lang": "zh", 3 | "demo-block": { 4 | "hide-text": "隐藏代码", 5 | "show-text": "显示代码", 6 | "button-text": "在线运行", 7 | "tooltip-text": "前往 codepen.io 运行此示例" 8 | } 9 | }] -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | sudo: required 3 | node_js: 4 | - "8.11.0" 5 | before_install: 6 | - chmod +x deploy.sh 7 | script: 8 | - ./deploy.sh 9 | branch: master 10 | cache: 11 | directories: 12 | - node_modules 13 | -------------------------------------------------------------------------------- /src/main.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import App from './App.vue' 3 | import ElementUI from 'element-ui' 4 | import 'element-ui/lib/theme-chalk/index.css' 5 | 6 | Vue.use(ElementUI) 7 | 8 | Vue.config.productionTip = false 9 | 10 | new Vue({ 11 | render: h => h(App) 12 | }).$mount('#app') 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | /dist 4 | 5 | # local env files 6 | .env.local 7 | .env.*.local 8 | 9 | # Log files 10 | npm-debug.log* 11 | yarn-debug.log* 12 | yarn-error.log* 13 | 14 | # Editor directories and files 15 | .idea 16 | .vscode 17 | *.suo 18 | *.ntvs* 19 | *.njsproj 20 | *.sln 21 | *.sw* 22 | -------------------------------------------------------------------------------- /docs/zh/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | home: true 3 | actionText: 快速上手 → 4 | actionLink: /zh/guide/ 5 | features: 6 | - title: 简洁至上 7 | details: 以 element-ui table为基础进行二次封装,减少代码量 8 | - title: 原参数 9 | details: 使用原有element table的参数及事件,还是熟悉的味道。 10 | - title: 99%支持度 11 | details: 支持几乎所有的事件及参数,新增其他某些功能。 12 | footer: MIT Licensed | Copyright © 2018-present Evan You 13 | --- -------------------------------------------------------------------------------- /src/views/Home.vue: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 19 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | env: { 4 | node: true 5 | }, 6 | 'extends': [ 7 | 'plugin:vue/essential', 8 | '@vue/standard' 9 | ], 10 | rules: { 11 | 'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off', 12 | 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off' 13 | }, 14 | parserOptions: { 15 | parser: 'babel-eslint' 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /docs/.vuepress/enhanceApp.js: -------------------------------------------------------------------------------- 1 | import Element from 'element-ui' 2 | import LbTable from '../../src/components/lb-table/lb-table' 3 | import DemoBlock from './components/demo-block/demo-block' 4 | import 'element-ui/lib/theme-chalk/index.css' 5 | export default ({ 6 | Vue, // VuePress 正在使用的 Vue 构造函数 7 | options, // 附加到根实例的一些选项 8 | router, // 当前应用的路由实例 9 | siteData // 站点元数据 10 | }) => { 11 | Vue.use(Element) 12 | Vue.component('lb-table', LbTable) 13 | Vue.component('demo-block', DemoBlock) 14 | } 15 | -------------------------------------------------------------------------------- /src/components/lb-table/lb-render.vue: -------------------------------------------------------------------------------- 1 | /* 2 | * FileName: lb-render.vue 3 | * Remark: 自定义render 4 | * Project: lb-element-table 5 | * Author: LiuBing 6 | * File Created: Tuesday, 19th March 2019 10:15:30 am 7 | * Last Modified: Tuesday, 19th March 2019 10:15:32 am 8 | * Modified By: LiuBing 9 | */ 10 | 23 | -------------------------------------------------------------------------------- /src/App.vue: -------------------------------------------------------------------------------- 1 | 7 | 8 | 18 | 19 | 29 | -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | lb-element-table 9 | 10 | 11 | 14 |
15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /deploy.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 确保脚本抛出遇到的错误 4 | set -e 5 | 6 | # 生成静态文件 7 | npm run docs:build 8 | 9 | # 进入生成的文件夹 10 | cd docs/.vuepress/dist 11 | 12 | # 如果是发布到自定义域名 13 | # echo 'www.example.com' > CNAME 14 | 15 | git init 16 | git add -A 17 | git commit -m 'deploy' 18 | 19 | git config --local user.name "liub1934" 20 | git config --local user.email "liub1934@gmail.com" 21 | 22 | # 如果发布到 https://.github.io 23 | # git push -f git@github.com:/.github.io.git master 24 | 25 | # 如果发布到 https://.github.io/ 26 | git push -f https://${access_token}@github.com/liub1934/lb-element-table.git master:gh-pages 27 | 28 | cd - -------------------------------------------------------------------------------- /docs/.vuepress/config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | base: '/lb-element-table/', 3 | locales: { 4 | '/zh/': { 5 | lang: 'zh-CN', 6 | title: 'lb-element-table', 7 | description: '基于element ui table二次封装,几乎支持原table所有的功能。' 8 | } 9 | }, 10 | themeConfig: { 11 | repo: 'liub1934/lb-element-table', 12 | docsDir: 'docs', 13 | locales: { 14 | '/zh/': { 15 | label: '简体中文', 16 | selectText: '选择语言', 17 | nav: [{ 18 | text: '主页', 19 | link: '/zh/' 20 | }, 21 | { 22 | text: '指南', 23 | link: '/zh/guide/' 24 | }, 25 | { 26 | text: '个人小站', 27 | link: 'https://liubing.me' 28 | } 29 | ] 30 | } 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /docs/.vuepress/components/example/zh/fixed-header-table.vue: -------------------------------------------------------------------------------- 1 | 8 | 9 | 41 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "lb-element-table", 3 | "version": "0.1.0", 4 | "private": true, 5 | "scripts": { 6 | "serve": "vue-cli-service serve", 7 | "build": "vue-cli-service build", 8 | "lint": "vue-cli-service lint", 9 | "docs:dev": "vuepress dev docs", 10 | "docs:build": "vuepress build docs" 11 | }, 12 | "dependencies": { 13 | "element-ui": "^2.9.1", 14 | "highlight.js": "^9.15.6", 15 | "vue": "^2.6.6", 16 | "vue-highlight.js": "^3.1.0", 17 | "webpack-dev-middleware": "^3.6.0" 18 | }, 19 | "devDependencies": { 20 | "@vue/cli-plugin-babel": "^3.5.0", 21 | "@vue/cli-plugin-eslint": "^3.5.0", 22 | "@vue/cli-service": "^3.5.0", 23 | "@vue/eslint-config-standard": "^4.0.0", 24 | "babel-eslint": "^10.0.1", 25 | "eslint": "^5.8.0", 26 | "eslint-plugin-vue": "^5.0.0", 27 | "node-sass": "^4.11.0", 28 | "sass-loader": "^7.1.0", 29 | "vue-template-compiler": "^2.5.21", 30 | "vuepress": "^0.14.10" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # lb-element-table 2 | 3 | > 不要使用`propColumn`,现已删除,Demo一直未更新。
4 | > Do not use `propColumn`, it has been deleted, the demo has not been updated 5 | 6 | Demo:[Go](https://github.liubing.me/lb-element-table/zh/guide/) 7 | 8 | How to Use: 9 | 10 | Find `lb-table` in `src/components` And Copy it to your own project, then import it, and change it freely according to your needs. 11 | 12 | 在`src/components`目录中找到`lb-table`,复制到自己的项目中,然后引用,可以根据自己的需求自由更改。 13 | 14 | ## Project setup 15 | ``` 16 | npm install 17 | ``` 18 | 19 | ### Compiles and hot-reloads for development 20 | ``` 21 | npm run serve 22 | ``` 23 | 24 | ### Compiles and hot-reloads for docs 25 | `/lb-element-table/zh/guide/` 26 | ``` 27 | npm run docs:dev 28 | ``` 29 | 30 | ### Compiles and minifies for production 31 | ``` 32 | npm run build 33 | ``` 34 | 35 | ### Compiles and minifies for docs 36 | ``` 37 | npm run docs:build 38 | ``` 39 | 40 | ### Lints and fixes files 41 | ``` 42 | npm run lint 43 | ``` 44 | 45 | ### Customize configuration 46 | See [Configuration Reference](https://cli.vuejs.org/config/). 47 | -------------------------------------------------------------------------------- /docs/.vuepress/components/example/zh/basis-table.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | 48 | -------------------------------------------------------------------------------- /docs/.vuepress/components/example/zh/border-table.vue: -------------------------------------------------------------------------------- 1 | 7 | 8 | 49 | -------------------------------------------------------------------------------- /docs/.vuepress/components/example/zh/stripe-table.vue: -------------------------------------------------------------------------------- 1 | 7 | 8 | 49 | -------------------------------------------------------------------------------- /docs/.vuepress/components/example/zh/custom-index-table.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | 57 | -------------------------------------------------------------------------------- /docs/.vuepress/components/example/zh/sort-table.vue: -------------------------------------------------------------------------------- 1 | 10 | 11 | 60 | -------------------------------------------------------------------------------- /docs/.vuepress/components/example/zh/fluid-height-table.vue: -------------------------------------------------------------------------------- 1 | 7 | 8 | 65 | -------------------------------------------------------------------------------- /docs/.vuepress/components/example/zh/status-table.vue: -------------------------------------------------------------------------------- 1 | 7 | 8 | 64 | 65 | 74 | -------------------------------------------------------------------------------- /docs/.vuepress/components/example/zh/radio-table.vue: -------------------------------------------------------------------------------- 1 | 15 | 16 | 70 | -------------------------------------------------------------------------------- /docs/.vuepress/components/example/zh/pagination-table.vue: -------------------------------------------------------------------------------- 1 | 17 | 18 | 74 | -------------------------------------------------------------------------------- /docs/.vuepress/components/example/zh/multiple-table.vue: -------------------------------------------------------------------------------- 1 | 14 | 15 | 74 | -------------------------------------------------------------------------------- /docs/.vuepress/components/example/zh/fixed-column-table.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | 77 | 78 | 87 | -------------------------------------------------------------------------------- /docs/.vuepress/components/example/zh/multi-header-table.vue: -------------------------------------------------------------------------------- 1 | 7 | 8 | 78 | -------------------------------------------------------------------------------- /src/components/lb-table/forced.js: -------------------------------------------------------------------------------- 1 | export default { 2 | selection: { 3 | renderHeader: (h, { store }) => { 4 | console.log(store) 5 | return ( 6 | 0 && !store.states.isAllSelected 10 | } 11 | nativeOn-click={store.toggleAllSelection} 12 | value={store.states.isAllSelected} 13 | /> 14 | ) 15 | }, 16 | renderCell: (h, { row, column, store, $index }) => { 17 | return ( 18 | event.stopPropagation()} 20 | value={store.isSelected(row)} 21 | disabled={ 22 | column.selectable 23 | ? !column.selectable.call(null, row, $index) 24 | : false 25 | } 26 | on-input={() => { 27 | store.commit('rowSelectedChanged', row) 28 | }} 29 | /> 30 | ) 31 | }, 32 | sortable: false, 33 | resizable: false 34 | }, 35 | index: { 36 | renderHeader: (h, scope) => { 37 | return {scope.column.label || '#'} 38 | }, 39 | renderCell: (h, { $index, column }) => { 40 | let i = $index + 1 41 | const index = column.index 42 | 43 | if (typeof index === 'number') { 44 | i = $index + index 45 | } else if (typeof index === 'function') { 46 | i = index($index) 47 | } 48 | 49 | return
{i}
50 | }, 51 | sortable: false 52 | }, 53 | expand: { 54 | renderHeader: (h, scope) => { 55 | return {scope.column.label || ''} 56 | }, 57 | renderCell: (h, { row, store }, proxy) => { 58 | const expanded = store.states.expandRows.indexOf(row) > -1 59 | return ( 60 |
proxy.handleExpandClick(row, e)} 66 | > 67 | 68 |
69 | ) 70 | }, 71 | sortable: false, 72 | resizable: false, 73 | className: 'el-table__expand-column' 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /docs/.vuepress/components/example/zh/render-header-table.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | 81 | -------------------------------------------------------------------------------- /docs/.vuepress/components/example/zh/align-table.vue: -------------------------------------------------------------------------------- 1 | 25 | 26 | 106 | -------------------------------------------------------------------------------- /docs/.vuepress/components/example/zh/render-table.vue: -------------------------------------------------------------------------------- 1 | 7 | 8 | 91 | -------------------------------------------------------------------------------- /docs/.vuepress/components/example/zh/merge-row-column-table.vue: -------------------------------------------------------------------------------- 1 | 17 | 18 | 116 | -------------------------------------------------------------------------------- /docs/.vuepress/components/example/zh/filter-table.vue: -------------------------------------------------------------------------------- 1 | 11 | 12 | 106 | -------------------------------------------------------------------------------- /src/components/HelloWorld.vue: -------------------------------------------------------------------------------- 1 | 11 | 12 | 111 | 112 | 121 | -------------------------------------------------------------------------------- /docs/.vuepress/components/example/zh/edit-dialog-table.vue: -------------------------------------------------------------------------------- 1 | 45 | 46 | 107 | -------------------------------------------------------------------------------- /docs/.vuepress/components/example/zh/footer-total-table.vue: -------------------------------------------------------------------------------- 1 | 19 | 20 | 120 | -------------------------------------------------------------------------------- /src/components/lb-table/lb-column.vue: -------------------------------------------------------------------------------- 1 | /* 2 | * FileName: lb-column.vue 3 | * Remark: element-column 4 | * Project: lb-element-table 5 | * Author: LiuBing 6 | * File Created: Tuesday, 19th March 2019 9:58:23 am 7 | * Last Modified: Tuesday, 19th March 2019 10:14:42 am 8 | * Modified By: LiuBing 9 | */ 10 | 11 | 65 | 66 | 107 | -------------------------------------------------------------------------------- /docs/.vuepress/components/example/zh/expand-row-table.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | 101 | 102 | 116 | -------------------------------------------------------------------------------- /docs/.vuepress/components/example/zh/tree-table.vue: -------------------------------------------------------------------------------- 1 | 22 | 23 | 135 | -------------------------------------------------------------------------------- /src/components/lb-table/lb-table.vue: -------------------------------------------------------------------------------- 1 | /* 2 | * FileName: lb-table.vue 3 | * Remark: element table 4 | * Project: lb-element-table 5 | * Author: LiuBing 6 | * File Created: Tuesday, 19th March 2019 9:55:27 am 7 | * Last Modified: Tuesday, 19th March 2019 9:55:34 am 8 | * Modified By: LiuBing 9 | */ 10 | 11 | 33 | 34 | 148 | -------------------------------------------------------------------------------- /docs/.vuepress/components/example/zh/merge-table.vue: -------------------------------------------------------------------------------- 1 | 17 | 18 | 177 | -------------------------------------------------------------------------------- /docs/.vuepress/components/example/zh/edit-table.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | 145 | -------------------------------------------------------------------------------- /docs/.vuepress/components/demo-block/demo-block.vue: -------------------------------------------------------------------------------- 1 | 45 | 46 | 192 | 193 | 294 | -------------------------------------------------------------------------------- /docs/zh/guide/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar: auto 3 | --- 4 | 5 | # 使用示例 6 | 7 | ## 基本使用 8 | 9 | ### 基础表格 10 | 基础的表格展示用法。 11 | 12 | 13 | 14 | <<< @/docs/.vuepress/components/example/zh/basis-table.vue 15 | 16 | 17 | ### 表格对齐 18 | 表格头部及内容的对齐方式。 19 | 20 | 21 | 22 | 默认表头及表格内容左对齐,可以分别设置不同字段的表头及表格内容对齐方式。 23 | 24 | `lb-table`设置`align`属性可以设置整体表格的对齐方式,默认`left`左对齐,可配置项:`left`、`center`、`right`。 25 | 26 | `column`中可单独为某个字段配置`align`,优先级`column配置的align` > `lb-table配置的align`。 27 | 28 | 表头对齐`header-align`同理,如果不设置对齐方式同`column`和`lb-table`设置的`align` 29 | 30 | <<< @/docs/.vuepress/components/example/zh/align-table.vue 31 | 32 | 33 | ### 带斑马纹表格 34 | 使用带斑马纹的表格,可以更容易区分出不同行的数据。 35 | 36 | 37 | 38 | <<< @/docs/.vuepress/components/example/zh/stripe-table.vue 39 | 40 | 41 | ### 带边框表格 42 | 43 | 44 | 45 | <<< @/docs/.vuepress/components/example/zh/border-table.vue 46 | 47 | 48 | ### 带状态表格 49 | 可将表格内容 highlight 显示,方便区分「成功、信息、警告、危险」等内容。 50 | 51 | 52 | 53 | 可以通过指定 Table 组件的 `row-class-name` 属性来为 Table 中的某一行添加 class,表明该行处于某种状态。 54 | 55 | <<< @/docs/.vuepress/components/example/zh/status-table.vue 56 | 57 | 58 | ### 固定表头 59 | 60 | 纵向内容过多时,可选择固定表头。 61 | 62 | 63 | 64 | 只要在`lb-table`元素中定义了`height`属性,即可实现固定表头的表格,而不需要额外的代码。 65 | 66 | <<< @/docs/.vuepress/components/example/zh/fixed-header-table.vue 67 | 68 | 69 | 70 | ### 固定列 71 | 横向内容过多时,可选择固定列。 72 | 73 | 74 | 75 | 固定列需要在`column`属性中配置`fixed`属性,它接受 Boolean 值或者leftright,表示左边固定还是右边固定。 76 | 77 | <<< @/docs/.vuepress/components/example/zh/fixed-column-table.vue 78 | 79 | 80 | ### 流体高度 81 | 当数据量动态变化时,可以为 Table 设置一个最大高度。 82 | 83 | 84 | 85 | 通过设置`max-height`属性为 Table 指定最大高度。此时若表格所需的高度大于最大高度,则会显示一个滚动条。 86 | 87 | <<< @/docs/.vuepress/components/example/zh/fluid-height-table.vue 88 | 89 | 90 | ### 多级表头 91 | 数据结构比较复杂的时候,可使用多级表头来展现数据的层次关系。 92 | 93 | 94 | 95 | 通过设置`column`中的`children`进行表格头嵌套,理论支持无限极嵌套,嵌套也支持自定义表头及列数据。 96 | 97 | <<< @/docs/.vuepress/components/example/zh/multi-header-table.vue 98 | 99 | 100 | ### 单选 101 | 选择单行数据时使用色块表示。 102 | 103 | 104 | 105 | 同 `El-Table` 组件,只需要配置`highlight-current-row`属性即可实现单选。之后由current-change事件来管理选中时触发的事件,它会传入`currentRow`,`oldCurrentRow`。 106 | 如果需要显示索引,可设置索引列`type`属性为`index`即可显示从 1 开始的索引号。 107 | 108 | <<< @/docs/.vuepress/components/example/zh/radio-table.vue 109 | 110 | 111 | ### 多选 112 | 选择多行数据时使用 Checkbox。 113 | 114 | 115 | 116 | 设置`type`为`selection`即可。 117 | 118 | <<< @/docs/.vuepress/components/example/zh/multiple-table.vue 119 | 120 | 121 | ### 排序 122 | 对表格进行排序,可快速查找或对比数据 123 | 124 | 125 | 126 | 在`column`相应列设置`sortable`属性即可实现以该列为基准的排序,接受一个`Boolean`,默认为`false`。可以通过 `lb-table` 的default-sort属性设置默认的排序列和排序顺序。可以使用`sort-method`或者`sort-by`使用自定义的排序规则。如果需要后端排序,需将`sortable`设置为`custom`,同时在 `lb-table` 上监听`sort-change`事件,在事件回调中可以获取当前排序的字段名和排序顺序,从而向接口请求排序后的表格数据。在本例中,我们还使用了`formatter`属性,它用于格式化指定列的值,接受一个`Function`,会传入两个参数:`row`和`column`,可以根据自己的需求进行处理。 127 | 128 | <<< @/docs/.vuepress/components/example/zh/sort-table.vue 129 | 130 | 131 | ### 筛选 132 | 对表格进行筛选,可快速查找到自己想看的数据。 133 | 134 | 135 | 136 | 在列中设置 `filters` `filter-method`属性即可开启该列的筛选,`filters` 是一个数组,`filter-method` 是一个方法,它用于决定某些数据是否显示,会传入三个参数:`value`, `row` 和 `column`。 137 | 138 | <<< @/docs/.vuepress/components/example/zh/filter-table.vue 139 | 140 | 141 | ### 展开行 142 | 当行内容过多并且不想显示横向滚动条时,可以使用 Table 展开行功能。 143 | 144 | 145 | 146 | 通过设置 `type="expand"`可以开启展开行功能,展开行的内容可以通过`render`自定义 147 | 148 | <<< @/docs/.vuepress/components/example/zh/expand-row-table.vue 149 | 150 | 151 | ### 自定义列模板 152 | 自定义列的显示内容,可组合其他组件使用。 153 | 154 | 155 | 156 | 暂不支持官方``用法自定义,统一使用`render`和`JSX`写法。`render`参考[官网文档](https://cn.vuejs.org/v2/guide/render-function.html)。个人觉得`JSX`写法更简洁舒服些,后面的相关示例都是`JSX`写法, 157 | `vue-cli-2`脚手架搭建的项目如需支持`JSX`,请参考配置:[点击前往](https://github.com/vuejs/babel-plugin-transform-vue-jsx),如需支持`v-model`写法,请安装配置:[点击前往](https://github.com/nickmessing/babel-plugin-jsx-v-model)。 158 | `vue-cli-3`脚手架自带,可直接使用`JSX`,`JSX`写法参考同上地址。 159 | 160 | <<< @/docs/.vuepress/components/example/zh/render-table.vue 161 | 162 | 163 | ### 树形数据与懒加载 164 | 2.8.0+版本支持树形表格 165 | 166 | 167 | 168 | 用法同`el-table`,当 `row` 中包含 `children` 字段时,被视为树形数据。渲染树形数据时,必须要指定 `row-key`。支持子节点数据异步加载。设置 Table 的 `lazy` 属性为 true 与加载函数 `load` 。通过指定 `row` 中的 `hasChildren` 字段来指定哪些行是包含子节点。`children` 与 `hasChildren` 都可以通过 `tree-props` 配置。 169 | 170 | <<< @/docs/.vuepress/components/example/zh/tree-table.vue 171 | 172 | 173 | ### 自定义表头 174 | 表头支持自定义。 175 | 176 | 177 | 178 | 通过设置`renderHeader`来自定义表头,写法同`自定义列模板` 179 | 180 | ::: tip 181 | 由于`vuepress`不支持`JSX`的`v-model`,所以示例代码使用的`value`、`onInput`实现的双向绑定,正常环境下可直接使用`v-model` 182 | ::: 183 | 184 | <<< @/docs/.vuepress/components/example/zh/render-header-table.vue 185 | 186 | 187 | ### 表尾合计行 188 | 若表格展示的是各类数字,可以在表尾显示各列的合计。 189 | 190 | 191 | 192 | 将`show-summary`设置为`true`就会在表格尾部展示合计行。默认情况下,对于合计行,第一列不进行数据求合操作,而是显示「合计」二字(可通过`sum-text`配置),其余列会将本列所有数值进行求合操作,并显示出来。当然,你也可以定义自己的合计逻辑。使用`summary-method`并传入一个方法,返回一个数组,这个数组中的各项就会显示在合计行的各列中,具体可以参考本例中的第二个表格。 193 | 194 | <<< @/docs/.vuepress/components/example/zh/footer-total-table.vue 195 | 196 | 197 | ### 自定义索引 198 | 若表格展示的是各类数字,可以在表尾显示各列的合计。 199 | 200 | 201 | 202 | 通过给 `type=index` 的列传入 `index` 属性,可以自定义索引。该属性传入数字时,将作为索引的起始值。也可以传入一个方法,它提供当前行的行号(从 0 开始)作为参数,返回值将作为索引展示。 203 | 204 | <<< @/docs/.vuepress/components/example/zh/custom-index-table.vue 205 | 206 | 207 | ### 合并行或列 208 | 多行或多列共用一个数据时,可以合并行或列。 209 | 210 | 211 | 212 | 通过给`lb-table`传入`span-method`方法可以实现合并行或列,方法的参数是一个对象,里面包含当前行`row`、当前列`column`、当前行号`rowIndex`、当前列号`columnIndex`四个属性。该函数可以返回一个包含两个元素的数组,第一个元素代表`rowspan`,第二个元素代表`colspan`。 也可以返回一个键名为`rowspan`和`colspan`的对象。 213 | 214 | <<< @/docs/.vuepress/components/example/zh/merge-row-column-table.vue 215 | 216 | 217 | ## 扩展使用 218 | 219 | ### 表格分页 220 | 表格支持开启分页显示 221 | 222 | 223 | 224 | `lb-table`设置属性`pagination`即可开启分页,分页相关参数及用法同`el-pagination`。暂时新增几个新参数,`paginationTop`表示分页距离表格的间距,默认`15px`,`paginationAlign`分页的对齐方式,默认为`right`,分页整体显示在右侧,可配置`left`、`center`、`right` 225 | 226 | ::: tip 227 | 由于分页和表格的`current-change`冲突,所以分页请使用`p-current-change` 228 | ::: 229 | 230 | <<< @/docs/.vuepress/components/example/zh/pagination-table.vue 231 | 232 | 233 | ### 表格动态合并 234 | 支持表格动态合并 235 | 236 | 237 | 238 | `lb-table`上配置`merge`,`merge`为一个包含需要合并的`column`中`prop`的数组,配置后会自动将值相同的项自动合并。 239 | 240 | <<< @/docs/.vuepress/components/example/zh/merge-table.vue 241 | 242 | 243 | ### 普通形式表格编辑 244 | 数据简单的情况下,可以通过点击编辑按钮直接进行表格的编辑、保存、取消操作 245 | 246 | 247 | 248 | 由于编辑模式下数据格式不统一,如日期数据通过`DatePicker`选择,普通的文本通过`Input`,下拉选择的通过`ElSelect`等,所以就不进行整合了, 249 | 大家可以通过`render`自定义出任意效果的编辑模式,原理就是根据是否是编辑模式的字段,渲染不同的内容, 250 | 如本例中的`_edit`,为`true`的情况下渲染相应的编辑模式下的组件,否则就是普通的文本。 251 | 252 | 由于编辑模式中有取消,所以取消的时候得还原原数据,可以通过定义一个`defaultData`,该值为`JSON.parse(JSON.stringify(this.tableData.data))`, 253 | 加`JSON.parse`和`JSON.stringify`防止`defaultData`数据随着`this.tableData.data`的改变而改变,取消的时候通过`$index`索引从`defaultData`中拿到原数据, 254 | 然后根据`$index`索引修改`this.tableData.data`的数据 255 | 256 | ::: tip 257 | 由于`vuepress`不支持`JSX`的`v-model`,所以示例代码使用的`value`、`onChange`、`onInput`实现的双向绑定,正常环境下可直接使用`v-model` 258 | ::: 259 | 260 | <<< @/docs/.vuepress/components/example/zh/edit-table.vue 261 | 262 | 263 | ### 弹窗形式表格编辑 264 | 数据复杂的情况,建议通过弹窗形式进行数据编辑的操作 265 | 266 | 267 | 268 | 269 | <<< @/docs/.vuepress/components/example/zh/edit-dialog-table.vue 270 | 271 | --------------------------------------------------------------------------------