1.2.17 • Published 10 months ago

tm-flextable v1.2.17

Weekly downloads
119
License
MIT
Repository
github
Last release
10 months ago

FlexTable

NPM version build status npm download codecov

An efficiently updated div table Vue component. Compatible with Vue 2.x

Demo

To view a demo online: https://tm-fe.github.io/FlexTable/examples/dist/

To view demo examples locally clone the repo and run yarn install && yarn dev or view local example

Screenshots

flextable

Feature

  • 支持最大高度,超过 fixed header
  • 固定列
  • footer 展示汇总数据
  • 自定义列宽
  • 排序
  • 拖动调整列宽(resizable)
  • selectable
  • expand 嵌套功能
  • 异步渲染
  • selectable模式下渲染选中行背景色
  • 初始化渲染行、列、单元格背景色
  • 合并单元格
  • 拖动改变列顺序

Install

npm install --save tm-flextable
// or
yarn add tm-flextable
import { FlexTable } from 'tm-flextable';

export default {
  // ...
  components: {
    FlexTable
  }
  // ...
}

Usage

CDN 引入

<script src="https://unpkg.com/tm-flextable@latest/dist/index.js" type="text/javascript"></script>

然后直接在页面使用

<div id="app">
    <flex-table
        resizable
        :loading="loading" 
        :columns="columns" 
        :data="list"
        :sum="sum">
    </flex-table>
</div>
<script>
    new Vue({
        el: '#app',
        data: {
            // ...
        },
        methods: {
            // ...
        }
    })
  </script>

npm 安装(推荐)

// main.js
import Vue from 'vue';
import VueRouter from 'vue-router';
import App from 'components/app.vue';
import Routers from './router.js';
import FlexTable from 'tm-flextable';

Vue.use(VueRouter);
Vue.use(FlexTable); // 全局注册组件

//or 
// app.vue
// 局部注册
import { FlexTable } from 'tm-flextable';
export default {
    components:{
        flexTable
    },
    // ...

API

Table props

属性说明类型默认值
data显示的结构化数据Array[]
columns表格列的配置描述,具体项见后文Array[]
sum显示的结构化数据汇总Object{}
loading是否加载中Booleanfalse
resizable是否可拖动调整列宽Booleanfalse
height表格高度,单位 px,设置后,如果表格内容大于此值,会固定表头Number-
no-data数据为空时显示的提示内容StringNo Data
asyncRender不为 0 时使用异步渲染模式,mounted 触发前渲染的行数(建议是刚好首屏,见后文详细说明)number0
minWidth最小列宽Number40
maxWidth拖动调整时,可调的最大列宽, 默认不限制number-
size表格大小 default/big/smallStringdefault
theme颜色 light/darkStringlight
border边框显示Booleantrue
stripe行的斑纹显示Booleantrue
fixedHead全屏固定头部Booleanfalse
fixedHeadTop全屏固定头部离顶部距离Number0
checkFixedHeadTop全屏固定头部离顶部距离判断(可以自定义)Function''
selectedClass单选或多选模式下,渲染选中行样式string''
rowClassName初始化渲染行背景色Function''
autoCalWidth是否自动计算widthBooleantrue, 默认true,false时会严格按照设置的width来展示
span-method合并行(合并列暂未实现)Function方法的参数是一个对象,里面包含当前行row、当前列column、当前行号rowIndex、当前列号columnIndex四个属性。该函数可以返回一个包含两个元素的数组,第一个元素代表rowspan,第二个元素代表colspan。 也可以返回一个键名为rowspan和colspan的对象。具体见 demo
multiple是否多选(设置false即为单选)Booleantrue
selectedData传入的默认选中idArray
uniqueKey表格数据的唯一值名称(处理id重复报错问题)String
virtualScroll虚拟滚动的展示条数(设置此值即自动开启虚拟滚动功能)Number
virtualHeight虚拟滚动的单条数据高度(开启虚拟滚动时必填,否则表格会有间隙错位)Number40
scrollContainer表格所在的滚动容器,默认document,传String会使用document.querySelector查询String/Objectdocument
fixedXScroll是否固定横向滚动Booleanfalse
fixedXScrollBottom固定横向滚动的底部位置Number/String0
vertical表格单元格是否垂直居中Booleanfalse(如果需要某一列需要垂直居中:在表columns中给需要垂直居中的字段增加 vertical: true 即可)

Table events

事件名说明返回值
on-sort-change排序时有效,当点击排序时触发column:当前列数据; key:排序依据的指标; order:排序的顺序,值为 asc 或 desc
on-selection-change点击全选时触发selection:已选项数据; row: 当前选中行数据
on-all-cancel全选取消时触发selection:已选项数据
on-selection-cancel单选取消时触发selection:已选项数据
on-render-done异步渲染完成时触发(asyncRender 不为 0 时生效)-
on-scroll-x横向滚动事件event
on-col-width-resize调整列宽事件newWidth, oldWidth, column, event

column

列描述数据对象,是 columns 中的一项

属性说明类型默认值
title列名String-
key列名String-
type列类型,可选值为 index、selection、expandString-
width列宽,不设置将自动分配,最小 60pxNumber60
align对齐方式,可选值为 left 左对齐、right 右对齐和 center 居中对齐StringLeft
fixed列是否固定在左侧或者右侧,可选值为 leftrightString-
render自定义渲染列,使用 Vue 的 Render 函数。传入两个参数,第一个是 h,第二个为对象,包含 row、column 和 index,分别指当前行数据,当前列数据,当前行索引,详见示例。Function-
renderHeader自定义列头显示内容,使用 Vue 的 Render 函数。传入两个参数,第一个是 h,第二个为对象,包含 column 和 index,分别为当前列数据和当前列索引。Function-
sortable对应列是否可以排序,如果设置为 custom,则代表用户希望远程排序,需要监听 Table 的 on-sort-change 事件Booleanfalse
sortType设置初始化排序。值为 asc, desc 和 normalStringnormal
resizable是否可拖动调整列宽(必须设置table props 的 resizable 为 true 才生效)Boolean-
minWidth最小列宽(优先级高于table props)number-
maxWidth拖动调整时,可调的最大列宽, 默认不限制(优先级高于table props)number-
className初始化渲染列的背景色string''

data

行描述数据对象,是 list 中的一项

属性说明类型默认值
cellClassName指定任意一个单元格的背景色Object{}

特别说明

行类名、列类名、单元格类名和选中行类名的权重由它们的定义顺序决定 定义在后面的权重相对较大

Table slot

名称说明
loading加载中

asyncRender

异步渲染功能,适用于数据量特别大,改善首次渲染慢的情况。asyncRender 值为 mounted 之前首次渲染的行数,剩余行数会在 mounted 之后以 RAF 的方式逐行渲染,因此如果没有设置表格最大高度 height, 可能会造成页面抖动和 reflow, 建议设置 table height prop。 此外, 当表格数据 data 属性变化时,也会造成整表重新渲染,而失去 vue diff 的优势, 可以在首次异步渲染完成后的 on-render-done 事件中,将 asyncRender 的值改为 pageSize 相同的值,这样可以避免整表重新渲染。

virtualScroll

image

虚拟滚动功能注意点:

    1. 只支持每条数据高度一致的情况,不支持展开行以及任何会改变单元格高度的方式;
    1. 不支持分组表头;
    1. 当表格有固定列的情况,虚拟滚动可能会有延迟
    1. 必须给源数据每一项加上唯一id。必须确定且唯一。假如用随机数,会导致每次的id都不一致,vue会误以为是有是数据更新,无法复用。详见Vue的dIff算法。

Test

    yarn test
    or
    npm test

Coverage

License

tm-flextable is released under the MIT license.

1.2.17

10 months ago

1.2.16

1 year ago

1.2.15

1 year ago

1.2.8

2 years ago

1.2.7

2 years ago

1.2.12

1 year ago

1.2.13

1 year ago

1.2.10

2 years ago

1.2.11

1 year ago

1.2.14

1 year ago

1.2.9

2 years ago

1.2.0

2 years ago

1.2.6

2 years ago

1.2.5

2 years ago

1.2.4

2 years ago

1.2.3

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.1.9

2 years ago

1.1.8

2 years ago

1.1.7

2 years ago

1.1.6

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

0.8.4

2 years ago

0.9.4

2 years ago

0.9.3

2 years ago

0.8.1

2 years ago

0.8.3

2 years ago

0.8.2

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

1.0.3

2 years ago

0.9.0

2 years ago

0.9.2

2 years ago

0.9.1

2 years ago

0.8.0

2 years ago

0.7.9

2 years ago

0.7.8

2 years ago

0.7.7

2 years ago

0.7.6

2 years ago

0.7.5

2 years ago

0.6.7

2 years ago

0.6.6

2 years ago

0.6.8

2 years ago

0.5.14

2 years ago

0.5.15

2 years ago

0.7.2

2 years ago

0.7.1

2 years ago

0.7.4

2 years ago

0.7.3

2 years ago

0.7.0

2 years ago

0.6.3

2 years ago

0.6.2

2 years ago

0.6.5

2 years ago

0.6.4

2 years ago

0.6.1

2 years ago

0.6.0

2 years ago

0.5.11

2 years ago

0.5.12

2 years ago

0.5.13

2 years ago

0.5.10

3 years ago

0.5.9

3 years ago

0.5.8

3 years ago

0.5.7

3 years ago

0.5.6

3 years ago

0.5.4

3 years ago

0.5.5

3 years ago

0.5.3

3 years ago

0.5.2

3 years ago

0.5.1

3 years ago

0.5.0

3 years ago

0.4.22

3 years ago

0.4.23

3 years ago

0.4.20

3 years ago

0.4.21

3 years ago

0.4.19

3 years ago

0.4.18

3 years ago

0.4.17

3 years ago

0.4.16

3 years ago

0.4.9

3 years ago

0.4.8

3 years ago

0.4.10

3 years ago

0.4.15

3 years ago

0.4.13

3 years ago

0.4.14

3 years ago

0.4.11

3 years ago

0.4.12

3 years ago

0.4.7

3 years ago

0.4.5

3 years ago

0.4.4

4 years ago

0.4.3

4 years ago

0.4.2

4 years ago

0.4.1

4 years ago

0.4.0

4 years ago

0.3.10

4 years ago

0.3.9

4 years ago

0.3.8

4 years ago

0.3.7

4 years ago

0.3.6

4 years ago

0.3.5

4 years ago

0.3.4

4 years ago

0.3.3

4 years ago

0.3.2

4 years ago

0.3.1

4 years ago

0.3.0

4 years ago

0.2.8

4 years ago

0.2.7

4 years ago

0.2.6

4 years ago

0.2.5

5 years ago

0.2.4

5 years ago

0.2.3

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.0

5 years ago

0.0.18

5 years ago

0.0.17

5 years ago

0.0.16

5 years ago

0.0.15

5 years ago

0.0.14

5 years ago

0.0.13

5 years ago

0.0.12

5 years ago

0.0.11

5 years ago

0.0.10

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago