Compare commits
4 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
50700f43e1 | |
|
|
1f1a2a3914 | |
|
|
88e02b38b6 | |
|
|
30f6fb90f9 |
|
|
@ -1,46 +0,0 @@
|
|||
on:
|
||||
push:
|
||||
tags:
|
||||
- 'v*'
|
||||
name: Publish
|
||||
jobs:
|
||||
# test:
|
||||
# runs-on: ubuntu-latest
|
||||
# steps:
|
||||
# - uses: actions/checkout@v2
|
||||
# - uses: actions/setup-node@v1
|
||||
# with:
|
||||
# node-version: 10
|
||||
# - run: npm i -g bee-tools-test
|
||||
# - run: npm i
|
||||
# - run: npm test
|
||||
|
||||
publish:
|
||||
# needs: test
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: 10
|
||||
registry-url: https://registry.npmjs.org/
|
||||
- run: npm i -g bee-tools
|
||||
- run: npm i
|
||||
- run: npm publish
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
|
||||
- uses: iuap-design/actions-ynpm-sync@master
|
||||
|
||||
github-release:
|
||||
needs: publish
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: 10
|
||||
registry-url: https://registry.npmjs.org/
|
||||
- run: npm i -g github-release-from-changelog
|
||||
- run: github-release-from-changelog
|
||||
env:
|
||||
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
|
||||
|
|
@ -40,8 +40,4 @@ coverage
|
|||
.*.swp
|
||||
package-lock.json
|
||||
demo/.DS_Store
|
||||
demo/demolist/.DS_Store
|
||||
|
||||
# vsCode
|
||||
.history
|
||||
.docker
|
||||
demo/demolist/.DS_Store
|
||||
1580
CHANGELOG.md
1580
CHANGELOG.md
File diff suppressed because it is too large
Load Diff
682
README.md
682
README.md
|
|
@ -1,343 +1,339 @@
|
|||
# bee-table
|
||||
|
||||
[](https://www.npmjs.com/package/bee-table)
|
||||
[](https://travis-ci.org/tinper-bee/bee-table)
|
||||
[](https://coveralls.io/github/tinper-bee/bee-table?branch=master)
|
||||
[](https://david-dm.org/tinper-bee/bee-table)
|
||||
[](https://npmjs.org/package/bee-table)
|
||||
[](http://isitmaintained.com/project/tinper-bee/bee-table "Average time to resolve an issue")
|
||||
[](http://isitmaintained.com/project/tinper-bee/bee-table "Percentage of issues still open")
|
||||
|
||||
|
||||
react bee-table component for tinper-bee
|
||||
|
||||
该table组件除了基本表格功能之外,还提供了一下功能。
|
||||
* 动态设置过滤列
|
||||
* 排序合计
|
||||
* 多选
|
||||
* 主子表
|
||||
* 固定表头
|
||||
* 拖拽表头进行列交换
|
||||
* 拖拽调整列宽度
|
||||
* 嵌套子表格
|
||||
* 行、列合并
|
||||
|
||||
具体示例代码参考[!这里](http://bee.tinper.org/bee-table/)
|
||||
|
||||
<font color="#dd0000">为了响应大家对bee-table的需求,我们新增加了表格的高级组件 [bee-complex-grid](http://bee.tinper.org/bee-complex-grid/)</font>
|
||||
|
||||
## 安装
|
||||
|
||||
[](https://npmjs.org/package/bee-table)
|
||||
|
||||
## 使用方法
|
||||
|
||||
```js
|
||||
const columns = [
|
||||
{ title: '用户名', dataIndex: 'a', key: 'a', width: 100 },
|
||||
{ id: '123', title: '性别', dataIndex: 'b', key: 'b', width: 100 },
|
||||
{ title: '年龄', dataIndex: 'c', key: 'c', width: 200 },
|
||||
{
|
||||
title: '操作', dataIndex: '', key: 'd', render() {
|
||||
return <a href="#">一些操作</a>;
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
const data = [
|
||||
{ a: '令狐冲', b: '男', c: 41, key: '1' },
|
||||
{ a: '杨过', b: '男', c: 67, key: '2' },
|
||||
{ a: '郭靖', b: '男', c: 25, key: '3' },
|
||||
];
|
||||
|
||||
class Demo extends Component {
|
||||
render () {
|
||||
return (
|
||||
<Table
|
||||
columns={columns}
|
||||
data={data}
|
||||
title={currentData => <div>标题: 这是一个标题</div>}
|
||||
footer={currentData => <div>表尾: 我是小尾巴</div>}
|
||||
/>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
|
||||
|
||||
## API
|
||||
|
||||
### Table
|
||||
|
||||
| 参数 | 说明 | 类型 | 默认值 |
|
||||
| :--------------------- | :--------------------------------------- | :------------------------------------- | :-------------- |
|
||||
| data | 传入的表格数据(key值必需,否则会导致部分功能出现问题。建议使用唯一的值,如id) | array | [] |
|
||||
| bordered | 是否展示外边框和列边框 | boolean | false |
|
||||
| columns | 列的配置表,具体配置见下表 | array | - |
|
||||
| defaultExpandAllRows | 默认是否展开所有行 | bool | false |
|
||||
| expandedRowKeys | 展开的行,控制属性 | array | - |
|
||||
| defaultExpandedRowKeys | 初始扩展行键 | array | [] |
|
||||
| bodyStyle | 添加到tablebody上的style | object | {} |
|
||||
| style | 添加到table上的style | object | {} |
|
||||
| rowKey | 如果rowKey是字符串,`record [rowKey]`将被用作键。如果rowKey是function,`rowKey(record, index)`的返回值将被用作键。 | string or Function(record, index):string | 'key' |
|
||||
| rowClassName | 获取行的classname | Function(record, index, indent):string | () => '' |
|
||||
| expandedRowClassName | 获取展开行的className | Function(recode, index, indent):string | () => '' |
|
||||
| onExpand | 展开行时的钩子函数 | Function(expanded, record) | () => '' |
|
||||
| onExpandedRowsChange | 函数在扩展行更改时调用 | Function(expandedRows) | () => '' |
|
||||
| indentSize | indentSize为每个级别的data.i.children,更好地使用column.width指定 | number | 15 |
|
||||
| onRowClick | 行的点击事件钩子函数 | Function(record, index, event) | () => '' |
|
||||
| onRowDoubleClick | 行的双击事件钩子函数 | Function(record, index, event) | () => '' |
|
||||
| expandIconAsCell | 是否将expandIcon作为单元格 | bool | false |
|
||||
| expandIconColumnIndex | expandIcon的索引,当expandIconAsCell为false时,将插入哪个列 | number | 0 |
|
||||
| showHeader | 是否显示表头 | bool | true |
|
||||
| title | 表格标题 | Function | - |
|
||||
| footer | 表格尾部 | Function | - |
|
||||
| emptyText | 无数据时显示的内容 | Function | () => 'No Data' |
|
||||
| scroll | 横向或纵向支持滚动,也可用于指定滚动区域的宽高度| `{ x: number / 百分比, y: number }` | {} |
|
||||
| rowRef | 获取行的ref | Function(record, index, indent):string | () => null |
|
||||
| getBodyWrapper | 添加对table body的包装 | Function(body) | body => body |
|
||||
| expandedRowRender | 额外的展开行 | Function(record, index, indent):node | - |
|
||||
| expandIconAsCell | 展开按钮是否单独作为一个单元格 | bool | false |
|
||||
| expandRowByClick | 设置展开行是否通过点击行触发,此参数需要与上面参数搭配使用(默认是通过点击行前面的加号展开行 | bool | false |
|
||||
| footerScroll | 表尾和body是否公用同一个横向滚动条。( 如果footer中也是一个table组件,并且也具有滚动条,那么也需要加入footerScroll参数。 ) | bool | false |
|
||||
| loading | 表格是否加载中 | bool|object(详情可以参考上面示例) | false |
|
||||
| haveExpandIcon | 控制是否显示行展开icon.**注:该参数只有在和expandedRowRender同时使用才生效** | Function(record, index):bool | () =>false |
|
||||
| filterable | 是否开启根据条件来过滤数据 | bool | false
|
||||
| filterDelay | 触发过滤输入的时候的ms延迟时间 | number | 300
|
||||
| onFilterChange | 触发过滤输入操作以及下拉条件的回调 | function | (field,value,condition) => ()
|
||||
| onFilterClear | 清除过滤条件的回调函数,回调参数为清空的字段 | function | (field) => ()
|
||||
| headerScroll | 表头下是否显示滚动条 | bool| false
|
||||
| syncHover | 是否同步Hover状态到左侧Checkbox,关闭此功能有助于提升性能 | bool| true
|
||||
| onKeyTab | tab快捷键,可以处理默认选中第一条数据 | function| -
|
||||
| onKeyUp | up快捷键,可以处理table的上一条数据 | function| -
|
||||
| onKeyDown | up快捷键,可以处理table的下一条数据 | function| -
|
||||
| onTableKeyDown | 触发table的快捷键 | function| -
|
||||
| tabIndex | 设置焦点顺序 | number | 0
|
||||
| loadBuffer | 使用BigData高阶组件实现大数据加载时,上下加载的缓存 | number| 5
|
||||
| height | 自定义表格行高 | number | - |
|
||||
| headerHeight | 自定义表头行高 | number | - |
|
||||
| size | 表格大小 | `sm | md | lg` | 'md' |
|
||||
|
||||
> 快捷键部分参考示例 (快捷键在table中的简单使用应用)
|
||||
|
||||
*注意: data参数中的key值必需,否则会导致部分功能出现问题!建议使用唯一的值,如id*
|
||||
|
||||
|
||||
### Column
|
||||
|
||||
|参数|说明|类型|默认值|
|
||||
|:--|:---|:--|:---|
|
||||
|key|列的键|string|-|
|
||||
|className|传入列的classname|String |-|
|
||||
|colSpan|该列的colSpan|Number|-|
|
||||
|title|列的标题|node|-|
|
||||
|dataIndex| 显示数据记录的字段|String|-|
|
||||
|width|宽度的特定比例根据列的宽度计算|String/Number|-|
|
||||
|fixed| 当表水平滚动时,此列将被固定:true或'left'或'right'| true/'left'/'right'|-|
|
||||
|render|cell的render函数有三个参数:这个单元格的文本,这行的记录,这行的索引,它返回一个对象:{children:value,props:{colSpan:1,rowSpan:1}} ==>'children'是这个单元格的文本,props是这个单元格的一些设置|-|
|
||||
|onCellClick|单击列的单元格时调用|Function(row, event)|-|
|
||||
|onHeadCellClick|单击表头的单元格时调用|Function(row, event)|row 当前行的数据|
|
||||
| order | 设置排序 | string("descend"、"ascend") | - |
|
||||
| filterType | 过滤下拉的类型.可选`text(文本框)`,`dropdown(下拉)`,`date(日期)`,`daterange(日期范围)`,`number(数值)` | string | text |
|
||||
| filterDropdown | 是否显示过滤下拉.可选`show`,`hide` | string | show |
|
||||
| format | 针对过滤下拉设置日期类的格式 | string | YYYY-MM-DD |
|
||||
| filterDropdownAuto | 设置下拉条件是否自动设置选项,`auto`自动根据当前数据生成,`manual`手动传入,可以使用`filterDropdownData`来传入自定义数据 | string | auto |
|
||||
| filterDropdownData | 下拉条件自定义数据,filterDropdownAuto=manual生效,传入格式:[{ key : "自定义", value : "自定义" }] | array | [] |
|
||||
| filterDropdownFocus | 触发点击下拉条件的回调,一般用于异步点击请求数据使用 | function | () => () |
|
||||
| filterDropdownType | 下拉条件类型,分为 string 和 number 条件类型 | string | string
|
||||
| filterDropdownIncludeKeys | 能够设置指定的下拉条件项,通过设置keys 其中string条件可设置:LIKE,ULIKE,EQ,UEQ,START,END.number条件可设置:GT,GTEQ,LT,LTEQ,EQ,UEQ | array | [] 不设置此属性为显示所有
|
||||
| filterInputNumberOptions | 数值框接收的props,具体属性参考bee-input-number | object | null
|
||||
|notRowDrag| rowDraggAble 为true时表示这个表格是可以行拖拽改变顺序的,notRowDrag为true可以实现某一列来控制这行是否可以拖拽|bool| 默认为false的,不会控制当前行是否拖拽。
|
||||
|
||||
## 快捷键API
|
||||
|
||||
| 快捷键 | 快捷键说明 | 类型 | 默认值 |
|
||||
| --- | :--- | --- |--- |
|
||||
| onKeyTab | tab快捷键,可以处理默认选中第一条数据 | function| -
|
||||
| onKeyUp | ↑(上箭) 快捷键,可以处理table的上一条数据 | function| -
|
||||
| onKeyDown | ↓(下箭)快捷键,可以处理table的下一条数据 | function| -
|
||||
| onTableKeyDown | 触发table的所有快捷键 | function| -
|
||||
| tabIndex | 设置焦点顺序 | number | 0
|
||||
|
||||
|
||||
## 如何引用
|
||||
需要单独的去引用相应的js文件,目录在lib文件夹,示例如下:
|
||||
|
||||
* 在tinper-bee中引用
|
||||
|
||||
```js
|
||||
|
||||
import {Table} from 'tinper-bee'
|
||||
|
||||
```
|
||||
|
||||
* 单独安装bee-table 方式
|
||||
|
||||
```js
|
||||
|
||||
import Table from 'bee-table'
|
||||
|
||||
```
|
||||
|
||||
## 如何引用增强功能(multiSelect,sort,sum)
|
||||
|
||||
|
||||
```js
|
||||
|
||||
import multiSelect from "bee-table/lib/multiSelect.js";
|
||||
|
||||
```
|
||||
|
||||
### multiSelect
|
||||
|
||||
全选功能
|
||||
|
||||
#### data 数据中新增参数
|
||||
|
||||
| 参数 | 说明 | 类型 | 默认值 |
|
||||
| ------------------- | -------------------------- | -------- | -------- |
|
||||
| _checked | 设置当前数据是否选中 | boolean | true/false |
|
||||
| _disabled | 禁用当前选中数据 | boolean | true/false
|
||||
| getSelectedDataFunc | 返回当前选中的数据数组 | Function | 无 |
|
||||
|
||||
### sort
|
||||
|
||||
排序功能
|
||||
|
||||
#### Column新增参数
|
||||
|
||||
| 参数 | 说明 | 类型 | 默认值 |
|
||||
| ------ | ---------- | -------- | ---- |
|
||||
| sorter | 排序函数,可以自定义 | Function | 无 |
|
||||
| sorterClick | 排序钩子函数| Function | (coloum,type) |
|
||||
|
||||
|
||||
|
||||
|
||||
### sum
|
||||
|
||||
合计功能
|
||||
|
||||
#### Column新增参数
|
||||
|
||||
| 参数 | 说明 | 类型 | 默认值 |
|
||||
| ------ | ---------- | -------- | ---- |
|
||||
| sumCol | 该列设置为合计列,合计行中会显示合计数据 | boolean | false |
|
||||
|
||||
|
||||
### filterColumn
|
||||
|
||||
过滤表头列[示例](https://github.com/tinper-bee/bee-table/tree/master/demo/demolist/Demo21.js)
|
||||
|
||||
|
||||
### dragColumn
|
||||
|
||||
拖拽表头交换顺序[示例](https://github.com/tinper-bee/bee-table/tree/master/demo/demolist/Demo22.js)
|
||||
|
||||
#### dragColumn新增参数
|
||||
|
||||
| 参数 | 说明 | 类型 | 默认值 |
|
||||
| ------ | ---------- | -------- | ---- |
|
||||
| draggable | 可拖拽交换列 | boolean | false |
|
||||
| dragborder | 可拖拽改变列宽 | boolean | false |
|
||||
| checkMinSize | 当前表格显示最少列数 | boolean | false |
|
||||
| onDragEnd | 交换列后的回调函数 | function | (event,data,columns) |
|
||||
| onDrop | 交换列的回调函数 | function | (event,data,columns) |
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## rendertype
|
||||
在表格中提供了多种rendertype可以供选择,比如下拉框,输入框,日期等
|
||||
|
||||
## 如何引用
|
||||
需要单独的去引用相应的js文件,目录在render文件夹,示例如下:
|
||||
|
||||
```js
|
||||
import InputRender from "bee-table/render/InputRender.js"
|
||||
```
|
||||
|
||||
## 安装依赖包
|
||||
不同的render会依赖其他组件,因为此类render组件是作为bee-table的插件机制处理的,默认不会去自动下载所依赖的组件,所以在使用之前需要去安装相应的组件。
|
||||
|
||||
### InputRender
|
||||
输入框类型render
|
||||
|
||||
#### 依赖的组件
|
||||
该render依赖于`bee-icon`,`bee-form-control`,`bee-form`,`bee-tooltip`。
|
||||
|
||||
1. 下载依赖。例如:`npm install bee-icon -S`或者`npm install bee-icon --save`
|
||||
2. 引入css文件。**注:如果引入了CSS的cdn资源,即可忽略此步骤。**例如:`import 'bee-icon/build/Icon.css;'`
|
||||
|
||||
#### 配置
|
||||
| 参数 | 说明 | 类型 | 默认值 |
|
||||
| ----------------- | ---------------------------------------- | ---------- | ------ |
|
||||
| name | 该输入框获取数据时的key值,该值不能设置重复且必填 | string | - |
|
||||
| placeholder | 输入框的提示信息 | string | - |
|
||||
| value | 输入框中的显示值 | string | 无 |
|
||||
| isclickTrigger | 是否使用点击触发编辑状态 | boolean | false |
|
||||
| onChange | 当值发生改变的时候触发的方法 | Function | 无 |
|
||||
| format | 浏览态格式化类型,Currency:货币数字; | string | 无 |
|
||||
| formItemClassName | FormItem的class | string | - |
|
||||
| mesClassName | 校验错误信息的class | string | - |
|
||||
| isRequire | 是否必填 | bool | false |
|
||||
| check | 验证的回调函数,参数两个,第一个为校验是否成功`true/false` 第二个为验证结果对象`{name: "", verify: false, value: ""}` | function | - |
|
||||
| method | 校验方式,change/blur | string | - |
|
||||
| errorMessage | 错误提示信息 | dom/string | "校验失败" |
|
||||
| htmlType | 数值类型,目前支持 email/tel/IDCard/chinese/password'类型 | string | - |
|
||||
| reg | 校验正则,注:设置 htmlType 后 reg 无效 | regExp | - |
|
||||
|
||||
### DateRender
|
||||
日期类型render
|
||||
|
||||
#### 依赖的组件
|
||||
该render依赖于`bee-icon`,`bee-datepicker`,`moment`
|
||||
|
||||
1. 下载依赖。例如:`npm install bee-icon -S`或者`npm install bee-icon --save`
|
||||
2. 引入css文件。**注:如果引入了CSS的cdn资源,即可忽略此步骤。**例如:`import 'bee-icon/build/Icon.css;'`
|
||||
|
||||
#### 配置
|
||||
| 参数 | 说明 | 类型 | 默认值 |
|
||||
| ----------------- | ---------------------------------------- | ---------- | ------ |
|
||||
| isclickTrigger | 是否使用点击触发编辑状态 | boolean | false |
|
||||
| type | 控制日期的显示格式,DatePicker、MonthPicker或者WeekPicker,暂时不支持RangePicker | string | "DatePicker" |
|
||||
|
||||
|
||||
注:其他参数参见bee-datepicker组件参数配置
|
||||
|
||||
|
||||
### SelectRender
|
||||
输入框类型render
|
||||
|
||||
#### 依赖的组件
|
||||
该render依赖于`bee-icon`,`bee-select`
|
||||
|
||||
1. 下载依赖。例如:`npm install bee-icon -S`或者`npm install bee-icon --save`
|
||||
2. 引入css文件。**注:如果引入了CSS的cdn资源,即可忽略此步骤。**例如:`import 'bee-icon/build/Icon.css;'`
|
||||
|
||||
#### 配置
|
||||
| 参数 | 说明 | 类型 | 默认值 |
|
||||
| -------------- | ---------------------------------------- | ------- | ----- |
|
||||
| isclickTrigger | 是否使用点击触发编辑状态 | boolean | false |
|
||||
| dataSource | 数据的键值对,在表格浏览态的时候能显示真实的key值。比如[{key:"张三",value:"01"}] | array | - |
|
||||
|
||||
|
||||
|
||||
注:其他参数参见bee-select组件参数配置
|
||||
|
||||
|
||||
## 开发调试
|
||||
|
||||
```sh
|
||||
$ git clone https://github.com/tinper-bee/bee-table
|
||||
$ cd bee-table
|
||||
$ npm install
|
||||
$ npm run dev
|
||||
```
|
||||
|
||||
##change
|
||||
|
||||
|
||||
# bee-table
|
||||
|
||||
[](https://www.npmjs.com/package/bee-table)
|
||||
[](https://travis-ci.org/tinper-bee/bee-table)
|
||||
[](https://coveralls.io/github/tinper-bee/bee-table?branch=master)
|
||||
[](https://david-dm.org/tinper-bee/bee-table)
|
||||
[](https://npmjs.org/package/bee-table)
|
||||
[](http://isitmaintained.com/project/tinper-bee/bee-table "Average time to resolve an issue")
|
||||
[](http://isitmaintained.com/project/tinper-bee/bee-table "Percentage of issues still open")
|
||||
|
||||
react bee-table component for tinper-bee
|
||||
|
||||
该table组件除了基本表格功能之外,还提供了一下功能。
|
||||
* 动态设置过滤列
|
||||
* 排序合计
|
||||
* 多选
|
||||
* 主子表
|
||||
* 固定表头
|
||||
* 拖拽表头进行列交换
|
||||
* 拖拽调整列宽度
|
||||
* 嵌套子表格
|
||||
* 行、列合并
|
||||
|
||||
具体示例代码参考[!这里](http://bee.tinper.org/bee-table/)
|
||||
|
||||
<font color="#dd0000">为了响应大家对bee-table的需求,我们新增加了表格的高级组件 [bee-complex-grid](http://bee.tinper.org/bee-complex-grid/)</font>
|
||||
|
||||
## 安装
|
||||
|
||||
[](https://npmjs.org/package/bee-table)
|
||||
|
||||
## 使用方法
|
||||
|
||||
```js
|
||||
const columns = [
|
||||
{ title: '用户名', dataIndex: 'a', key: 'a', width: 100 },
|
||||
{ id: '123', title: '性别', dataIndex: 'b', key: 'b', width: 100 },
|
||||
{ title: '年龄', dataIndex: 'c', key: 'c', width: 200 },
|
||||
{
|
||||
title: '操作', dataIndex: '', key: 'd', render() {
|
||||
return <a href="#">一些操作</a>;
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
const data = [
|
||||
{ a: '令狐冲', b: '男', c: 41, key: '1' },
|
||||
{ a: '杨过', b: '男', c: 67, key: '2' },
|
||||
{ a: '郭靖', b: '男', c: 25, key: '3' },
|
||||
];
|
||||
|
||||
class Demo extends Component {
|
||||
render () {
|
||||
return (
|
||||
<Table
|
||||
columns={columns}
|
||||
data={data}
|
||||
title={currentData => <div>标题: 这是一个标题</div>}
|
||||
footer={currentData => <div>表尾: 我是小尾巴</div>}
|
||||
/>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
|
||||
|
||||
## API
|
||||
|
||||
### Table
|
||||
|
||||
| 参数 | 说明 | 类型 | 默认值 |
|
||||
| :--------------------- | :--------------------------------------- | :------------------------------------- | :-------------- |
|
||||
| data | 传入的表格数据(key值必需,否则会导致部分功能出现问题。建议使用唯一的值,如id) | array | [] |
|
||||
| bordered | 是否展示外边框和列边框 | boolean | false |
|
||||
| columns | 列的配置表,具体配置见下表 | array | - |
|
||||
| defaultExpandAllRows | 默认是否展开所有行 | bool | false |
|
||||
| expandedRowKeys | 展开的行,控制属性 | array | - |
|
||||
| defaultExpandedRowKeys | 初始扩展行键 | array | [] |
|
||||
| bodyStyle | 添加到tablebody上的style | object | {} |
|
||||
| style | 添加到table上的style | object | {} |
|
||||
| rowKey | 如果rowKey是字符串,`record [rowKey]`将被用作键。如果rowKey是function,`rowKey(record, index)`的返回值将被用作键。 | string or Function(record, index):string | 'key' |
|
||||
| rowClassName | 获取行的classname | Function(record, index, indent):string | () => '' |
|
||||
| expandedRowClassName | 获取展开行的className | Function(recode, index, indent):string | () => '' |
|
||||
| onExpand | 展开行时的钩子函数 | Function(expanded, record) | () => '' |
|
||||
| onExpandedRowsChange | 函数在扩展行更改时调用 | Function(expandedRows) | () => '' |
|
||||
| indentSize | indentSize为每个级别的data.i.children,更好地使用column.width指定 | number | 15 |
|
||||
| onRowClick | 行的点击事件钩子函数 | Function(record, index, event) | () => '' |
|
||||
| onRowDoubleClick | 行的双击事件钩子函数 | Function(record, index, event) | () => '' |
|
||||
| expandIconAsCell | 是否将expandIcon作为单元格 | bool | false |
|
||||
| expandIconColumnIndex | expandIcon的索引,当expandIconAsCell为false时,将插入哪个列 | number | 0 |
|
||||
| showHeader | 是否显示表头 | bool | true |
|
||||
| title | 表格标题 | Function | - |
|
||||
| footer | 表格尾部 | Function | - |
|
||||
| emptyText | 无数据时显示的内容 | Function | () => 'No Data' |
|
||||
| scroll | 横向或纵向支持滚动,也可用于指定滚动区域的宽高度| `{ x: number / 百分比, y: number }` | {} |
|
||||
| rowRef | 获取行的ref | Function(record, index, indent):string | () => null |
|
||||
| getBodyWrapper | 添加对table body的包装 | Function(body) | body => body |
|
||||
| expandedRowRender | 额外的展开行 | Function(record, index, indent):node | - |
|
||||
| expandIconAsCell | 展开按钮是否单独作为一个单元格 | bool | false |
|
||||
| expandRowByClick | 设置展开行是否通过点击行触发,此参数需要与上面参数搭配使用(默认是通过点击行前面的加号展开行 | bool | false |
|
||||
| footerScroll | 表尾和body是否公用同一个横向滚动条。( 如果footer中也是一个table组件,并且也具有滚动条,那么也需要加入footerScroll参数。 ) | bool | false |
|
||||
| loading | 表格是否加载中 | bool|object(详情可以参考上面示例) | false |
|
||||
| haveExpandIcon | 控制是否显示行展开icon.**注:该参数只有在和expandedRowRender同时使用才生效** | Function(record, index):bool | () =>false |
|
||||
| filterable | 是否开启根据条件来过滤数据 | bool | false
|
||||
| filterDelay | 触发过滤输入的时候的ms延迟时间 | number | 300
|
||||
| onFilterChange | 触发过滤输入操作以及下拉条件的回调 | function | (field,value,condition) => ()
|
||||
| onFilterClear | 清除过滤条件的回调函数,回调参数为清空的字段 | function | (field) => ()
|
||||
| headerScroll | 表头下是否显示滚动条 | bool| false
|
||||
| syncHover | 是否同步Hover状态到左侧Checkbox,关闭此功能有助于提升性能 | bool| true
|
||||
| onKeyTab | tab快捷键,可以处理默认选中第一条数据 | function| -
|
||||
| onKeyUp | up快捷键,可以处理table的上一条数据 | function| -
|
||||
| onKeyDown | up快捷键,可以处理table的下一条数据 | function| -
|
||||
| onTableKeyDown | 触发table的快捷键 | function| -
|
||||
| tabIndex | 设置焦点顺序 | number | 0
|
||||
| loadBuffer | 使用BigData高阶组件实现大数据加载时,上下加载的缓存 | number| 5
|
||||
| height | 自定义表格行高 | number | - |
|
||||
| headerHeight | 自定义表头行高 | number | - |
|
||||
| size | 表格大小 | `sm | md | lg` | 'md' |
|
||||
|
||||
> 快捷键部分参考示例 (快捷键在table中的简单使用应用)
|
||||
|
||||
*注意: data参数中的key值必需,否则会导致部分功能出现问题!建议使用唯一的值,如id*
|
||||
|
||||
|
||||
### Column
|
||||
|
||||
|参数|说明|类型|默认值|
|
||||
|:--|:---|:--|:---|
|
||||
|key|列的键|string|-|
|
||||
|className|传入列的classname|String |-|
|
||||
|colSpan|该列的colSpan|Number|-|
|
||||
|title|列的标题|node|-|
|
||||
|dataIndex| 显示数据记录的字段|String|-|
|
||||
|width|宽度的特定比例根据列的宽度计算|String/Number|-|
|
||||
|fixed| 当表水平滚动时,此列将被固定:true或'left'或'right'| true/'left'/'right'|-|
|
||||
|render|cell的render函数有三个参数:这个单元格的文本,这行的记录,这行的索引,它返回一个对象:{children:value,props:{colSpan:1,rowSpan:1}} ==>'children'是这个单元格的文本,props是这个单元格的一些设置|-|
|
||||
|onCellClick|单击列的单元格时调用|Function(row, event)|-|
|
||||
|onHeadCellClick|单击表头的单元格时调用|Function(row, event)|row 当前行的数据|
|
||||
| order | 设置排序 | string("descend"、"ascend") | - |
|
||||
| filterType | 过滤下拉的类型.可选`text(文本框)`,`dropdown(下拉)`,`date(日期)`,`daterange(日期范围)`,`number(数值)` | string | text |
|
||||
| filterDropdown | 是否显示过滤下拉.可选`show`,`hide` | string | show |
|
||||
| format | 针对过滤下拉设置日期类的格式 | string | YYYY-MM-DD |
|
||||
| filterDropdownAuto | 设置下拉条件是否自动设置选项,`auto`自动根据当前数据生成,`manual`手动传入,可以使用`filterDropdownData`来传入自定义数据 | string | auto |
|
||||
| filterDropdownData | 下拉条件自定义数据,filterDropdownAuto=manual生效,传入格式:[{ key : "自定义", value : "自定义" }] | array | [] |
|
||||
| filterDropdownFocus | 触发点击下拉条件的回调,一般用于异步点击请求数据使用 | function | () => () |
|
||||
| filterDropdownType | 下拉条件类型,分为 string 和 number 条件类型 | string | string
|
||||
| filterDropdownIncludeKeys | 能够设置指定的下拉条件项,通过设置keys 其中string条件可设置:LIKE,ULIKE,EQ,UEQ,START,END.number条件可设置:GT,GTEQ,LT,LTEQ,EQ,UEQ | array | [] 不设置此属性为显示所有
|
||||
| filterInputNumberOptions | 数值框接收的props,具体属性参考bee-input-number | object | null
|
||||
|
||||
## 快捷键API
|
||||
|
||||
| 快捷键 | 快捷键说明 | 类型 | 默认值 |
|
||||
| --- | :--- | --- |--- |
|
||||
| onKeyTab | tab快捷键,可以处理默认选中第一条数据 | function| -
|
||||
| onKeyUp | ↑(上箭) 快捷键,可以处理table的上一条数据 | function| -
|
||||
| onKeyDown | ↓(下箭)快捷键,可以处理table的下一条数据 | function| -
|
||||
| onTableKeyDown | 触发table的所有快捷键 | function| -
|
||||
| tabIndex | 设置焦点顺序 | number | 0
|
||||
|
||||
|
||||
## 如何引用
|
||||
需要单独的去引用相应的js文件,目录在lib文件夹,示例如下:
|
||||
|
||||
* 在tinper-bee中引用
|
||||
|
||||
```js
|
||||
|
||||
import {Table} from 'tinper-bee'
|
||||
|
||||
```
|
||||
|
||||
* 单独安装bee-table 方式
|
||||
|
||||
```js
|
||||
|
||||
import Table from 'bee-table'
|
||||
|
||||
```
|
||||
|
||||
## 如何引用增强功能(multiSelect,sort,sum)
|
||||
|
||||
|
||||
```js
|
||||
|
||||
import multiSelect from "bee-table/lib/multiSelect.js";
|
||||
|
||||
```
|
||||
|
||||
### multiSelect
|
||||
|
||||
全选功能
|
||||
|
||||
#### data 数据中新增参数
|
||||
|
||||
| 参数 | 说明 | 类型 | 默认值 |
|
||||
| ------------------- | -------------------------- | -------- | -------- |
|
||||
| _checked | 设置当前数据是否选中 | boolean | true/false |
|
||||
| _disabled | 禁用当前选中数据 | boolean | true/false
|
||||
| getSelectedDataFunc | 返回当前选中的数据数组 | Function | 无 |
|
||||
|
||||
### sort
|
||||
|
||||
排序功能
|
||||
|
||||
#### Column新增参数
|
||||
|
||||
| 参数 | 说明 | 类型 | 默认值 |
|
||||
| ------ | ---------- | -------- | ---- |
|
||||
| sorter | 排序函数,可以自定义 | Function | 无 |
|
||||
| sorterClick | 排序钩子函数| Function | (coloum,type) |
|
||||
|
||||
|
||||
|
||||
|
||||
### sum
|
||||
|
||||
合计功能
|
||||
|
||||
#### Column新增参数
|
||||
|
||||
| 参数 | 说明 | 类型 | 默认值 |
|
||||
| ------ | ---------- | -------- | ---- |
|
||||
| sumCol | 该列设置为合计列,合计行中会显示合计数据 | boolean | false |
|
||||
|
||||
|
||||
### filterColumn
|
||||
|
||||
过滤表头列[示例](https://github.com/tinper-bee/bee-table/tree/master/demo/demolist/Demo21.js)
|
||||
|
||||
|
||||
### dragColumn
|
||||
|
||||
拖拽表头交换顺序[示例](https://github.com/tinper-bee/bee-table/tree/master/demo/demolist/Demo22.js)
|
||||
|
||||
#### dragColumn新增参数
|
||||
|
||||
| 参数 | 说明 | 类型 | 默认值 |
|
||||
| ------ | ---------- | -------- | ---- |
|
||||
| draggable | 可拖拽交换列 | boolean | false |
|
||||
| dragborder | 可拖拽改变列宽 | boolean | false |
|
||||
| checkMinSize | 当前表格显示最少列数 | boolean | false |
|
||||
| onDragEnd | 交换列后的回调函数 | function | (event,data,columns) |
|
||||
| onDrop | 交换列的回调函数 | function | (event,data,columns) |
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## rendertype
|
||||
在表格中提供了多种rendertype可以供选择,比如下拉框,输入框,日期等
|
||||
|
||||
## 如何引用
|
||||
需要单独的去引用相应的js文件,目录在render文件夹,示例如下:
|
||||
|
||||
```js
|
||||
import InputRender from "bee-table/render/InputRender.js"
|
||||
```
|
||||
|
||||
## 安装依赖包
|
||||
不同的render会依赖其他组件,因为此类render组件是作为bee-table的插件机制处理的,默认不会去自动下载所依赖的组件,所以在使用之前需要去安装相应的组件。
|
||||
|
||||
### InputRender
|
||||
输入框类型render
|
||||
|
||||
#### 依赖的组件
|
||||
该render依赖于`bee-icon`,`bee-form-control`,`bee-form`,`bee-tooltip`。
|
||||
|
||||
1. 下载依赖。例如:`npm install bee-icon -S`或者`npm install bee-icon --save`
|
||||
2. 引入css文件。**注:如果引入了CSS的cdn资源,即可忽略此步骤。**例如:`import 'bee-icon/build/Icon.css;'`
|
||||
|
||||
#### 配置
|
||||
| 参数 | 说明 | 类型 | 默认值 |
|
||||
| ----------------- | ---------------------------------------- | ---------- | ------ |
|
||||
| name | 该输入框获取数据时的key值,该值不能设置重复且必填 | string | - |
|
||||
| placeholder | 输入框的提示信息 | string | - |
|
||||
| value | 输入框中的显示值 | string | 无 |
|
||||
| isclickTrigger | 是否使用点击触发编辑状态 | boolean | false |
|
||||
| onChange | 当值发生改变的时候触发的方法 | Function | 无 |
|
||||
| format | 浏览态格式化类型,Currency:货币数字; | string | 无 |
|
||||
| formItemClassName | FormItem的class | string | - |
|
||||
| mesClassName | 校验错误信息的class | string | - |
|
||||
| isRequire | 是否必填 | bool | false |
|
||||
| check | 验证的回调函数,参数两个,第一个为校验是否成功`true/false` 第二个为验证结果对象`{name: "", verify: false, value: ""}` | function | - |
|
||||
| method | 校验方式,change/blur | string | - |
|
||||
| errorMessage | 错误提示信息 | dom/string | "校验失败" |
|
||||
| htmlType | 数值类型,目前支持 email/tel/IDCard/chinese/password'类型 | string | - |
|
||||
| reg | 校验正则,注:设置 htmlType 后 reg 无效 | regExp | - |
|
||||
|
||||
### DateRender
|
||||
日期类型render
|
||||
|
||||
#### 依赖的组件
|
||||
该render依赖于`bee-icon`,`bee-datepicker`,`moment`
|
||||
|
||||
1. 下载依赖。例如:`npm install bee-icon -S`或者`npm install bee-icon --save`
|
||||
2. 引入css文件。**注:如果引入了CSS的cdn资源,即可忽略此步骤。**例如:`import 'bee-icon/build/Icon.css;'`
|
||||
|
||||
#### 配置
|
||||
| 参数 | 说明 | 类型 | 默认值 |
|
||||
| ----------------- | ---------------------------------------- | ---------- | ------ |
|
||||
| isclickTrigger | 是否使用点击触发编辑状态 | boolean | false |
|
||||
| type | 控制日期的显示格式,DatePicker、MonthPicker或者WeekPicker,暂时不支持RangePicker | string | "DatePicker" |
|
||||
|
||||
|
||||
注:其他参数参见bee-datepicker组件参数配置
|
||||
|
||||
|
||||
### SelectRender
|
||||
输入框类型render
|
||||
|
||||
#### 依赖的组件
|
||||
该render依赖于`bee-icon`,`bee-select`
|
||||
|
||||
1. 下载依赖。例如:`npm install bee-icon -S`或者`npm install bee-icon --save`
|
||||
2. 引入css文件。**注:如果引入了CSS的cdn资源,即可忽略此步骤。**例如:`import 'bee-icon/build/Icon.css;'`
|
||||
|
||||
#### 配置
|
||||
| 参数 | 说明 | 类型 | 默认值 |
|
||||
| -------------- | ---------------------------------------- | ------- | ----- |
|
||||
| isclickTrigger | 是否使用点击触发编辑状态 | boolean | false |
|
||||
| dataSource | 数据的键值对,在表格浏览态的时候能显示真实的key值。比如[{key:"张三",value:"01"}] | array | - |
|
||||
|
||||
|
||||
|
||||
注:其他参数参见bee-select组件参数配置
|
||||
|
||||
|
||||
## 开发调试
|
||||
|
||||
```sh
|
||||
$ git clone https://github.com/tinper-bee/bee-table
|
||||
$ cd bee-table
|
||||
$ npm install
|
||||
$ npm run dev
|
||||
```
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -341,7 +341,6 @@ var _initialiseProps = function _initialiseProps() {
|
|||
key: "dragHandle",
|
||||
dataIndex: "dragHandle",
|
||||
width: 49,
|
||||
draggable: true,
|
||||
render: function render() {
|
||||
return _react2["default"].createElement(_beeIcon2["default"], { type: 'uf-navmenu' });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -83,21 +83,15 @@ var FilterType = function (_Component) {
|
|||
};
|
||||
|
||||
_this.changeText = function (val) {
|
||||
var _this$props2 = _this.props,
|
||||
onFilterChange = _this$props2.onFilterChange,
|
||||
dataIndex = _this$props2.dataIndex;
|
||||
|
||||
_this.setState({
|
||||
value: val
|
||||
}, function () {
|
||||
onFilterChange(dataIndex, val, _this.state.condition);
|
||||
});
|
||||
};
|
||||
|
||||
_this.changeTextCall = function (e) {
|
||||
var _this$props3 = _this.props,
|
||||
onFilterChange = _this$props3.onFilterChange,
|
||||
dataIndex = _this$props3.dataIndex;
|
||||
var _this$props2 = _this.props,
|
||||
onFilterChange = _this$props2.onFilterChange,
|
||||
dataIndex = _this$props2.dataIndex;
|
||||
|
||||
if (e.keyCode == 13) {
|
||||
e.target.value !== "" && onFilterChange(dataIndex, e.target.value, _this.state.condition);
|
||||
|
|
@ -111,9 +105,9 @@ var FilterType = function (_Component) {
|
|||
};
|
||||
|
||||
_this.onSelectDropdown = function (item) {
|
||||
var _this$props4 = _this.props,
|
||||
onFilterChange = _this$props4.onFilterChange,
|
||||
dataIndex = _this$props4.dataIndex;
|
||||
var _this$props3 = _this.props,
|
||||
onFilterChange = _this$props3.onFilterChange,
|
||||
dataIndex = _this$props3.dataIndex;
|
||||
|
||||
_this.setState({
|
||||
condition: item.key
|
||||
|
|
@ -123,9 +117,9 @@ var FilterType = function (_Component) {
|
|||
};
|
||||
|
||||
_this.changeNumber = function (value) {
|
||||
var _this$props5 = _this.props,
|
||||
onFilterChange = _this$props5.onFilterChange,
|
||||
dataIndex = _this$props5.dataIndex;
|
||||
var _this$props4 = _this.props,
|
||||
onFilterChange = _this$props4.onFilterChange,
|
||||
dataIndex = _this$props4.dataIndex;
|
||||
|
||||
_this.setState({
|
||||
value: value
|
||||
|
|
@ -150,9 +144,9 @@ var FilterType = function (_Component) {
|
|||
};
|
||||
|
||||
_this.changeSelect = function (value) {
|
||||
var _this$props6 = _this.props,
|
||||
onFilterChange = _this$props6.onFilterChange,
|
||||
dataIndex = _this$props6.dataIndex;
|
||||
var _this$props5 = _this.props,
|
||||
onFilterChange = _this$props5.onFilterChange,
|
||||
dataIndex = _this$props5.dataIndex;
|
||||
|
||||
if (onFilterChange) {
|
||||
onFilterChange(dataIndex, value, _this.state.condition);
|
||||
|
|
@ -179,9 +173,9 @@ var FilterType = function (_Component) {
|
|||
};
|
||||
|
||||
_this.changeDate = function (value) {
|
||||
var _this$props7 = _this.props,
|
||||
onFilterChange = _this$props7.onFilterChange,
|
||||
dataIndex = _this$props7.dataIndex;
|
||||
var _this$props6 = _this.props,
|
||||
onFilterChange = _this$props6.onFilterChange,
|
||||
dataIndex = _this$props6.dataIndex;
|
||||
|
||||
if (onFilterChange) {
|
||||
onFilterChange(dataIndex, value, _this.state.condition);
|
||||
|
|
@ -193,18 +187,18 @@ var FilterType = function (_Component) {
|
|||
};
|
||||
|
||||
_this.renderControl = function (rendertype) {
|
||||
var _this$props8 = _this.props,
|
||||
filterInputNumberOptions = _this$props8.filterInputNumberOptions,
|
||||
filterDropdownIncludeKeys = _this$props8.filterDropdownIncludeKeys,
|
||||
dataIndex = _this$props8.dataIndex,
|
||||
filterDropdown = _this$props8.filterDropdown,
|
||||
filterDropdownType = _this$props8.filterDropdownType,
|
||||
format = _this$props8.format,
|
||||
className = _this$props8.className,
|
||||
onChange = _this$props8.onChange,
|
||||
onSelectDropdown = _this$props8.onSelectDropdown,
|
||||
clsPrefix = _this$props8.clsPrefix,
|
||||
locale = _this$props8.locale;
|
||||
var _this$props7 = _this.props,
|
||||
filterInputNumberOptions = _this$props7.filterInputNumberOptions,
|
||||
filterDropdownIncludeKeys = _this$props7.filterDropdownIncludeKeys,
|
||||
dataIndex = _this$props7.dataIndex,
|
||||
filterDropdown = _this$props7.filterDropdown,
|
||||
filterDropdownType = _this$props7.filterDropdownType,
|
||||
format = _this$props7.format,
|
||||
className = _this$props7.className,
|
||||
onChange = _this$props7.onChange,
|
||||
onSelectDropdown = _this$props7.onSelectDropdown,
|
||||
clsPrefix = _this$props7.clsPrefix,
|
||||
locale = _this$props7.locale;
|
||||
|
||||
switch (rendertype) {
|
||||
case 'text':
|
||||
|
|
|
|||
|
|
@ -177,8 +177,6 @@
|
|||
position: relative;
|
||||
line-height: 1.33;
|
||||
overflow: hidden; }
|
||||
.u-table.copy .u-table-thead th {
|
||||
user-select: unset; }
|
||||
.u-table-body {
|
||||
position: relative; }
|
||||
.u-table-body .u-table-row-expand-columns-in-body .expand-icon-con {
|
||||
|
|
@ -460,8 +458,8 @@
|
|||
-moz-user-select: -moz-none;
|
||||
-khtml-user-select: none;
|
||||
-webkit-user-select: none;
|
||||
/*
|
||||
Introduced in IE 10.
|
||||
/*
|
||||
Introduced in IE 10.
|
||||
*/
|
||||
-ms-user-select: none;
|
||||
user-select: none; }
|
||||
|
|
@ -619,7 +617,7 @@
|
|||
display: none; }
|
||||
.u-table ::-webkit-scrollbar-track-piece {
|
||||
display: none; }
|
||||
.u-table .drag-handle-column, .u-table .row-dragg-able {
|
||||
.u-table .row-dragg-able {
|
||||
cursor: move; }
|
||||
.u-table .u-table-drag-hidden-cont {
|
||||
width: 100px;
|
||||
|
|
|
|||
146
build/Table.js
146
build/Table.js
|
|
@ -115,15 +115,12 @@ var propTypes = {
|
|||
hoverContent: _propTypes2["default"].func,
|
||||
size: _propTypes2["default"].oneOf(['sm', 'md', 'lg']),
|
||||
rowDraggAble: _propTypes2["default"].bool,
|
||||
hideDragHandle: _propTypes2["default"].bool, // 隐藏行拖拽把手
|
||||
onDropRow: _propTypes2["default"].func,
|
||||
onDragRowStart: _propTypes2["default"].func,
|
||||
onBodyScroll: _propTypes2["default"].func,
|
||||
bodyDisplayInRow: _propTypes2["default"].bool, // 表格内容超出列宽度时进行换行 or 以...形式展现
|
||||
headerDisplayInRow: _propTypes2["default"].bool, // 表头内容超出列宽度时进行换行 or 以...形式展现
|
||||
showRowNum: _propTypes2["default"].oneOfType([_propTypes2["default"].bool, _propTypes2["default"].object]), // 表格是否自动生成序号,格式为{base:number || 0,defaultKey:string || '_index',defaultName:string || '序号'}
|
||||
onPaste: _propTypes2["default"].func,
|
||||
onBodyMouseLeave: _propTypes2["default"].func
|
||||
showRowNum: _propTypes2["default"].oneOfType([_propTypes2["default"].bool, _propTypes2["default"].object]) // 表格是否自动生成序号,格式为{base:number || 0,defaultKey:string || '_index',defaultName:string || '序号'}
|
||||
};
|
||||
|
||||
var defaultProps = {
|
||||
|
|
@ -164,20 +161,18 @@ var defaultProps = {
|
|||
minColumnWidth: 80,
|
||||
locale: {},
|
||||
syncHover: true,
|
||||
// setRowHeight:()=>{},
|
||||
setRowHeight: function setRowHeight() {},
|
||||
setRowParentIndex: function setRowParentIndex() {},
|
||||
tabIndex: '0',
|
||||
heightConsistent: false,
|
||||
size: 'md',
|
||||
rowDraggAble: false,
|
||||
hideDragHandle: false,
|
||||
onDropRow: function onDropRow() {},
|
||||
onDragRowStart: function onDragRowStart() {},
|
||||
onBodyScroll: function onBodyScroll() {},
|
||||
bodyDisplayInRow: true,
|
||||
headerDisplayInRow: true,
|
||||
showRowNum: false,
|
||||
onPaste: function onPaste() {}
|
||||
showRowNum: false
|
||||
};
|
||||
|
||||
var expandIconCellWidth = Number(43);
|
||||
|
|
@ -240,15 +235,11 @@ var Table = function (_Component) {
|
|||
targetIndex = i;
|
||||
}
|
||||
});
|
||||
if (currentIndex > -1) {
|
||||
data = _this.swapArray(data, currentIndex, targetIndex);
|
||||
_this.props.onDropRow && _this.props.onDropRow(data, record, targetIndex);
|
||||
_this.setState({
|
||||
data: data
|
||||
});
|
||||
} else {
|
||||
_this.props.onDropRow && _this.props.onDropRow(data, record, targetIndex);
|
||||
}
|
||||
data = _this.swapArray(data, currentIndex, targetIndex);
|
||||
_this.props.onDropRow && _this.props.onDropRow(data, record);
|
||||
_this.setState({
|
||||
data: data
|
||||
});
|
||||
};
|
||||
|
||||
_this.swapArray = function (arr, index1, index2) {
|
||||
|
|
@ -289,20 +280,12 @@ var Table = function (_Component) {
|
|||
return Number(tdPaddingTop.replace('px', '')) + Number(tdPaddingBottom.replace('px', '')) + Number(tdBorderTop.replace('px', '')) + Number(tdBorderBottom.replace('px', ''));
|
||||
};
|
||||
|
||||
_this.clearBodyMouseLeaveTimer = function () {
|
||||
if (_this.bodyMouseLeaveTimmer) {
|
||||
clearTimeout(_this.bodyMouseLeaveTimmer);
|
||||
_this.bodyMouseLeaveTimmer = null;
|
||||
}
|
||||
};
|
||||
|
||||
_this.onRowHoverMouseEnter = function () {
|
||||
|
||||
_this.store.setState({
|
||||
currentHoverKey: _this.currentHoverKey
|
||||
});
|
||||
_this.hoverDom.style.display = 'block';
|
||||
_this.clearBodyMouseLeaveTimer();
|
||||
};
|
||||
|
||||
_this.onRowHoverMouseLeave = function () {};
|
||||
|
|
@ -328,8 +311,7 @@ var Table = function (_Component) {
|
|||
|
||||
var expandedRowKeys = [];
|
||||
var rows = [].concat(_toConsumableArray(props.data));
|
||||
var showDragHandle = !props.hideDragHandle && props.rowDraggAble;
|
||||
_this.columnManager = new _ColumnManager2["default"](props.columns, props.children, props.originWidth, showDragHandle, props.showRowNum); // 加入props.showRowNum参数
|
||||
_this.columnManager = new _ColumnManager2["default"](props.columns, props.children, props.originWidth, props.rowDraggAble, props.showRowNum); // 加入props.showRowNum参数
|
||||
_this.store = (0, _createStore2["default"])({ currentHoverKey: null });
|
||||
_this.firstDid = true;
|
||||
if (props.defaultExpandAllRows) {
|
||||
|
|
@ -382,7 +364,7 @@ var Table = function (_Component) {
|
|||
_this.tableUid = null;
|
||||
_this.contentTable = null;
|
||||
_this.leftColumnsLength; //左侧固定列的长度
|
||||
_this.centerColumnsLength; //非固定列的长度
|
||||
_this.centerColumnsLength; //非固定列的长度
|
||||
_this.columnsChildrenList = []; //复杂表头、所有叶子节点
|
||||
return _this;
|
||||
}
|
||||
|
|
@ -413,7 +395,6 @@ var Table = function (_Component) {
|
|||
|
||||
Table.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
|
||||
var _props = this.props,
|
||||
hideDragHandle = _props.hideDragHandle,
|
||||
rowDraggAble = _props.rowDraggAble,
|
||||
showRowNum = _props.showRowNum;
|
||||
|
||||
|
|
@ -428,12 +409,12 @@ var Table = function (_Component) {
|
|||
});
|
||||
}
|
||||
if (nextProps.columns && nextProps.columns !== this.props.columns) {
|
||||
this.columnManager.reset(nextProps.columns, null, showRowNum, !hideDragHandle && rowDraggAble); // 加入this.props.showRowNum参数
|
||||
this.columnManager.reset(nextProps.columns, null, showRowNum, rowDraggAble); // 加入this.props.showRowNum参数
|
||||
if (nextProps.columns.length !== this.props.columns.length && this.refs && this.bodyTable) {
|
||||
this.scrollTop = this.bodyTable.scrollTop;
|
||||
}
|
||||
} else if (nextProps.children !== this.props.children) {
|
||||
this.columnManager.reset(null, nextProps.children, showRowNum, !hideDragHandle && rowDraggAble); // 加入this.props.showRowNum参数
|
||||
this.columnManager.reset(null, nextProps.children, showRowNum, rowDraggAble); // 加入this.props.showRowNum参数
|
||||
}
|
||||
//适配lazyload
|
||||
if (nextProps.scrollTop > -1) {
|
||||
|
|
@ -474,10 +455,9 @@ var Table = function (_Component) {
|
|||
this.bodyTable.scrollTop = this.scrollTop;
|
||||
this.scrollTop = -1;
|
||||
}
|
||||
// 当表格没有数据时,重置滚动条位置,造成grid里面的表头列无法操作
|
||||
// if (prevProps.data.length === 0 || this.props.data.length === 0 ) {
|
||||
// this.resetScrollX();
|
||||
// }
|
||||
if (prevProps.data.length === 0 || this.props.data.length === 0) {
|
||||
this.resetScrollX();
|
||||
}
|
||||
|
||||
// 是否传入 scroll中的y属性,如果传入判断是否是整数,如果是则进行比较 。bodyTable 的clientHeight进行判断
|
||||
this.isShowScrollY();
|
||||
|
|
@ -647,10 +627,7 @@ var Table = function (_Component) {
|
|||
headerScroll = _props2.headerScroll,
|
||||
bordered = _props2.bordered,
|
||||
onDropBorder = _props2.onDropBorder,
|
||||
onDraggingBorder = _props2.onDraggingBorder,
|
||||
bodyDisplayInRow = _props2.bodyDisplayInRow,
|
||||
headerEventNoStop = _props2.headerEventNoStop,
|
||||
onCopy = _props2.onCopy;
|
||||
onDraggingBorder = _props2.onDraggingBorder;
|
||||
|
||||
this.columnsChildrenList = []; //复杂表头拖拽,重新render表头前,将其置空
|
||||
var rows = this.getHeaderRows(columns);
|
||||
|
|
@ -697,10 +674,7 @@ var Table = function (_Component) {
|
|||
headerScroll: headerScroll,
|
||||
bordered: bordered,
|
||||
leftFixedWidth: leftFixedWidth,
|
||||
rightFixedWidth: rightFixedWidth,
|
||||
bodyDisplayInRow: bodyDisplayInRow,
|
||||
eventNoStop: headerEventNoStop,
|
||||
onCopy: onCopy
|
||||
rightFixedWidth: rightFixedWidth
|
||||
})) : null;
|
||||
};
|
||||
|
||||
|
|
@ -799,9 +773,7 @@ var Table = function (_Component) {
|
|||
Table.prototype.getExpandedRow = function getExpandedRow(key, content, visible, className, fixed) {
|
||||
var _props3 = this.props,
|
||||
clsPrefix = _props3.clsPrefix,
|
||||
expandIconAsCell = _props3.expandIconAsCell,
|
||||
onPaste = _props3.onPaste,
|
||||
getCellClassName = _props3.getCellClassName;
|
||||
expandIconAsCell = _props3.expandIconAsCell;
|
||||
|
||||
var colCount = void 0;
|
||||
if (fixed === 'left') {
|
||||
|
|
@ -841,7 +813,6 @@ var Table = function (_Component) {
|
|||
});
|
||||
}
|
||||
return _react2["default"].createElement(_TableRow2["default"], {
|
||||
onPaste: onPaste,
|
||||
columns: columns,
|
||||
visible: visible,
|
||||
className: className,
|
||||
|
|
@ -852,11 +823,9 @@ var Table = function (_Component) {
|
|||
store: this.store,
|
||||
dragborderKey: this.props.dragborderKey,
|
||||
rowDraggAble: this.props.rowDraggAble,
|
||||
useDragHandle: this.props.useDragHandle,
|
||||
onDragRow: this.onDragRow,
|
||||
onDragRowStart: this.onDragRowStart,
|
||||
height: expandedRowHeight,
|
||||
getCellClassName: getCellClassName
|
||||
height: expandedRowHeight
|
||||
});
|
||||
};
|
||||
|
||||
|
|
@ -899,7 +868,6 @@ var Table = function (_Component) {
|
|||
var childrenColumnName = props.childrenColumnName;
|
||||
var expandedRowRender = props.expandedRowRender;
|
||||
var expandRowByClick = props.expandRowByClick;
|
||||
var onPaste = props.onPaste;
|
||||
var fixedColumnsBodyRowsHeight = this.state.fixedColumnsBodyRowsHeight;
|
||||
|
||||
var rst = [];
|
||||
|
|
@ -916,7 +884,7 @@ var Table = function (_Component) {
|
|||
var expandIconAsCell = fixed !== 'right' ? props.expandIconAsCell : false;
|
||||
var expandIconColumnIndex = props.expandIconColumnIndex;
|
||||
if (props.lazyLoad && props.lazyLoad.preHeight && indent == 0) {
|
||||
rst.push(_react2["default"].createElement(_TableRow2["default"], { onPaste: onPaste, height: props.lazyLoad.preHeight, columns: [], className: '', key: 'table_row_first', store: this.store, visible: true }));
|
||||
rst.push(_react2["default"].createElement(_TableRow2["default"], { height: props.lazyLoad.preHeight, columns: [], className: '', key: 'table_row_first', store: this.store, visible: true }));
|
||||
}
|
||||
var lazyCurrentIndex = props.lazyLoad && props.lazyLoad.startIndex ? props.lazyLoad.startIndex : 0;
|
||||
var lazyParentIndex = props.lazyLoad && props.lazyLoad.startParentIndex ? props.lazyLoad.startParentIndex : 0;
|
||||
|
|
@ -984,11 +952,10 @@ var Table = function (_Component) {
|
|||
index = i + lazyParentIndex;
|
||||
}
|
||||
rst.push(_react2["default"].createElement(_TableRow2["default"], _extends({
|
||||
onPaste: onPaste,
|
||||
indent: indent,
|
||||
indentSize: props.indentSize,
|
||||
needIndentSpaced: needIndentSpaced,
|
||||
className: '' + className,
|
||||
className: className + ' ' + (this.props.rowDraggAble ? ' row-dragg-able ' : ''),
|
||||
record: record,
|
||||
expandIconAsCell: expandIconAsCell,
|
||||
onDestroy: this.onRowDestroy,
|
||||
|
|
@ -1020,8 +987,7 @@ var Table = function (_Component) {
|
|||
rootIndex: rootIndex,
|
||||
syncHover: props.syncHover,
|
||||
bodyDisplayInRow: props.bodyDisplayInRow,
|
||||
rowDraggAble: props.rowDraggAble,
|
||||
useDragHandle: props.useDragHandle,
|
||||
rowDraggAble: this.props.rowDraggAble,
|
||||
onDragRow: this.onDragRow,
|
||||
onDragRowStart: this.onDragRowStart,
|
||||
contentTable: this.contentTable,
|
||||
|
|
@ -1032,8 +998,7 @@ var Table = function (_Component) {
|
|||
lazyEndIndex: lazyEndIndex,
|
||||
centerColumnsLength: this.centerColumnsLength,
|
||||
leftColumnsLength: this.leftColumnsLength,
|
||||
expandIconCellWidth: expandIconCellWidth,
|
||||
getCellClassName: props.getCellClassName
|
||||
expandIconCellWidth: expandIconCellWidth
|
||||
})));
|
||||
this.treeRowIndex++;
|
||||
var subVisible = visible && isRowExpanded;
|
||||
|
|
@ -1049,7 +1014,7 @@ var Table = function (_Component) {
|
|||
}
|
||||
|
||||
if (props.lazyLoad && props.lazyLoad.sufHeight && indent == 0) {
|
||||
rst.push(_react2["default"].createElement(_TableRow2["default"], { onPaste: onPaste, height: props.lazyLoad.sufHeight, key: 'table_row_end', columns: [], className: '', store: this.store, visible: true }));
|
||||
rst.push(_react2["default"].createElement(_TableRow2["default"], { height: props.lazyLoad.sufHeight, key: 'table_row_end', columns: [], className: '', store: this.store, visible: true }));
|
||||
}
|
||||
if (!this.isTreeType) {
|
||||
this.treeType = false;
|
||||
|
|
@ -1327,7 +1292,7 @@ var Table = function (_Component) {
|
|||
}
|
||||
// const leftFixedWidth = this.columnManager.getLeftColumnsWidth(this.contentWidth);
|
||||
// const rightFixedWidth = this.columnManager.getRightColumnsWidth(this.contentWidth);
|
||||
var expandIconWidth = expandIconAsCell ? 32 : 0;
|
||||
var expandIconWidth = expandIconAsCell ? 33 : 0;
|
||||
var parStyle = {};
|
||||
if (!fixed) {
|
||||
parStyle = { 'marginLeft': leftFixedWidth + expandIconWidth, 'marginRight': rightFixedWidth };
|
||||
|
|
@ -1437,7 +1402,7 @@ var Table = function (_Component) {
|
|||
if (headerHeight) {
|
||||
height = ((0, _utils.getMaxColChildrenLength)(columns) + 1) * headerHeight;
|
||||
}
|
||||
return headerHeight ? height : parseInt(row.getBoundingClientRect().height) || 'auto';
|
||||
return headerHeight ? height : row.getBoundingClientRect().height || 'auto';
|
||||
});
|
||||
var fixedColumnsBodyRowsHeight = [].map.call(bodyRows, function (row, index) {
|
||||
var rsHeight = height;
|
||||
|
|
@ -1451,37 +1416,33 @@ var Table = function (_Component) {
|
|||
rightHeight = void 0,
|
||||
currentHeight = void 0,
|
||||
maxHeight = void 0;
|
||||
leftHeight = leftBodyRows[index] ? parseInt(leftBodyRows[index].getBoundingClientRect().height) : 0;
|
||||
rightHeight = rightBodyRows[index] ? parseInt(rightBodyRows[index].getBoundingClientRect().height) : 0;
|
||||
currentHeight = parseInt(row.getBoundingClientRect().height);
|
||||
leftHeight = leftBodyRows[index] ? leftBodyRows[index].getBoundingClientRect().height : 0;
|
||||
rightHeight = rightBodyRows[index] ? rightBodyRows[index].getBoundingClientRect().height : 0;
|
||||
currentHeight = row.getBoundingClientRect().height;
|
||||
maxHeight = Math.max(leftHeight, rightHeight, currentHeight);
|
||||
return maxHeight || 'auto';
|
||||
} else {
|
||||
return parseInt(row.getBoundingClientRect().height) || 'auto';
|
||||
return row.getBoundingClientRect().height || 'auto';
|
||||
}
|
||||
}
|
||||
});
|
||||
var fixedColumnsExpandedRowsHeight = {};
|
||||
// expandedRows为NodeList Array.prototype.forEach ie 下报错 对象不支持 “forEach” 方法
|
||||
expandedRows.length > 0 && Array.prototype.forEach.call(expandedRows, function (row) {
|
||||
var parentRowKey = row && row.previousSibling && row.previousSibling.getAttribute("data-row-key");
|
||||
var exHeight = height;
|
||||
if (!exHeight) {
|
||||
exHeight = row && parseInt(row.getBoundingClientRect().height) || 'auto';
|
||||
try {
|
||||
//子表数据减少时,动态计算高度
|
||||
var td = row.querySelector('td');
|
||||
var tdPadding = _this5.getTdPadding(td);
|
||||
var trueheight = parseInt(row.querySelectorAll('.u-table')[0].getBoundingClientRect().height);
|
||||
exHeight = trueheight + tdPadding;
|
||||
} catch (error) {}
|
||||
}
|
||||
fixedColumnsExpandedRowsHeight[parentRowKey] = parseInt(exHeight);
|
||||
var parentRowKey = row && row.previousSibling && row.previousSibling.getAttribute("data-row-key"),
|
||||
height = row && row.getBoundingClientRect().height || 'auto';
|
||||
try {
|
||||
//子表数据减少时,动态计算高度
|
||||
var td = row.querySelector('td');
|
||||
var tdPadding = _this5.getTdPadding(td);
|
||||
var trueheight = row.querySelectorAll('.u-table')[0].getBoundingClientRect().height;
|
||||
height = trueheight + tdPadding;
|
||||
} catch (error) {}
|
||||
fixedColumnsExpandedRowsHeight[parentRowKey] = height;
|
||||
});
|
||||
if ((0, _shallowequal2["default"])(this.state.fixedColumnsHeadRowsHeight, fixedColumnsHeadRowsHeight) && (0, _shallowequal2["default"])(this.state.fixedColumnsBodyRowsHeight, fixedColumnsBodyRowsHeight) && (0, _shallowequal2["default"])(this.state.fixedColumnsExpandedRowsHeight, fixedColumnsExpandedRowsHeight)) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.setState({
|
||||
fixedColumnsHeadRowsHeight: fixedColumnsHeadRowsHeight,
|
||||
fixedColumnsBodyRowsHeight: fixedColumnsBodyRowsHeight,
|
||||
|
|
@ -1513,15 +1474,6 @@ var Table = function (_Component) {
|
|||
|
||||
Table.prototype.onBodyMouseLeave = function onBodyMouseLeave(e) {
|
||||
this.hideHoverDom(e);
|
||||
var onBodyMouseLeave = this.props.onBodyMouseLeave;
|
||||
|
||||
if (typeof onBodyMouseLeave === 'function') {
|
||||
this.clearBodyMouseLeaveTimer();
|
||||
//因为鼠标移动到 hoverContent 中也会触发 onBodyMouseLeave,这是错误的
|
||||
//所以讲 onBodyMouseLeave 回调的调用放入 setTimeout中,
|
||||
// 当触发 hoverContent 的 onRowHoverMouseEnter 回调时,清除此定时器
|
||||
this.bodyMouseLeaveTimmer = setTimeout(onBodyMouseLeave, 0);
|
||||
}
|
||||
};
|
||||
|
||||
Table.prototype.detectScrollTarget = function detectScrollTarget(e) {
|
||||
|
|
@ -1563,7 +1515,7 @@ var Table = function (_Component) {
|
|||
}
|
||||
if (e.target.scrollLeft === 0) {
|
||||
position = 'left';
|
||||
} else if (e.target.scrollLeft + 1 >= e.target.querySelector('table').getBoundingClientRect().width - e.target.getBoundingClientRect().width) {
|
||||
} else if (e.target.scrollLeft + 1 >= e.target.children[0].getBoundingClientRect().width - e.target.getBoundingClientRect().width) {
|
||||
position = 'right';
|
||||
} else if (this.state.scrollPosition !== 'middle') {
|
||||
position = 'middle';
|
||||
|
|
@ -1592,9 +1544,6 @@ var Table = function (_Component) {
|
|||
this.lastScrollTop = e.target.scrollTop;
|
||||
if (handleScrollY) {
|
||||
(0, _utils.debounce)(handleScrollY(this.lastScrollTop, this.treeType, onBodyScroll), 300);
|
||||
} else {
|
||||
//滚动回调
|
||||
onBodyScroll(this.lastScrollTop);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1635,10 +1584,6 @@ var Table = function (_Component) {
|
|||
this.hoverDom.style.lineHeight = td.offsetHeight + 'px';
|
||||
this.hoverDom.style.display = 'block';
|
||||
}
|
||||
this.setState({
|
||||
currentHoverIndex: currentIndex,
|
||||
currentHoverRecord: record
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1648,10 +1593,6 @@ var Table = function (_Component) {
|
|||
Table.prototype.render = function render() {
|
||||
var _this7 = this;
|
||||
|
||||
var _state3 = this.state,
|
||||
currentHoverRecord = _state3.currentHoverRecord,
|
||||
currentHoverIndex = _state3.currentHoverIndex;
|
||||
|
||||
var props = this.props;
|
||||
var clsPrefix = props.clsPrefix;
|
||||
var hasFixedLeft = this.columnManager.isAnyColumnsLeftFixed();
|
||||
|
|
@ -1668,9 +1609,6 @@ var Table = function (_Component) {
|
|||
if (props.bordered) {
|
||||
className += ' ' + clsPrefix + '-bordered';
|
||||
}
|
||||
if (props.onCopy) {
|
||||
className += ' copy';
|
||||
}
|
||||
className += ' ' + clsPrefix + '-scroll-position-' + this.state.scrollPosition;
|
||||
//如果传入height说明是固定高度
|
||||
//内容过多折行显示时,height 属性会失效,为了避免产生错行
|
||||
|
|
@ -1734,7 +1672,7 @@ var Table = function (_Component) {
|
|||
onMouseEnter: this.onRowHoverMouseEnter, onMouseLeave: this.onRowHoverMouseLeave, ref: function ref(el) {
|
||||
return _this7.hoverDom = el;
|
||||
} },
|
||||
props.hoverContent(currentHoverRecord, currentHoverIndex)
|
||||
props.hoverContent()
|
||||
)
|
||||
);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -55,8 +55,7 @@ var propTypes = {
|
|||
indent: _propTypes2["default"].number,
|
||||
indentSize: _propTypes2["default"].number,
|
||||
column: _propTypes2["default"].object,
|
||||
expandIcon: _propTypes2["default"].node,
|
||||
onPaste: _propTypes2["default"].func
|
||||
expandIcon: _propTypes2["default"].node
|
||||
};
|
||||
|
||||
var TableCell = function (_Component) {
|
||||
|
|
@ -256,27 +255,6 @@ var TableCell = function (_Component) {
|
|||
});
|
||||
};
|
||||
|
||||
_this.onPaste = function (e) {
|
||||
var _this$props = _this.props,
|
||||
row = _this$props.index,
|
||||
onPaste = _this$props.onPaste,
|
||||
fixed = _this$props.fixed,
|
||||
col = _this$props.col;
|
||||
|
||||
var position = {
|
||||
row: row,
|
||||
col: col,
|
||||
fixed: !!fixed
|
||||
};
|
||||
onPaste(e, position);
|
||||
};
|
||||
|
||||
_this.onCellMouseOver = function (e) {
|
||||
var column = _this.props.column;
|
||||
|
||||
_this.props.stopRowDrag(column.notRowDrag);
|
||||
};
|
||||
|
||||
_this.isInvalidRenderCellText = _this.isInvalidRenderCellText.bind(_this);
|
||||
_this.handleClick = _this.handleClick.bind(_this);
|
||||
_this.state = {
|
||||
|
|
@ -336,8 +314,7 @@ var TableCell = function (_Component) {
|
|||
showSum = _props2.showSum,
|
||||
bodyDisplayInRow = _props2.bodyDisplayInRow,
|
||||
lazyStartIndex = _props2.lazyStartIndex,
|
||||
lazyEndIndex = _props2.lazyEndIndex,
|
||||
getCellClassName = _props2.getCellClassName;
|
||||
lazyEndIndex = _props2.lazyEndIndex;
|
||||
|
||||
var dataIndex = column.dataIndex,
|
||||
render = column.render,
|
||||
|
|
@ -457,24 +434,15 @@ var TableCell = function (_Component) {
|
|||
if (colMenu) {
|
||||
className += ' u-table-inline-icon';
|
||||
}
|
||||
|
||||
if (typeof getCellClassName == 'function') {
|
||||
var selfClassName = getCellClassName(record, index, column) || '';
|
||||
className += ' ' + selfClassName;
|
||||
}
|
||||
|
||||
if (colSpan == 0) return null;
|
||||
return _react2["default"].createElement(
|
||||
'td',
|
||||
{
|
||||
draggable: column.draggable,
|
||||
colSpan: colSpan,
|
||||
rowSpan: rowSpan,
|
||||
className: className,
|
||||
onClick: this.handleClick,
|
||||
title: title,
|
||||
onPaste: this.onPaste,
|
||||
onMouseOver: this.onCellMouseOver,
|
||||
style: _extends({ maxWidth: column.width, color: fontColor, backgroundColor: bgColor }, column.style) },
|
||||
indentText,
|
||||
expandIcon,
|
||||
|
|
|
|||
|
|
@ -144,28 +144,15 @@ var TableHeader = function (_Component) {
|
|||
table.tr = tableDome.getElementsByTagName("tr");
|
||||
table.tableBody = contentTable.querySelector('.u-table-scroll .u-table-body') && contentTable.querySelector('.u-table-scroll .u-table-body');
|
||||
table.tableBodyCols = contentTable.querySelector('.u-table-scroll .u-table-body') && contentTable.querySelector('.u-table-scroll .u-table-body').getElementsByTagName("col");
|
||||
table.bodyRows = table.tableBody && table.tableBody.querySelectorAll('tr') || [];
|
||||
|
||||
table.fixedLeftHeaderTable = contentTable.querySelector('.u-table-fixed-left .u-table-header');
|
||||
table.fixedRighHeadertTable = contentTable.querySelector('.u-table-fixed-right .u-table-header');
|
||||
table.contentTableHeader = contentTable.querySelector('.u-table-scroll .u-table-header');
|
||||
table.fixedLeftBodyTable = contentTable.querySelectorAll('.u-table-fixed-left .u-table-body-outer');
|
||||
if (table.fixedLeftBodyTable) {
|
||||
var leftBodyTableIndex = table.fixedLeftBodyTable.length - 1 < 0 ? 0 : table.fixedLeftBodyTable.length - 1;
|
||||
table.fixedLeftBodyTable = table.fixedLeftBodyTable[leftBodyTableIndex];
|
||||
}
|
||||
|
||||
table.fixedRightBodyTable = contentTable.querySelectorAll('.u-table-fixed-right .u-table-body-outer');
|
||||
if (table.fixedRightBodyTable) {
|
||||
var rightBodyTableIndex = table.fixedRightBodyTable.length - 1 < 0 ? 0 : table.fixedRightBodyTable.length - 1;
|
||||
table.fixedRightBodyTable = table.fixedRightBodyTable[rightBodyTableIndex];
|
||||
}
|
||||
|
||||
table.innerTableBody = contentTable.querySelector('.u-table-scroll .u-table-body table');
|
||||
table.fixedLeftBodyRows = table.fixedLeftBodyTable && table.fixedLeftBodyTable.querySelectorAll('tr') || [];
|
||||
table.fixedRightBodyRows = table.fixedRightBodyTable && table.fixedRightBodyTable.querySelectorAll('tr') || [];
|
||||
}
|
||||
|
||||
table.fixedLeftHeaderTable = contentTable.querySelector('.u-table-fixed-left .u-table-header');
|
||||
table.fixedRighHeadertTable = contentTable.querySelector('.u-table-fixed-right .u-table-header');
|
||||
table.contentTableHeader = contentTable.querySelector('.u-table-scroll .u-table-header');
|
||||
table.fixedLeftBodyTable = contentTable.querySelector('.u-table-fixed-left .u-table-body-outer');
|
||||
table.fixedRightBodyTable = contentTable.querySelector('.u-table-fixed-right .u-table-body-outer');
|
||||
table.innerTableBody = contentTable.querySelector('.u-table-scroll .u-table-body table');
|
||||
|
||||
this.table = table;
|
||||
|
||||
if (!this.props.dragborder) return;
|
||||
|
|
@ -515,9 +502,7 @@ var TableHeader = function (_Component) {
|
|||
return _react2["default"].createElement(
|
||||
"th",
|
||||
_extends({}, da, keyTemp, { className: thClassName, "data-th-fixed": da.fixed, "data-line-key": da.key,
|
||||
"data-line-index": columIndex, "data-th-width": da.width, "data-type": "draggable", onCopy: function onCopy(event) {
|
||||
_this7.onCopy(da, columIndex, event);
|
||||
} }),
|
||||
"data-line-index": columIndex, "data-th-width": da.width, "data-type": "draggable" }),
|
||||
da.children,
|
||||
|
||||
// && columIndex != _rowLeng
|
||||
|
|
@ -538,7 +523,7 @@ var TableHeader = function (_Component) {
|
|||
da.onClick ? thDefaultObj.onClick = function (e) {
|
||||
da.onClick(da, e);
|
||||
} : "";
|
||||
return _react2["default"].createElement("th", _extends({}, thDefaultObj, keyTemp, { "data-th-fixed": da.fixed, style: { maxWidth: da.width }, onCopy: _this7.onCopy }));
|
||||
return _react2["default"].createElement("th", _extends({}, thDefaultObj, keyTemp, { "data-th-fixed": da.fixed, style: { maxWidth: da.width } }));
|
||||
}
|
||||
})
|
||||
);
|
||||
|
|
@ -571,9 +556,7 @@ var _initialiseProps = function _initialiseProps() {
|
|||
};
|
||||
|
||||
this.onTrMouseDown = function (e) {
|
||||
var eventNoStop = _this8.props.eventNoStop;
|
||||
|
||||
!eventNoStop && _utils.Event.stopPropagation(e);
|
||||
_utils.Event.stopPropagation(e);
|
||||
var event = _utils.Event.getEvent(e),
|
||||
targetEvent = _utils.Event.getTarget(event);
|
||||
var _props3 = _this8.props,
|
||||
|
|
@ -607,7 +590,7 @@ var _initialiseProps = function _initialiseProps() {
|
|||
}
|
||||
var currentObj = _this8.table.cols[currentIndex];
|
||||
_this8.drag.currIndex = currentIndex;
|
||||
_this8.drag.oldLeft = event.clientX;
|
||||
_this8.drag.oldLeft = event.x;
|
||||
_this8.drag.oldWidth = parseInt(currentObj.style.width);
|
||||
_this8.drag.minWidth = currentObj.style.minWidth != "" ? parseInt(currentObj.style.minWidth) : defaultWidth;
|
||||
_this8.drag.tableWidth = parseInt(_this8.table.table.style.width ? _this8.table.table.style.width : _this8.table.table.scrollWidth);
|
||||
|
|
@ -671,34 +654,18 @@ var _initialiseProps = function _initialiseProps() {
|
|||
lastShowIndex = _props4.lastShowIndex,
|
||||
onDraggingBorder = _props4.onDraggingBorder,
|
||||
leftFixedWidth = _props4.leftFixedWidth,
|
||||
rightFixedWidth = _props4.rightFixedWidth,
|
||||
bodyDisplayInRow = _props4.bodyDisplayInRow,
|
||||
eventNoStop = _props4.eventNoStop;
|
||||
rightFixedWidth = _props4.rightFixedWidth;
|
||||
|
||||
!eventNoStop && _utils.Event.stopPropagation(e);
|
||||
_utils.Event.stopPropagation(e);
|
||||
var event = _utils.Event.getEvent(e);
|
||||
if (_this8.props.dragborder && _this8.drag.option == "border") {
|
||||
//移动改变宽度
|
||||
var currentCols = _this8.table.cols[_this8.drag.currIndex];
|
||||
var diff = event.clientX - _this8.drag.oldLeft;
|
||||
var diff = event.x - _this8.drag.oldLeft;
|
||||
var newWidth = _this8.drag.oldWidth + diff;
|
||||
_this8.drag.newWidth = newWidth > 0 ? newWidth : _this8.minWidth;
|
||||
if (newWidth > _this8.minWidth) {
|
||||
currentCols.style.width = newWidth + 'px';
|
||||
|
||||
// displayinrow 判断、 固定行高判断
|
||||
if (!bodyDisplayInRow) {
|
||||
_this8.table.bodyRows.forEach(function (row, index) {
|
||||
var leftRow = _this8.table.fixedLeftBodyRows[index];
|
||||
var rightRow = _this8.table.fixedRightBodyRows[index];
|
||||
if (leftRow || rightRow) {
|
||||
var height = row.getBoundingClientRect().height;
|
||||
leftRow && (leftRow.style.height = height + "px");
|
||||
rightRow && (rightRow.style.height = height + "px");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//hao 支持固定表头拖拽 修改表体的width
|
||||
if (_this8.fixedTable.cols) {
|
||||
_this8.fixedTable.cols[_this8.drag.currIndex].style.width = newWidth + "px";
|
||||
|
|
@ -832,8 +799,6 @@ var _initialiseProps = function _initialiseProps() {
|
|||
}
|
||||
var event = _utils.Event.getEvent(e),
|
||||
target = _utils.Event.getTarget(event);
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
_this8.currentDome.setAttribute('draggable', false); //添加交换列效果
|
||||
// let data = this.getCurrentEventData(this._dragCurrent);
|
||||
// if(!data){
|
||||
|
|
@ -862,8 +827,6 @@ var _initialiseProps = function _initialiseProps() {
|
|||
var event = _utils.Event.getEvent(e),
|
||||
target = _utils.Event.getTarget(event);
|
||||
_this8._dragCurrent.setAttribute("style", "");
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
// this._dragCurrent.style = "";
|
||||
document.getElementById(_this8._table_none_cont_id).innerHTML = "";
|
||||
|
||||
|
|
@ -917,7 +880,7 @@ var _initialiseProps = function _initialiseProps() {
|
|||
, clsPrefix: clsPrefix //css前缀
|
||||
, className: clsPrefix + " filter-text",
|
||||
dataIndex: dataIndex //字段
|
||||
, onFilterChange: (0, _throttleDebounce.debounce)(filterDelay || 300, _this8.handlerFilterChange) //输入框回调
|
||||
, onFilterChange: _this8.handlerFilterChange //输入框回调
|
||||
, onFilterClear: _this8.handlerFilterClear //清除回调
|
||||
, filterDropdown: rows[1][index]["filterdropdown"] //是否显示下拉条件
|
||||
, filterDropdownType: rows[1][index]["filterdropdowntype"] //下拉的条件类型为string,number
|
||||
|
|
@ -1053,12 +1016,6 @@ var _initialiseProps = function _initialiseProps() {
|
|||
return _react2["default"].createElement("div", null);
|
||||
}
|
||||
};
|
||||
|
||||
this.onCopy = function (data, index, event) {
|
||||
if (_this8.props.onCopy) {
|
||||
_this8.props.onCopy(_extends(data, { col: index }), event);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
TableHeader.propTypes = propTypes;
|
||||
|
|
|
|||
|
|
@ -59,8 +59,7 @@ var propTypes = {
|
|||
store: _propTypes2["default"].object.isRequired,
|
||||
rowDraggAble: _propTypes2["default"].bool,
|
||||
onDragRow: _propTypes2["default"].func,
|
||||
onDragRowStart: _propTypes2["default"].func,
|
||||
syncRowHeight: _propTypes2["default"].bool
|
||||
onDragRowStart: _propTypes2["default"].func
|
||||
};
|
||||
|
||||
var defaultProps = {
|
||||
|
|
@ -75,9 +74,8 @@ var defaultProps = {
|
|||
|
||||
className: '',
|
||||
setRowParentIndex: function setRowParentIndex() {},
|
||||
rowDraggAble: false,
|
||||
rowDraggAble: false
|
||||
// onDragRow:()=>{}
|
||||
syncRowHeight: false
|
||||
};
|
||||
|
||||
var TableRow = function (_Component) {
|
||||
|
|
@ -115,16 +113,19 @@ var TableRow = function (_Component) {
|
|||
_this.onDragStart = function (e) {
|
||||
var onDragRowStart = _this.props.onDragRowStart;
|
||||
|
||||
if (!_this.props.rowDraggAble || _this.notRowDrag) return;
|
||||
if (!_this.props.rowDraggAble) return;
|
||||
var event = _utils.Event.getEvent(e),
|
||||
target = _utils.Event.getTarget(event);
|
||||
if (target.tagName === 'TD') {
|
||||
target = target.parentNode;
|
||||
}
|
||||
_this.currentIndex = target.getAttribute("data-row-key");
|
||||
_this._dragCurrent = target;
|
||||
|
||||
//TODO 自定义图像后续需要增加。
|
||||
// let crt = this.synchronizeTableTrShadow();
|
||||
// document.getElementById(this.props.tableUid).appendChild(crt);
|
||||
// event.dataTransfer.setDragImage(crt, 0, 0);
|
||||
event.dataTransfer.effectAllowed = "move";
|
||||
event.dataTransfer.setData("Text", _this.currentIndex);
|
||||
|
||||
onDragRowStart && onDragRowStart(_this.currentIndex);
|
||||
};
|
||||
|
||||
|
|
@ -134,13 +135,14 @@ var TableRow = function (_Component) {
|
|||
};
|
||||
|
||||
_this.onDrop = function (e) {
|
||||
var onDragRow = _this.props.onDragRow;
|
||||
var _this$props = _this.props,
|
||||
rowDraggAble = _this$props.rowDraggAble,
|
||||
onDragRow = _this$props.onDragRow;
|
||||
|
||||
var event = _utils.Event.getEvent(e),
|
||||
_target = _utils.Event.getTarget(event),
|
||||
target = _target.parentNode;
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
|
||||
var currentKey = event.dataTransfer.getData("text");
|
||||
var targetKey = target.getAttribute("data-row-key");
|
||||
|
||||
|
|
@ -148,6 +150,8 @@ var TableRow = function (_Component) {
|
|||
if (target.nodeName.toUpperCase() === "TR") {
|
||||
_this.synchronizeTableTr(currentKey, null);
|
||||
_this.synchronizeTableTr(targetKey, null);
|
||||
// target.setAttribute("style","");
|
||||
// this.synchronizeTrStyle(this.currentIndex,false);
|
||||
}
|
||||
onDragRow && onDragRow(currentKey, targetKey);
|
||||
};
|
||||
|
|
@ -224,9 +228,9 @@ var TableRow = function (_Component) {
|
|||
};
|
||||
|
||||
_this.synchronizeTableTrShadow = function () {
|
||||
var _this$props = _this.props,
|
||||
contentTable = _this$props.contentTable,
|
||||
index = _this$props.index;
|
||||
var _this$props2 = _this.props,
|
||||
contentTable = _this$props2.contentTable,
|
||||
index = _this$props2.index;
|
||||
|
||||
|
||||
var cont = contentTable.querySelector('.u-table-scroll table tbody').getElementsByTagName("tr")[index],
|
||||
|
|
@ -278,7 +282,7 @@ var TableRow = function (_Component) {
|
|||
}
|
||||
}
|
||||
if (type) {
|
||||
currentObj && currentObj.setAttribute("style", "border-bottom:2px solid #02B1FD");
|
||||
currentObj && currentObj.setAttribute("style", "border-bottom:2px dashed rgb(30, 136, 229)");
|
||||
} else {
|
||||
currentObj && currentObj.setAttribute("style", "");
|
||||
}
|
||||
|
|
@ -292,6 +296,8 @@ var TableRow = function (_Component) {
|
|||
if (!currentIndex || currentIndex === _this.currentIndex) return;
|
||||
if (target.nodeName.toUpperCase() === "TR") {
|
||||
_this.synchronizeTableTr(currentIndex, true);
|
||||
// target.setAttribute("style","border-bottom:2px dashed rgba(5,0,0,0.25)");
|
||||
// // target.style.backgroundColor = 'rgb(235, 236, 240)';
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -306,17 +312,6 @@ var TableRow = function (_Component) {
|
|||
}
|
||||
};
|
||||
|
||||
_this.stopRowDrag = function (isStop) {
|
||||
var rowDraggAble = _this.props.rowDraggAble;
|
||||
var notRowDrag = _this.state.notRowDrag;
|
||||
|
||||
if (rowDraggAble && isStop !== notRowDrag) {
|
||||
_this.setState({
|
||||
notRowDrag: isStop
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
_this.set = function (fn) {
|
||||
_this.clear();
|
||||
_this._timeout = window.setTimeout(fn, 300);
|
||||
|
|
@ -437,9 +432,7 @@ var TableRow = function (_Component) {
|
|||
|
||||
|
||||
TableRow.prototype.componentDidUpdate = function componentDidUpdate(prevProps) {
|
||||
var _props2 = this.props,
|
||||
rowDraggAble = _props2.rowDraggAble,
|
||||
syncRowHeight = _props2.syncRowHeight;
|
||||
var rowDraggAble = this.props.rowDraggAble;
|
||||
|
||||
if (!this.event) {
|
||||
this.event = true;
|
||||
|
|
@ -447,21 +440,19 @@ var TableRow = function (_Component) {
|
|||
this.initEvent();
|
||||
}
|
||||
}
|
||||
|
||||
if (this.props.treeType) {
|
||||
this.setRowParentIndex();
|
||||
}
|
||||
// if(syncRowHeight){
|
||||
// this.setRowHeight()
|
||||
// }
|
||||
this.setRowHeight();
|
||||
};
|
||||
|
||||
TableRow.prototype.componentWillUnmount = function componentWillUnmount() {
|
||||
var _props3 = this.props,
|
||||
record = _props3.record,
|
||||
onDestroy = _props3.onDestroy,
|
||||
index = _props3.index,
|
||||
rowDraggAble = _props3.rowDraggAble;
|
||||
var _props2 = this.props,
|
||||
record = _props2.record,
|
||||
onDestroy = _props2.onDestroy,
|
||||
index = _props2.index,
|
||||
rowDraggAble = _props2.rowDraggAble;
|
||||
|
||||
onDestroy(record, index);
|
||||
if (this.unsubscribe) {
|
||||
|
|
@ -473,23 +464,23 @@ var TableRow = function (_Component) {
|
|||
};
|
||||
|
||||
TableRow.prototype.setRowHeight = function setRowHeight() {
|
||||
var _props4 = this.props,
|
||||
setRowHeight = _props4.setRowHeight,
|
||||
_props4$expandedConte = _props4.expandedContentHeight,
|
||||
expandedContentHeight = _props4$expandedConte === undefined ? 0 : _props4$expandedConte,
|
||||
fixed = _props4.fixed,
|
||||
fixedIndex = _props4.fixedIndex;
|
||||
var _props3 = this.props,
|
||||
setRowHeight = _props3.setRowHeight,
|
||||
_props3$expandedConte = _props3.expandedContentHeight,
|
||||
expandedContentHeight = _props3$expandedConte === undefined ? 0 : _props3$expandedConte,
|
||||
fixed = _props3.fixed,
|
||||
fixedIndex = _props3.fixedIndex;
|
||||
|
||||
if (!setRowHeight || !this.element || fixed) return;
|
||||
setRowHeight(this.element.clientHeight + expandedContentHeight, fixedIndex);
|
||||
};
|
||||
|
||||
TableRow.prototype.setRowParentIndex = function setRowParentIndex() {
|
||||
var _props5 = this.props,
|
||||
index = _props5.index,
|
||||
setRowParentIndex = _props5.setRowParentIndex,
|
||||
fixedIndex = _props5.fixedIndex,
|
||||
rootIndex = _props5.rootIndex;
|
||||
var _props4 = this.props,
|
||||
index = _props4.index,
|
||||
setRowParentIndex = _props4.setRowParentIndex,
|
||||
fixedIndex = _props4.fixedIndex,
|
||||
rootIndex = _props4.rootIndex;
|
||||
|
||||
setRowParentIndex(rootIndex < 0 ? index : rootIndex, fixedIndex);
|
||||
};
|
||||
|
|
@ -499,16 +490,16 @@ var TableRow = function (_Component) {
|
|||
// 异步访问事件属性
|
||||
// 调用 event.persist() 会从事件池中移除该合成函数并允许对该合成事件的引用被保留下来。
|
||||
event.persist();
|
||||
var _props6 = this.props,
|
||||
record = _props6.record,
|
||||
index = _props6.index,
|
||||
onRowClick = _props6.onRowClick,
|
||||
expandable = _props6.expandable,
|
||||
expandRowByClick = _props6.expandRowByClick,
|
||||
expanded = _props6.expanded,
|
||||
onExpand = _props6.onExpand,
|
||||
fixedIndex = _props6.fixedIndex,
|
||||
onRowDoubleClick = _props6.onRowDoubleClick;
|
||||
var _props5 = this.props,
|
||||
record = _props5.record,
|
||||
index = _props5.index,
|
||||
onRowClick = _props5.onRowClick,
|
||||
expandable = _props5.expandable,
|
||||
expandRowByClick = _props5.expandRowByClick,
|
||||
expanded = _props5.expanded,
|
||||
onExpand = _props5.onExpand,
|
||||
fixedIndex = _props5.fixedIndex,
|
||||
onRowDoubleClick = _props5.onRowDoubleClick;
|
||||
|
||||
if (expandable && expandRowByClick) {
|
||||
onExpand(!expanded, record, fixedIndex, event);
|
||||
|
|
@ -523,23 +514,23 @@ var TableRow = function (_Component) {
|
|||
};
|
||||
|
||||
TableRow.prototype.onRowDoubleClick = function onRowDoubleClick(event) {
|
||||
var _props7 = this.props,
|
||||
record = _props7.record,
|
||||
index = _props7.index,
|
||||
onRowDoubleClick = _props7.onRowDoubleClick,
|
||||
fixedIndex = _props7.fixedIndex;
|
||||
var _props6 = this.props,
|
||||
record = _props6.record,
|
||||
index = _props6.index,
|
||||
onRowDoubleClick = _props6.onRowDoubleClick,
|
||||
fixedIndex = _props6.fixedIndex;
|
||||
|
||||
this.clear();
|
||||
onRowDoubleClick && onRowDoubleClick(record, fixedIndex, event);
|
||||
};
|
||||
|
||||
TableRow.prototype.onMouseEnter = function onMouseEnter(e) {
|
||||
var _props8 = this.props,
|
||||
onHover = _props8.onHover,
|
||||
hoverKey = _props8.hoverKey,
|
||||
fixedIndex = _props8.fixedIndex,
|
||||
syncHover = _props8.syncHover,
|
||||
record = _props8.record;
|
||||
var _props7 = this.props,
|
||||
onHover = _props7.onHover,
|
||||
hoverKey = _props7.hoverKey,
|
||||
fixedIndex = _props7.fixedIndex,
|
||||
syncHover = _props7.syncHover,
|
||||
record = _props7.record;
|
||||
|
||||
if (syncHover) {
|
||||
this.setState({ hovered: true });
|
||||
|
|
@ -548,12 +539,12 @@ var TableRow = function (_Component) {
|
|||
};
|
||||
|
||||
TableRow.prototype.onMouseLeave = function onMouseLeave(e) {
|
||||
var _props9 = this.props,
|
||||
onHover = _props9.onHover,
|
||||
hoverKey = _props9.hoverKey,
|
||||
fixedIndex = _props9.fixedIndex,
|
||||
syncHover = _props9.syncHover,
|
||||
record = _props9.record;
|
||||
var _props8 = this.props,
|
||||
onHover = _props8.onHover,
|
||||
hoverKey = _props8.hoverKey,
|
||||
fixedIndex = _props8.fixedIndex,
|
||||
syncHover = _props8.syncHover,
|
||||
record = _props8.record;
|
||||
|
||||
if (syncHover) {
|
||||
this.setState({ hovered: false });
|
||||
|
|
@ -562,35 +553,32 @@ var TableRow = function (_Component) {
|
|||
};
|
||||
|
||||
TableRow.prototype.render = function render() {
|
||||
var _props10 = this.props,
|
||||
clsPrefix = _props10.clsPrefix,
|
||||
columns = _props10.columns,
|
||||
record = _props10.record,
|
||||
height = _props10.height,
|
||||
visible = _props10.visible,
|
||||
index = _props10.index,
|
||||
onPaste = _props10.onPaste,
|
||||
expandIconColumnIndex = _props10.expandIconColumnIndex,
|
||||
expandIconAsCell = _props10.expandIconAsCell,
|
||||
expanded = _props10.expanded,
|
||||
useDragHandle = _props10.useDragHandle,
|
||||
rowDraggAble = _props10.rowDraggAble,
|
||||
expandable = _props10.expandable,
|
||||
onExpand = _props10.onExpand,
|
||||
needIndentSpaced = _props10.needIndentSpaced,
|
||||
indent = _props10.indent,
|
||||
indentSize = _props10.indentSize,
|
||||
isHiddenExpandIcon = _props10.isHiddenExpandIcon,
|
||||
fixed = _props10.fixed,
|
||||
bodyDisplayInRow = _props10.bodyDisplayInRow,
|
||||
expandedIcon = _props10.expandedIcon,
|
||||
collapsedIcon = _props10.collapsedIcon,
|
||||
hoverKey = _props10.hoverKey,
|
||||
lazyStartIndex = _props10.lazyStartIndex,
|
||||
lazyEndIndex = _props10.lazyEndIndex,
|
||||
expandIconCellWidth = _props10.expandIconCellWidth,
|
||||
getCellClassName = _props10.getCellClassName;
|
||||
var notRowDrag = this.state.notRowDrag;
|
||||
var _props9 = this.props,
|
||||
clsPrefix = _props9.clsPrefix,
|
||||
columns = _props9.columns,
|
||||
record = _props9.record,
|
||||
height = _props9.height,
|
||||
visible = _props9.visible,
|
||||
index = _props9.index,
|
||||
expandIconColumnIndex = _props9.expandIconColumnIndex,
|
||||
expandIconAsCell = _props9.expandIconAsCell,
|
||||
expanded = _props9.expanded,
|
||||
expandRowByClick = _props9.expandRowByClick,
|
||||
rowDraggAble = _props9.rowDraggAble,
|
||||
expandable = _props9.expandable,
|
||||
onExpand = _props9.onExpand,
|
||||
needIndentSpaced = _props9.needIndentSpaced,
|
||||
indent = _props9.indent,
|
||||
indentSize = _props9.indentSize,
|
||||
isHiddenExpandIcon = _props9.isHiddenExpandIcon,
|
||||
fixed = _props9.fixed,
|
||||
bodyDisplayInRow = _props9.bodyDisplayInRow,
|
||||
expandedIcon = _props9.expandedIcon,
|
||||
collapsedIcon = _props9.collapsedIcon,
|
||||
hoverKey = _props9.hoverKey,
|
||||
lazyStartIndex = _props9.lazyStartIndex,
|
||||
lazyEndIndex = _props9.lazyEndIndex,
|
||||
expandIconCellWidth = _props9.expandIconCellWidth;
|
||||
|
||||
var showSum = false;
|
||||
var className = this.props.className;
|
||||
|
|
@ -623,8 +611,8 @@ var TableRow = function (_Component) {
|
|||
expandIndexInThisTable = expandIconColumnIndex;
|
||||
}
|
||||
for (var i = 0; i < columns.length; i++) {
|
||||
if (expandIconAsCell && i === 0) {
|
||||
showSum ? cells.push(_react2["default"].createElement('td', { width: expandIconCellWidth })) : cells.push(_react2["default"].createElement(
|
||||
if (expandIconAsCell && i === 0 && !showSum) {
|
||||
cells.push(_react2["default"].createElement(
|
||||
'td',
|
||||
{
|
||||
className: clsPrefix + '-expand-icon-cell ' + isExpandIconAsCell,
|
||||
|
|
@ -649,11 +637,7 @@ var TableRow = function (_Component) {
|
|||
expandIcon: isColumnHaveExpandIcon ? expandIcon : null,
|
||||
bodyDisplayInRow: bodyDisplayInRow,
|
||||
lazyStartIndex: lazyStartIndex,
|
||||
lazyEndIndex: lazyEndIndex,
|
||||
onPaste: onPaste,
|
||||
stopRowDrag: this.stopRowDrag,
|
||||
col: i,
|
||||
getCellClassName: getCellClassName
|
||||
lazyEndIndex: lazyEndIndex
|
||||
}));
|
||||
}
|
||||
var style = _extends({ height: height }, record ? record.style : undefined);
|
||||
|
|
@ -663,15 +647,10 @@ var TableRow = function (_Component) {
|
|||
if (record && record._checked) {
|
||||
className += ' selected';
|
||||
}
|
||||
|
||||
if (rowDraggAble && !useDragHandle && !notRowDrag) {
|
||||
className += ' row-dragg-able';
|
||||
}
|
||||
|
||||
return _react2["default"].createElement(
|
||||
'tr',
|
||||
{
|
||||
draggable: rowDraggAble && !useDragHandle && !notRowDrag,
|
||||
draggable: rowDraggAble,
|
||||
onClick: this.onRowClick,
|
||||
onDoubleClick: this.onRowDoubleClick,
|
||||
onMouseEnter: this.onMouseEnter,
|
||||
|
|
|
|||
|
|
@ -100,12 +100,9 @@ function bigData(Table) {
|
|||
_this.cachedRowParentIndex = [];
|
||||
_this.computeCachedRowParentIndex(newData);
|
||||
// fix:切换数据源,startIndex、endIndex错误
|
||||
if (_this.scrollTop <= 0) {
|
||||
// 增加scrollTop 判断,ncc场景下滚动条不在最上层, 会出现空白,因为重置了currentIndex没有重置滚动条
|
||||
_this.currentIndex = 0;
|
||||
_this.startIndex = _this.currentIndex; //数据开始位置
|
||||
_this.endIndex = _this.currentIndex + _this.loadCount;
|
||||
}
|
||||
_this.currentIndex = 0;
|
||||
_this.startIndex = _this.currentIndex; //数据开始位置
|
||||
_this.endIndex = _this.currentIndex + _this.loadCount;
|
||||
}
|
||||
_this.treeData = [];
|
||||
_this.flatTreeData = [];
|
||||
|
|
@ -117,7 +114,7 @@ function bigData(Table) {
|
|||
}
|
||||
}
|
||||
//如果传currentIndex,会判断该条数据是否在可视区域,如果没有的话,则重新计算startIndex和endIndex
|
||||
if (currentIndex != -1 && currentIndex !== this.currentIndex) {
|
||||
if (currentIndex !== -1 && currentIndex !== this.currentIndex) {
|
||||
_this.setStartAndEndIndex(currentIndex, dataLen);
|
||||
}
|
||||
};
|
||||
|
|
@ -258,7 +255,7 @@ function bigData(Table) {
|
|||
if (this.cachedRowHeight[i] == undefined) {
|
||||
if (this.treeType) {
|
||||
// currentKey = this.keys[i];
|
||||
currentKey = this.flatTreeData[i] && this.flatTreeData[i].key;
|
||||
currentKey = this.flatTreeData[i].key;
|
||||
currentRowHeight = 0;
|
||||
if (this.flatTreeKeysMap.hasOwnProperty(currentKey)) {
|
||||
currentRowHeight = rowHeight;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
value: true
|
||||
});
|
||||
|
||||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
|
||||
|
|
@ -35,115 +35,115 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function"
|
|||
|
||||
function dragColumn(Table) {
|
||||
|
||||
return function (_Component) {
|
||||
_inherits(DragColumn, _Component);
|
||||
return function (_Component) {
|
||||
_inherits(DragColumn, _Component);
|
||||
|
||||
function DragColumn(props) {
|
||||
_classCallCheck(this, DragColumn);
|
||||
function DragColumn(props) {
|
||||
_classCallCheck(this, DragColumn);
|
||||
|
||||
var _this = _possibleConstructorReturn(this, _Component.call(this, props));
|
||||
var _this = _possibleConstructorReturn(this, _Component.call(this, props));
|
||||
|
||||
_this.setColumOrderByIndex = function (_column) {
|
||||
_column.forEach(function (da, i) {
|
||||
da.dragIndex = i;
|
||||
da.drgHover = false;
|
||||
});
|
||||
return _column;
|
||||
};
|
||||
_this.setColumOrderByIndex = function (_column) {
|
||||
_column.forEach(function (da, i) {
|
||||
da.dragIndex = i;
|
||||
da.drgHover = false;
|
||||
});
|
||||
return _column;
|
||||
};
|
||||
|
||||
_this.onDragEnd = function (event, data) {
|
||||
var dragSource = data.dragSource,
|
||||
dragTarg = data.dragTarg;
|
||||
var columns = _this.state.columns;
|
||||
_this.onDragEnd = function (event, data) {
|
||||
var dragSource = data.dragSource,
|
||||
dragTarg = data.dragTarg;
|
||||
var columns = _this.state.columns;
|
||||
|
||||
var sourceIndex = -1,
|
||||
targetIndex = -1;
|
||||
var sourceIndex = -1,
|
||||
targetIndex = -1;
|
||||
|
||||
sourceIndex = columns.findIndex(function (da, i) {
|
||||
return da.key == dragSource.key;
|
||||
});
|
||||
targetIndex = columns.findIndex(function (da, i) {
|
||||
return da.key == dragTarg.key;
|
||||
});
|
||||
// 向前移动
|
||||
if (targetIndex < sourceIndex) {
|
||||
targetIndex = targetIndex + 1;
|
||||
sourceIndex = columns.findIndex(function (da, i) {
|
||||
return da.key == dragSource.key;
|
||||
});
|
||||
targetIndex = columns.findIndex(function (da, i) {
|
||||
return da.key == dragTarg.key;
|
||||
});
|
||||
// 向前移动
|
||||
if (targetIndex < sourceIndex) {
|
||||
targetIndex = targetIndex + 1;
|
||||
}
|
||||
columns.splice(targetIndex, 0, columns.splice(sourceIndex, 1)[0]);
|
||||
var _newColumns = [];
|
||||
columns.forEach(function (da, i) {
|
||||
var newDate = _extends(da, {});
|
||||
newDate.title = da.title;
|
||||
_newColumns.push(newDate);
|
||||
});
|
||||
_this.setState({
|
||||
columns: _newColumns //cloneDeep(columns)
|
||||
});
|
||||
if (_this.props.onDragEnd) {
|
||||
_this.props.onDragEnd(event, data, columns);
|
||||
}
|
||||
};
|
||||
|
||||
_this.getTarget = function (evt) {
|
||||
return evt.target || evt.srcElement;
|
||||
};
|
||||
|
||||
_this.state = {
|
||||
columns: _this.setColumOrderByIndex(props.columns)
|
||||
};
|
||||
return _this;
|
||||
}
|
||||
columns.splice(targetIndex, 0, columns.splice(sourceIndex, 1)[0]);
|
||||
var _newColumns = [];
|
||||
columns.forEach(function (da, i) {
|
||||
var newDate = _extends(da, {});
|
||||
newDate.title = da.title;
|
||||
_newColumns.push(newDate);
|
||||
|
||||
DragColumn.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
|
||||
if (nextProps.columns != this.props.columns) {
|
||||
this.setState({
|
||||
columns: this.setColumOrderByIndex(nextProps.columns)
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
DragColumn.prototype.recursion = function (_recursion) {
|
||||
function recursion(_x) {
|
||||
return _recursion.apply(this, arguments);
|
||||
}
|
||||
|
||||
recursion.toString = function () {
|
||||
return _recursion.toString();
|
||||
};
|
||||
|
||||
return recursion;
|
||||
}(function (obj) {
|
||||
var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||||
|
||||
for (key in obj) {
|
||||
if (_typeof(obj[key]) == 'object' && Object.keys(obj[key].length > 0)) {
|
||||
data[key] = recursion(obj[key]);
|
||||
} else {
|
||||
data[key] = obj[key];
|
||||
}
|
||||
}
|
||||
return data;
|
||||
});
|
||||
_this.setState({
|
||||
columns: _newColumns //cloneDeep(columns)
|
||||
});
|
||||
if (_this.props.onDragEnd) {
|
||||
_this.props.onDragEnd(event, data, columns);
|
||||
}
|
||||
};
|
||||
|
||||
_this.getTarget = function (evt) {
|
||||
return evt.target || evt.srcElement;
|
||||
};
|
||||
DragColumn.prototype.render = function render() {
|
||||
var _props = this.props,
|
||||
data = _props.data,
|
||||
dragborder = _props.dragborder,
|
||||
draggable = _props.draggable,
|
||||
className = _props.className,
|
||||
others = _objectWithoutProperties(_props, ['data', 'dragborder', 'draggable', 'className']);
|
||||
|
||||
_this.state = {
|
||||
columns: _this.setColumOrderByIndex(props.columns)
|
||||
};
|
||||
return _this;
|
||||
}
|
||||
return _react2["default"].createElement(Table, _extends({}, others, {
|
||||
columns: this.state.columns,
|
||||
data: data,
|
||||
className: className + ' u-table-drag-border',
|
||||
onDragEnd: this.onDragEnd,
|
||||
draggable: draggable,
|
||||
dragborder: dragborder
|
||||
}));
|
||||
};
|
||||
|
||||
DragColumn.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
|
||||
if (nextProps.columns != this.props.columns) {
|
||||
this.setState({
|
||||
columns: this.setColumOrderByIndex(nextProps.columns)
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
DragColumn.prototype.recursion = function (_recursion) {
|
||||
function recursion(_x) {
|
||||
return _recursion.apply(this, arguments);
|
||||
}
|
||||
|
||||
recursion.toString = function () {
|
||||
return _recursion.toString();
|
||||
};
|
||||
|
||||
return recursion;
|
||||
}(function (obj) {
|
||||
var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||||
|
||||
for (key in obj) {
|
||||
if (_typeof(obj[key]) == 'object' && Object.keys(obj[key].length > 0)) {
|
||||
data[key] = recursion(obj[key]);
|
||||
} else {
|
||||
data[key] = obj[key];
|
||||
}
|
||||
}
|
||||
return data;
|
||||
});
|
||||
|
||||
DragColumn.prototype.render = function render() {
|
||||
var _props = this.props,
|
||||
data = _props.data,
|
||||
dragborder = _props.dragborder,
|
||||
draggable = _props.draggable,
|
||||
className = _props.className,
|
||||
others = _objectWithoutProperties(_props, ['data', 'dragborder', 'draggable', 'className']);
|
||||
|
||||
return _react2["default"].createElement(Table, _extends({}, others, {
|
||||
columns: this.state.columns,
|
||||
data: data,
|
||||
className: className + ' u-table-drag-border',
|
||||
onDragEnd: this.onDragEnd,
|
||||
draggable: draggable,
|
||||
dragborder: dragborder
|
||||
}));
|
||||
};
|
||||
|
||||
return DragColumn;
|
||||
}(_react.Component);
|
||||
return DragColumn;
|
||||
}(_react.Component);
|
||||
}
|
||||
module.exports = exports['default'];
|
||||
|
|
@ -57,34 +57,31 @@ function sort(Table, Icon) {
|
|||
var flatColumns = [];
|
||||
_this2._toFlatColumn(props.columns, -1, flatColumns);
|
||||
_this2.state = { data: _this2.props.data, columns: props.columns, flatColumns: flatColumns };
|
||||
_this2._initSort();
|
||||
|
||||
return _this2;
|
||||
}
|
||||
|
||||
//默认是前端排序,值为true为后端排序
|
||||
|
||||
SortTable.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
|
||||
|
||||
if (nextProps.columns !== this.props.columns) {
|
||||
var flatColumns = [];
|
||||
this._toFlatColumn(nextProps.columns, -1, flatColumns);
|
||||
this.setState({ columns: nextProps.columns, flatColumns: flatColumns });
|
||||
}
|
||||
|
||||
if (nextProps.data !== this.props.data) {
|
||||
this.setState({
|
||||
data: nextProps.data,
|
||||
oldData: nextProps.data.concat()
|
||||
}, function () {
|
||||
this._initSort(); // 数据更新后需要重新排序
|
||||
});
|
||||
}
|
||||
if (nextProps.columns !== this.props.columns) {
|
||||
var flatColumns = [];
|
||||
this._toFlatColumn(nextProps.columns, -1, flatColumns);
|
||||
this.setState({ columns: nextProps.columns, flatColumns: flatColumns });
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
*column扁平化处理,适应多表头避免递归操作
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
SortTable.prototype._toFlatColumn = function _toFlatColumn(columns) {
|
||||
var parentIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : -1;
|
||||
var flatColumns = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
||||
|
|
@ -167,24 +164,6 @@ function sort(Table, Icon) {
|
|||
}(_react.Component), _class.defaultProps = { sort: { mode: "single", backSource: false } }, _initialiseProps = function _initialiseProps() {
|
||||
var _this3 = this;
|
||||
|
||||
this._initSort = function () {
|
||||
var flatColumns = _this3.state.flatColumns;
|
||||
|
||||
var needSort = false;
|
||||
flatColumns.forEach(function (item) {
|
||||
if (item.order == 'descend' || item.order == 'ascend') {
|
||||
needSort = true;
|
||||
return;
|
||||
}
|
||||
});
|
||||
if (needSort) {
|
||||
var data = _this3.multiSort(flatColumns);
|
||||
_this3.setState({
|
||||
data: data
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
this.getOrderNum = function () {
|
||||
var orderNum = 0;
|
||||
//todo 1
|
||||
|
|
@ -228,8 +207,13 @@ function sort(Table, Icon) {
|
|||
|
||||
this._sortBy = function (pre, after, orderCols, orderColslen, currentIndex) {
|
||||
var currentCol = orderCols[currentIndex];
|
||||
var getMultiSorterValueFunc = currentCol.getMultiSorterValue;
|
||||
var preKey = pre[currentCol.key];
|
||||
var afterKey = after[currentCol.key];
|
||||
if (getMultiSorterValueFunc) {
|
||||
preKey = getMultiSorterValueFunc(pre, currentCol);
|
||||
afterKey = getMultiSorterValueFunc(after, currentCol);
|
||||
}
|
||||
var colSortFun = currentCol.sorter;
|
||||
if (typeof colSortFun !== 'function') {
|
||||
colSortFun = function colSortFun() {
|
||||
|
|
@ -249,8 +233,7 @@ function sort(Table, Icon) {
|
|||
this.multiSort = function (columns) {
|
||||
var _state = _this3.state,
|
||||
data = _state.data,
|
||||
_state$oldData = _state.oldData,
|
||||
oldData = _state$oldData === undefined ? [] : _state$oldData;
|
||||
oldData = _state.oldData;
|
||||
|
||||
var self = _this3;
|
||||
var orderCols = {},
|
||||
|
|
@ -275,8 +258,7 @@ function sort(Table, Icon) {
|
|||
this.toggleSortOrder = function (order, column) {
|
||||
var _state2 = _this3.state,
|
||||
data = _state2.data,
|
||||
_state2$oldData = _state2.oldData,
|
||||
oldData = _state2$oldData === undefined ? [] : _state2$oldData,
|
||||
oldData = _state2.oldData,
|
||||
flatColumns = _state2.flatColumns;
|
||||
var sort = _this3.props.sort;
|
||||
|
||||
|
|
@ -315,7 +297,7 @@ function sort(Table, Icon) {
|
|||
} else {
|
||||
data = oldData.concat();
|
||||
}
|
||||
typeof sort.sortFun === "function" && sort.sortFun(sortCol, data, oldData);
|
||||
typeof sort.sortFun === "function" && sort.sortFun(sortCol, data);
|
||||
}
|
||||
} else {
|
||||
seleObj = flatColumns.find(function (da) {
|
||||
|
|
@ -333,7 +315,7 @@ function sort(Table, Icon) {
|
|||
sort.sortFun(sortCol);
|
||||
} else {
|
||||
data = _this3.multiSort(flatColumns);
|
||||
typeof sort.sortFun === "function" && sort.sortFun(sortCol, data, oldData);
|
||||
typeof sort.sortFun === "function" && sort.sortFun(sortCol, data);
|
||||
}
|
||||
}
|
||||
_this3.setState({ data: data, oldData: oldData, flatColumns: flatColumns });
|
||||
|
|
|
|||
|
|
@ -25,8 +25,6 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen
|
|||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : _defaults(subClass, superClass); }
|
||||
|
||||
function sum(Table) {
|
||||
var precision = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2;
|
||||
|
||||
return function (_React$Component) {
|
||||
_inherits(SumTable, _React$Component);
|
||||
|
||||
|
|
@ -93,14 +91,7 @@ function sum(Table) {
|
|||
count += _num;
|
||||
}
|
||||
});
|
||||
var _sum = (0, _utils.DicimalFormater)(count, precision);
|
||||
if (column.sumThousandth) {
|
||||
_sum = _this.toThousands(_sum);
|
||||
}
|
||||
sumdata[column.dataIndex] = _sum;
|
||||
if (column.sumRender && typeof column.sumRender == 'function') {
|
||||
sumdata[column.dataIndex] = column.sumRender(_sum);
|
||||
}
|
||||
sumdata[column.dataIndex] = (0, _utils.DicimalFormater)(count, 2);
|
||||
}
|
||||
if (index == 0) {
|
||||
sumdata[column.dataIndex] = "合计 " + sumdata[column.dataIndex];
|
||||
|
|
@ -117,26 +108,10 @@ function sum(Table) {
|
|||
|
||||
/**
|
||||
* 获取当前的表格类型。
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
SumTable.prototype.toThousands = function toThousands(num) {
|
||||
var result = '',
|
||||
counter = 0;
|
||||
num = (num || 0).toString();
|
||||
var numArr = num.split('.');
|
||||
num = numArr[0];
|
||||
for (var i = num.length - 1; i >= 0; i--) {
|
||||
counter++;
|
||||
result = num.charAt(i) + result;
|
||||
if (!(counter % 3) && i != 0) {
|
||||
result = ',' + result;
|
||||
}
|
||||
}
|
||||
return numArr.length === 1 ? result : result + '.' + numArr[1];
|
||||
};
|
||||
|
||||
SumTable.prototype.render = function render() {
|
||||
return _react2["default"].createElement(Table, _extends({}, this.props, {
|
||||
columns: this.props.columns,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
value: true
|
||||
});
|
||||
|
||||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
|
||||
|
|
@ -20,29 +20,29 @@ exports.ObjectAssign = ObjectAssign;
|
|||
*/
|
||||
|
||||
function sortBy(arr, prop, desc) {
|
||||
var props = [],
|
||||
ret = [],
|
||||
i = 0,
|
||||
len = arr.length;
|
||||
if (typeof prop == 'string') {
|
||||
for (; i < len; i++) {
|
||||
var oI = arr[i];
|
||||
(props[i] = new String(oI && oI[prop] || ''))._obj = oI;
|
||||
}
|
||||
} else if (typeof prop == 'function') {
|
||||
for (; i < len; i++) {
|
||||
var _oI = arr[i];
|
||||
(props[i] = new String(_oI && prop(_oI) || ''))._obj = _oI;
|
||||
}
|
||||
} else {
|
||||
throw '参数类型错误';
|
||||
var props = [],
|
||||
ret = [],
|
||||
i = 0,
|
||||
len = arr.length;
|
||||
if (typeof prop == 'string') {
|
||||
for (; i < len; i++) {
|
||||
var oI = arr[i];
|
||||
(props[i] = new String(oI && oI[prop] || ''))._obj = oI;
|
||||
}
|
||||
props.sort();
|
||||
for (i = 0; i < len; i++) {
|
||||
ret[i] = props[i]._obj;
|
||||
} else if (typeof prop == 'function') {
|
||||
for (; i < len; i++) {
|
||||
var _oI = arr[i];
|
||||
(props[i] = new String(_oI && prop(_oI) || ''))._obj = _oI;
|
||||
}
|
||||
if (desc) ret.reverse();
|
||||
return ret;
|
||||
} else {
|
||||
throw '参数类型错误';
|
||||
}
|
||||
props.sort();
|
||||
for (i = 0; i < len; i++) {
|
||||
ret[i] = props[i]._obj;
|
||||
}
|
||||
if (desc) ret.reverse();
|
||||
return ret;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -51,11 +51,11 @@ function sortBy(arr, prop, desc) {
|
|||
* @param {} property
|
||||
*/
|
||||
function compare(property) {
|
||||
return function (a, b) {
|
||||
var value1 = a[property];
|
||||
var value2 = b[property];
|
||||
return value1 - value2;
|
||||
};
|
||||
return function (a, b) {
|
||||
var value1 = a[property];
|
||||
var value2 = b[property];
|
||||
return value1 - value2;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -63,17 +63,17 @@ function compare(property) {
|
|||
* @param {*} obj 要拷贝的对象
|
||||
*/
|
||||
function ObjectAssign(obj) {
|
||||
var b = obj instanceof Array;
|
||||
var tagObj = b ? [] : {};
|
||||
if (b) {
|
||||
//数组
|
||||
obj.forEach(function (da) {
|
||||
var _da = {};
|
||||
_extends(_da, da);
|
||||
tagObj.push(_da);
|
||||
});
|
||||
} else {
|
||||
_extends(tagObj, obj);
|
||||
}
|
||||
return tagObj;
|
||||
var b = obj instanceof Array;
|
||||
var tagObj = b ? [] : {};
|
||||
if (b) {
|
||||
//数组
|
||||
obj.forEach(function (da) {
|
||||
var _da = {};
|
||||
_extends(_da, da);
|
||||
tagObj.push(_da);
|
||||
});
|
||||
} else {
|
||||
_extends(tagObj, obj);
|
||||
}
|
||||
return tagObj;
|
||||
}
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
module.exports = {
|
||||
extends: ['@commitlint/config-conventional']
|
||||
}
|
||||
|
|
@ -1,62 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* @title 悬浮列
|
||||
* @parent 列渲染 Custom Render
|
||||
* @description 鼠标hover行时呼出操作按钮。
|
||||
* demo0401
|
||||
*/
|
||||
|
||||
import React, { Component } from "react";
|
||||
import {Button,Popconfirm} from "tinper-bee";
|
||||
import Table from "../../src";
|
||||
|
||||
const columns = [
|
||||
{ title: "员工编号", dataIndex: "a", key: "a", width: 150 },
|
||||
{ title: "员工姓名", dataIndex: "b", key: "b", width: 100 },
|
||||
{ title: "性别", dataIndex: "c", key: "c", width: 100 },
|
||||
{ title: "部门", dataIndex: "d", key: "d", width: 100 }
|
||||
];
|
||||
|
||||
const data = [
|
||||
{ a: "ASVAL_201903280005", b: "小张", c: "男", d: "财务二科", key: "1" },
|
||||
{ a: "ASVAL_201903200004", b: "小明", c: "男", d: "财务一科", key: "2" },
|
||||
{ a: "ASVAL_201903120002", b: "小红", c: "女", d: "财务一科", key: "3" }
|
||||
];
|
||||
|
||||
class Demo11 extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
}
|
||||
|
||||
deleteRow=()=>{
|
||||
console.log('删除第' , this.currentIndex , '行');
|
||||
}
|
||||
|
||||
onRowHover=(index,record)=>{
|
||||
this.currentIndex = index;
|
||||
this.currentRecord = record;
|
||||
}
|
||||
|
||||
getHoverContent=(record, index)=>{
|
||||
return (
|
||||
<div className="opt-btns">
|
||||
<Popconfirm key={index} trigger="click" placement="left" content="是否删除当前行?" onClose={this.deleteRow}>
|
||||
<Button size="sm">删除</Button>
|
||||
</Popconfirm>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Table
|
||||
columns={columns}
|
||||
data={data}
|
||||
onRowHover={this.onRowHover}
|
||||
hoverContent={this.getHoverContent}
|
||||
/>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default Demo11;
|
||||
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
import React, { Component } from "react";
|
||||
import Table from "../../src";
|
||||
import {Button} from "tinper-bee";
|
||||
|
||||
import dragColumn from '../../src/lib/dragColumn';
|
||||
|
||||
|
|
@ -105,7 +106,7 @@ for (let i = 0; i < 20; i++) {
|
|||
|
||||
const DragColumnTable = dragColumn(Table);
|
||||
|
||||
class Demo12 extends Component {
|
||||
class Demo32 extends Component {
|
||||
render() {
|
||||
return (
|
||||
<DragColumnTable
|
||||
|
|
@ -124,4 +125,4 @@ class Demo12 extends Component {
|
|||
}
|
||||
}
|
||||
|
||||
export default Demo12;
|
||||
export default Demo32;
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ const data = [
|
|||
const MultiSelectTable = multiSelect(Table, Checkbox);
|
||||
const ComplexTable = sort(MultiSelectTable, Icon);
|
||||
|
||||
class Demo13 extends Component {
|
||||
class Demo33 extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
}
|
||||
|
|
@ -101,4 +101,4 @@ class Demo13 extends Component {
|
|||
}
|
||||
}
|
||||
|
||||
export default Demo13;
|
||||
export default Demo33;
|
||||
|
|
@ -8,12 +8,11 @@
|
|||
|
||||
import React, { Component } from "react";
|
||||
import {Checkbox} from "tinper-bee";
|
||||
import Table from "../../src";
|
||||
import Table from "../../src";
|
||||
import sum from "../../src/lib/sum.js";
|
||||
import multiSelect from "../../src/lib/multiSelect.js";
|
||||
|
||||
|
||||
let ComplexTable = multiSelect(sum(Table), Checkbox);
|
||||
//sum第二个参数可以设置精度,例如 sum(Table,4); 设计精度为4
|
||||
let _sum = 0;
|
||||
const columns = [
|
||||
{
|
||||
|
|
@ -57,16 +56,14 @@ const columns = [
|
|||
dataIndex: "total",
|
||||
key: "total",
|
||||
width: 100,
|
||||
sumCol: true,
|
||||
sumThousandth: true
|
||||
sumCol: true
|
||||
},
|
||||
{
|
||||
title: "金额",
|
||||
dataIndex: "money",
|
||||
key: "money",
|
||||
width: 100,
|
||||
sumCol: true,
|
||||
sumThousandth: true
|
||||
sumCol: true
|
||||
}
|
||||
];
|
||||
|
||||
|
|
@ -82,7 +79,7 @@ function getData(){
|
|||
contact: "Tom",
|
||||
warehouse: "普通仓",
|
||||
total: i + Math.floor(Math.random()*10),
|
||||
money: 2000 * Math.floor(Math.random()*10)
|
||||
money: 20 * Math.floor(Math.random()*10)
|
||||
});
|
||||
_sum += data[i].total;
|
||||
_sum += data[i].money;
|
||||
|
|
@ -91,7 +88,7 @@ function getData(){
|
|||
}
|
||||
|
||||
class Demo35 extends Component {
|
||||
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
|
|
@ -104,7 +101,7 @@ class Demo35 extends Component {
|
|||
const {data} = this.state;
|
||||
return (
|
||||
<div>
|
||||
<ComplexTable
|
||||
<ComplexTable
|
||||
columns={columns}
|
||||
data={data}
|
||||
bordered
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
import React, { Component } from 'react';
|
||||
import Table from '../../src';
|
||||
|
||||
const columns = [
|
||||
const columns26 = [
|
||||
{ title: "姓名", width: 180, dataIndex: "name", key: "name", filterType: "text", filterDropdown: "show" },
|
||||
{ title: "年龄", width: 150, dataIndex: "age", key: "age", filterType: "dropdown", filterDropdown: "show" },
|
||||
{ title: "日期", width: 200, dataIndex: "date", key: "date", filterType: "date", filterDropdown: "show", format: "YYYY-MM-DD" },
|
||||
|
|
@ -17,7 +17,7 @@ const columns = [
|
|||
{ title: "备注", dataIndex: "mark", key: "mark" }
|
||||
];
|
||||
|
||||
const data = [
|
||||
const data26 = [
|
||||
{
|
||||
key: "1",
|
||||
name: "John Brown",
|
||||
|
|
@ -83,7 +83,7 @@ const data = [
|
|||
}
|
||||
];
|
||||
|
||||
class Demo23 extends Component {
|
||||
class Demo26 extends Component {
|
||||
handlerFilterChange = (key, val, condition) => {
|
||||
console.log('参数:key=', key, ' value=', val, 'condition=', condition);
|
||||
}
|
||||
|
|
@ -98,9 +98,9 @@ class Demo23 extends Component {
|
|||
filterDelay={500}//输入文本多少ms触发回调函数,默认300ms
|
||||
filterable={true}//是否开启过滤数据功能
|
||||
bordered
|
||||
columns={columns}
|
||||
data={data} />;
|
||||
columns={columns26}
|
||||
data={data26} />;
|
||||
}
|
||||
}
|
||||
|
||||
export default Demo23;
|
||||
export default Demo26;
|
||||
|
|
@ -13,7 +13,7 @@ import Table from '../../src';
|
|||
import multiSelect from '../../src/lib/multiSelect';
|
||||
import sort from '../../src/lib/sort';
|
||||
|
||||
const data = [
|
||||
const data27 = [
|
||||
{
|
||||
key: "1",
|
||||
name: "John Brown",
|
||||
|
|
@ -82,7 +82,7 @@ const data = [
|
|||
|
||||
const MultiSelectTable = multiSelect(Table, Checkbox);
|
||||
const ComplexTable = sort(MultiSelectTable, Icon);
|
||||
class Demo24 extends Component {
|
||||
class Demo27 extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
|
|
@ -107,7 +107,7 @@ class Demo24 extends Component {
|
|||
let multiObj = {
|
||||
type: "checkbox"
|
||||
};
|
||||
let columns = [
|
||||
let columns27 = [
|
||||
{
|
||||
title: "姓名",
|
||||
width: 180,
|
||||
|
|
@ -162,9 +162,9 @@ class Demo24 extends Component {
|
|||
getSelectedDataFunc={this.getSelectedDataFunc}
|
||||
bordered
|
||||
multiSelect={multiObj}
|
||||
columns={columns}
|
||||
data={data} />;
|
||||
columns={columns27}
|
||||
data={data27} />;
|
||||
}
|
||||
}
|
||||
|
||||
export default Demo24;
|
||||
export default Demo27;
|
||||
|
|
@ -56,11 +56,7 @@ const columns13 = [
|
|||
key: "e",
|
||||
width: 200,
|
||||
sumCol: true,
|
||||
sorter: (pre, after) => pre.e.value - after.e.value,
|
||||
// getMultiSorterValue: (data, col) => {},
|
||||
render: (text, data) => {
|
||||
return text.value
|
||||
}
|
||||
sorter: (pre, after) => pre.e - after.e,
|
||||
},
|
||||
{
|
||||
title: "供应商",
|
||||
|
|
@ -71,13 +67,14 @@ const columns13 = [
|
|||
];
|
||||
|
||||
const data13 = [
|
||||
{ a: "NU0391001", b: 675, c: 30, d: "xx供应商",e:{value: 120}, key: "2" },
|
||||
{ a: "NU0391002", b: 43, c: 41, d: "yy供应商",e:{value: 90}, key: "1" },
|
||||
{ a: "NU0391003", b: 43, c: 81, d: "zz供应商", e:{value: 120},key: "4" },
|
||||
{ a: "NU0391004", b: 43, c: 81, d: "aa供应商", e:{value: 110},key: "5" },
|
||||
{ a: "NU0391005", b: 153, c: 25, d: "bb供应商",e:{value: 90}, key: "3" }
|
||||
{ a: "NU0391001", b: 675, c: 30, d: "xx供应商",e:100, key: "2" },
|
||||
{ a: "NU0391002", b: 43, c: 41, d: "yy供应商",e:90, key: "1" },
|
||||
{ a: "NU0391003", b: 43, c: 81, d: "zz供应商", e:120,key: "4" },
|
||||
{ a: "NU0391004", b: 43, c: 81, d: "aa供应商", e:130,key: "5" },
|
||||
{ a: "NU0391005", b: 153, c: 25, d: "bb供应商",e:90, key: "3" }
|
||||
];
|
||||
|
||||
|
||||
//拼接成复杂功能的table组件不能在render中定义,需要像此例子声明在组件的外侧,不然操作state会导致功能出现异常
|
||||
let ComplexTable = multiSelect(sort(sum(Table, Icon)), Checkbox);
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@
|
|||
* demo1001
|
||||
*/
|
||||
import React, { Component } from 'react';
|
||||
import {Icon} from "tinper-bee";
|
||||
|
||||
import Table from '../../src';
|
||||
import dragColumn from '../../src/lib/dragColumn';
|
||||
|
||||
|
|
@ -53,11 +55,11 @@ const data = [
|
|||
|
||||
const DragColumnTable = dragColumn(Table);
|
||||
|
||||
const defaultProps29 = {
|
||||
const defaultProps22 = {
|
||||
prefixCls: "bee-table"
|
||||
};
|
||||
|
||||
class Demo29 extends Component {
|
||||
class Demo22 extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
}
|
||||
|
|
@ -86,5 +88,5 @@ class Demo29 extends Component {
|
|||
}
|
||||
}
|
||||
|
||||
Demo29.defaultProps = defaultProps29;
|
||||
export default Demo29;
|
||||
Demo22.defaultProps = defaultProps22;
|
||||
export default Demo22;
|
||||
|
|
@ -10,7 +10,7 @@ import React, { Component } from 'react';
|
|||
import Table from '../../src';
|
||||
import dragColumn from '../../src/lib/dragColumn';
|
||||
|
||||
const columns = [
|
||||
const columns23 = [
|
||||
{
|
||||
title: "订单编号",
|
||||
dataIndex: "a",
|
||||
|
|
@ -38,7 +38,7 @@ const columns = [
|
|||
}
|
||||
];
|
||||
|
||||
const data = [
|
||||
const data23 = [
|
||||
{ a: "NU0391001", b: "2019-03-01", c: "xx供应商",d:'Tom', key: "2" },
|
||||
{ a: "NU0391002", b: "2018-11-02", c: "yy供应商",d:'Jack', key: "1" },
|
||||
{ a: "NU0391003", b: "2019-05-03", c: "zz供应商",d:'Jane', key: "3" }
|
||||
|
|
@ -46,15 +46,15 @@ const data = [
|
|||
|
||||
const DragColumnTable = dragColumn(Table);
|
||||
|
||||
class Demo30 extends Component {
|
||||
class Demo23 extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
}
|
||||
|
||||
render() {
|
||||
return <DragColumnTable
|
||||
columns={columns}
|
||||
data={data}
|
||||
columns={columns23}
|
||||
data={data23}
|
||||
bordered
|
||||
scroll={{y:200}}
|
||||
dragborder={true}
|
||||
|
|
@ -65,4 +65,4 @@ class Demo30 extends Component {
|
|||
}
|
||||
}
|
||||
|
||||
export default Demo30;
|
||||
export default Demo23;
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* @title 拖拽改变行顺序
|
||||
* @parent 行操作-拖拽
|
||||
* @description `rowDraggAble`参数设置是否使用行交换顺序功能,`useDragHandle`设置拖拽把手,`onDropRow` 是拖拽行后的回调函数。注意:表格行数据必须有唯一标识,可以通过 `data.key` 或 `rowKey` 两种方式传入。
|
||||
* @description `rowDraggAble`参数设置是否使用行交换顺序功能,`onDropRow` 是拖拽行后的回调函数。注意:表格行数据必须有唯一标识,可以通过 `data.key` 或 `rowKey` 两种方式传入。
|
||||
* Demo1201
|
||||
*/
|
||||
|
||||
|
|
@ -30,7 +30,7 @@ const data = [
|
|||
{ a: "ASVAL_201903120007", b: "小杨", c: "女", d: "财务四科", e: "T2", key: "1009" }
|
||||
];
|
||||
|
||||
class Demo38 extends Component {
|
||||
class Demo1201 extends Component {
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
|
@ -69,7 +69,6 @@ class Demo38 extends Component {
|
|||
columns={columns}
|
||||
data={data}
|
||||
rowDraggAble={true}
|
||||
// useDragHandle={true}
|
||||
onDragRowStart={this.onDragRowStart}
|
||||
onDropRow={this.onDropRow}
|
||||
/>
|
||||
|
|
@ -77,4 +76,4 @@ class Demo38 extends Component {
|
|||
}
|
||||
}
|
||||
|
||||
export default Demo38;
|
||||
export default Demo1201;
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ const data = [ ...new Array(10000) ].map((e, i) => {
|
|||
})
|
||||
|
||||
|
||||
class Demo43 extends Component {
|
||||
class Demo32 extends Component {
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
|
@ -87,4 +87,4 @@ class Demo43 extends Component {
|
|||
}
|
||||
}
|
||||
|
||||
export default Demo43;
|
||||
export default Demo32;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
import polyfill from '@babel/polyfill'
|
||||
import React, { Component } from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import { Con, Row, Col } from 'bee-layout';
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -162,10 +162,6 @@
|
|||
position: relative;
|
||||
line-height: 1.33;
|
||||
overflow: hidden; }
|
||||
.u-table.copy .u-table-thead th {
|
||||
-webkit-user-select: unset;
|
||||
-ms-user-select: unset;
|
||||
user-select: unset; }
|
||||
.u-table-body {
|
||||
position: relative; }
|
||||
.u-table-body .u-table-row-expand-columns-in-body .expand-icon-con {
|
||||
|
|
@ -452,8 +448,8 @@
|
|||
color: rgb(33, 33, 33);
|
||||
background-clip: padding-box;
|
||||
-webkit-user-select: none;
|
||||
/*
|
||||
Introduced in IE 10.
|
||||
/*
|
||||
Introduced in IE 10.
|
||||
*/
|
||||
-ms-user-select: none;
|
||||
user-select: none; }
|
||||
|
|
@ -608,7 +604,7 @@
|
|||
display: none; }
|
||||
.u-table ::-webkit-scrollbar-track-piece {
|
||||
display: none; }
|
||||
.u-table .drag-handle-column, .u-table .row-dragg-able {
|
||||
.u-table .row-dragg-able {
|
||||
cursor: move; }
|
||||
.u-table .u-table-drag-hidden-cont {
|
||||
width: 100px;
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
17
docs/api.md
17
docs/api.md
|
|
@ -56,7 +56,6 @@ import 'bee-table/build/Table.css';
|
|||
|collapsedIcon|嵌套表格场景中关闭子表时的关闭图标|||
|
||||
| expandRowByClick | 设置展开行是否通过点击行触发,此参数需要与上面参数搭配使用(默认是通过点击行前面的加号展开行 | bool | false |
|
||||
| rowDraggAble | 是否增加行交换顺序功能 | boolean| false |
|
||||
| useDragHandle | 通过行手柄进行拖拽排序,在 `rowDraggAble` 为 `true` 时有效 | boolean| false |
|
||||
| showHeader | 是否显示表头 | bool | true |
|
||||
| title | 表格标题 | Function | - |
|
||||
| footer | 表格尾部 | Function | - |
|
||||
|
|
@ -85,12 +84,6 @@ import 'bee-table/build/Table.css';
|
|||
| [v2.2.2新增]showRowNum | 展示序号功能,false时不展示,true时展示默认情况,可传入自定义配置信息 | bool / obj:{name: '序号', key: '_index', // 在数据中存储的key值width: 50,base: 0,// 排序的基准值,为数字或者字母type:'number', // 排序类型,默认为number类型,支持单字母排序(type='ascii')} | false |
|
||||
| [v2.2.8新增]autoCheckedByClickRows | 设置为 false 时,表格行点击事件,不会自动勾选复选框 | bool | true |
|
||||
| [v2.2.8新增]autoSelect | 树型表格勾选时,是否开启子节点的联动 | bool | false |
|
||||
| onPaste | 粘贴的回调函数 | func(event,positon) | - |
|
||||
| onCopy | 复制列的回调函数 | func(data,event) | - |
|
||||
| onBodyScroll | table body 滚动的回调 | func(scrollTop) | - |
|
||||
| syncRowHeight | 滚动是否同步高度,关闭此功能有利于提高性能,注:树表和主子表不允许关闭 | true | - |
|
||||
|onBodyMouseLeave| 移除表体的回调事件| func() |-|
|
||||
|
||||
|
||||
> 快捷键部分参考示例 (快捷键在table中的简单使用应用)
|
||||
|
||||
|
|
@ -128,13 +121,12 @@ import 'bee-table/build/Table.css';
|
|||
|width|宽度的特定比例根据列的宽度计算|String/Number|-|
|
||||
|fixed| 当表水平滚动时,此列将被固定:true或'left'或'right'| true/'left'/'right'|-|
|
||||
|sorter|前端列排序方法,只要列上有此属性就说明这列可排序。**注:默认是前端排序,排序方法书写时注意有些字段的值可能是undefined的情况,需要转换成0**| function|-|
|
||||
|getMultiSorterValue| 多列排序的时候,可以使用此方法得到单元格中显示的值,用来进行排序中的判断|Function(data, currentCol)|-|
|
||||
|getMultiSorterValue| 多列排序的时候,可以使用此方法得到单元格中显示的值,用来进行排序中的判断|Function(data, col)|-|
|
||||
|sorterClick|排序的回调函数|function|-|
|
||||
|render|cell的render函数有三个参数:这个单元格的文本,这行的记录,这行的索引,它返回一个对象:{children:value,props:{colSpan:1,rowSpan:1}} ==>'children'是这个单元格的文本,props是这个单元格的一些设置,可以设置单元格行/列合并。2.2.48及以后版本新增第四个参数options为column设置的属性|-|
|
||||
|onCellClick|单击列的单元格时调用|Function(row, event)|-|
|
||||
|onHeadCellClick|单击表头的单元格时调用|Function(row, event)|row 当前行的数据|
|
||||
| order | 设置排序 | string("descend"、"ascend") | -|
|
||||
| orderNum | 多列排序时,用来设置排序优先级(1的优先级最高) | number | -|
|
||||
| filterType | 过滤下拉的类型.可选`text(文本框)`,`dropdown(下拉)`,`date(日期)`,`dateyear(日期-年)`,`datemonth(日期-月)`,`dateweek(日期-周)`,`daterange(日期范围)`,`number(数值)` | string | text |
|
||||
| filterDropdown | 是否显示过滤下拉.可选`show`,`hide` | string | show |
|
||||
| format | 针对过滤下拉设置日期类的格式 | string | YYYY-MM-DD |
|
||||
|
|
@ -157,8 +149,6 @@ import 'bee-table/build/Table.css';
|
|||
| isShow | 是否展示该列数据 | bool | true |
|
||||
| cellMenu | 渲染单元格内操作按钮 | object | - |
|
||||
| style | 该列的样式,严格按照react的样式书写规则,即对象内每一个属性的键为小写驼峰式,值为字符串 | object | - |
|
||||
| sumRender | 自定义合计render函数 | func(value) | - |
|
||||
|getCellClassName|自定义单元格样式| func(record,index,column) record:当前行数据,index:行索引,column:当前列索引|-|
|
||||
|
||||
#### [v2.2.x新增] cellMenu
|
||||
|
||||
|
|
@ -351,9 +341,6 @@ import { Table } from 'tinper-bee';
|
|||
|
||||
const SumTable = sum(Table);
|
||||
|
||||
//[v2.2.49新增]precision为精度,默认为2
|
||||
const SumTable = sum(Table,precision);
|
||||
|
||||
```
|
||||
|
||||
#### API
|
||||
|
|
@ -365,7 +352,7 @@ column 数组参数:
|
|||
| sumCol | 该列设置为合计列,合计行中会显示合计数据 | boolean | false |
|
||||
|
||||
#### sum 使用示例
|
||||
- [列合计(总计)](http://bee.tinper.org/tinper-bee/bee-table#%E5%88%97%E5%90%88%E8%AE%A1%EF%BC%88%E6%80%BB%E8%AE%A1%EF%BC%89)
|
||||
- [列合计(总计)](http://design.yonyoucloud.com/tinper-bee/bee-table#%E5%88%97%E5%90%88%E8%AE%A1%EF%BC%88%E6%80%BB%E8%AE%A1%EF%BC%89)
|
||||
|
||||
### dragColumn 拖拽列功能
|
||||
|
||||
|
|
|
|||
|
|
@ -20,8 +20,5 @@
|
|||
<script src="//design.yonyoucloud.com/static/react/16.8.4/umd/react-dom.development.js"></script>
|
||||
<script src="//design.yonyoucloud.com/static/prop-types/15.6.0/prop-types.min.js"></script>
|
||||
<script src="./dist/demo.js"></script>
|
||||
<script>
|
||||
console.log(111)
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
13
package.json
13
package.json
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "bee-table",
|
||||
"version": "2.3.14",
|
||||
"version": "2.2.48.2",
|
||||
"description": "Table ui component for react",
|
||||
"keywords": [
|
||||
"react",
|
||||
|
|
@ -41,10 +41,7 @@
|
|||
"coveralls": "jest",
|
||||
"browsers": "bee-tools run browsers",
|
||||
"pub": "bee-tools run pub",
|
||||
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0",
|
||||
"version": "conventional-changelog -p angular -i CHANGELOG.md -s && git add CHANGELOG.md",
|
||||
"postversion": "git push --follow-tags",
|
||||
"prepublishOnly": "npm run build"
|
||||
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0"
|
||||
},
|
||||
"dependencies": {
|
||||
"bee-button": "latest",
|
||||
|
|
@ -74,7 +71,6 @@
|
|||
"prop-types": "^15.6.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/polyfill": "^7.12.1",
|
||||
"babel-jest": "^22.0.4",
|
||||
"bee-clipboard": "^2.0.0",
|
||||
"bee-drawer": "0.0.2",
|
||||
|
|
@ -94,7 +90,6 @@
|
|||
"react-dom": "^16.6.3",
|
||||
"ref-tree": "2.0.1-beta.1",
|
||||
"reqwest": "^2.0.5",
|
||||
"tinper-bee": "latest",
|
||||
"husky": "^4.2.5"
|
||||
"tinper-bee": "latest"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -27,7 +27,6 @@ export default class ColumnManager {
|
|||
key: "dragHandle",
|
||||
dataIndex: "dragHandle",
|
||||
width: 49,
|
||||
draggable: true,
|
||||
render: () => {
|
||||
return <Icon type="uf-navmenu" />
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,11 +49,8 @@ class FilterType extends Component {
|
|||
*
|
||||
*/
|
||||
changeText = (val) => {
|
||||
let { onFilterChange, dataIndex } = this.props;
|
||||
this.setState({
|
||||
value: val
|
||||
}, () => {
|
||||
onFilterChange(dataIndex, val, this.state.condition);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
151
src/Table.js
151
src/Table.js
|
|
@ -59,15 +59,12 @@ const propTypes = {
|
|||
hoverContent:PropTypes.func,
|
||||
size: PropTypes.oneOf(['sm', 'md', 'lg']),
|
||||
rowDraggAble: PropTypes.bool,
|
||||
hideDragHandle: PropTypes.bool, // 隐藏行拖拽把手
|
||||
onDropRow: PropTypes.func,
|
||||
onDragRowStart: PropTypes.func,
|
||||
onBodyScroll: PropTypes.func,
|
||||
bodyDisplayInRow: PropTypes.bool, // 表格内容超出列宽度时进行换行 or 以...形式展现
|
||||
headerDisplayInRow: PropTypes.bool, // 表头内容超出列宽度时进行换行 or 以...形式展现
|
||||
showRowNum: PropTypes.oneOfType([PropTypes.bool, PropTypes.object]), // 表格是否自动生成序号,格式为{base:number || 0,defaultKey:string || '_index',defaultName:string || '序号'}
|
||||
onPaste:PropTypes.func,
|
||||
onBodyMouseLeave: PropTypes.func
|
||||
};
|
||||
|
||||
const defaultProps = {
|
||||
|
|
@ -99,20 +96,18 @@ const defaultProps = {
|
|||
minColumnWidth: 80,
|
||||
locale:{},
|
||||
syncHover: true,
|
||||
// setRowHeight:()=>{},
|
||||
setRowHeight:()=>{},
|
||||
setRowParentIndex:()=>{},
|
||||
tabIndex:'0',
|
||||
heightConsistent:false,
|
||||
size: 'md',
|
||||
rowDraggAble:false,
|
||||
hideDragHandle:false,
|
||||
onDropRow: ()=>{},
|
||||
onDragRowStart: ()=>{},
|
||||
onBodyScroll: ()=>{},
|
||||
bodyDisplayInRow: true,
|
||||
headerDisplayInRow: true,
|
||||
showRowNum: false,
|
||||
onPaste:()=>{}
|
||||
};
|
||||
|
||||
const expandIconCellWidth = Number(43);
|
||||
|
|
@ -122,8 +117,7 @@ class Table extends Component {
|
|||
super(props);
|
||||
let expandedRowKeys = [];
|
||||
let rows = [...props.data];
|
||||
const showDragHandle = !props.hideDragHandle && props.rowDraggAble;
|
||||
this.columnManager = new ColumnManager(props.columns, props.children, props.originWidth, showDragHandle, props.showRowNum); // 加入props.showRowNum参数
|
||||
this.columnManager = new ColumnManager(props.columns, props.children, props.originWidth, props.rowDraggAble, props.showRowNum); // 加入props.showRowNum参数
|
||||
this.store = createStore({ currentHoverKey: null });
|
||||
this.firstDid = true;
|
||||
if (props.defaultExpandAllRows) {
|
||||
|
|
@ -176,7 +170,7 @@ class Table extends Component {
|
|||
this.tableUid = null;
|
||||
this.contentTable = null;
|
||||
this.leftColumnsLength //左侧固定列的长度
|
||||
this.centerColumnsLength //非固定列的长度
|
||||
this.centerColumnsLength //非固定列的长度
|
||||
this.columnsChildrenList = [];//复杂表头、所有叶子节点
|
||||
}
|
||||
componentWillMount() {
|
||||
|
|
@ -207,7 +201,7 @@ class Table extends Component {
|
|||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
let { hideDragHandle, rowDraggAble, showRowNum } = this.props;
|
||||
let { rowDraggAble, showRowNum } = this.props;
|
||||
if ('data' in nextProps) {
|
||||
this.setState({
|
||||
data: nextProps.data,
|
||||
|
|
@ -219,12 +213,12 @@ class Table extends Component {
|
|||
});
|
||||
}
|
||||
if (nextProps.columns && nextProps.columns !== this.props.columns) {
|
||||
this.columnManager.reset(nextProps.columns, null, showRowNum, !hideDragHandle && rowDraggAble); // 加入this.props.showRowNum参数
|
||||
this.columnManager.reset(nextProps.columns, null, showRowNum, rowDraggAble); // 加入this.props.showRowNum参数
|
||||
if(nextProps.columns.length !== this.props.columns.length && this.refs && this.bodyTable){
|
||||
this.scrollTop = this.bodyTable.scrollTop;
|
||||
}
|
||||
} else if (nextProps.children !== this.props.children) {
|
||||
this.columnManager.reset(null, nextProps.children, showRowNum, !hideDragHandle && rowDraggAble); // 加入this.props.showRowNum参数
|
||||
this.columnManager.reset(null, nextProps.children, showRowNum, rowDraggAble); // 加入this.props.showRowNum参数
|
||||
}
|
||||
//适配lazyload
|
||||
if(nextProps.scrollTop > -1){
|
||||
|
|
@ -254,7 +248,7 @@ class Table extends Component {
|
|||
if(this.columnManager.isAnyColumnsFixed()) {
|
||||
this.syncFixedTableRowHeight();
|
||||
}
|
||||
|
||||
|
||||
//适应模态框中表格、以及父容器宽度变化的情况
|
||||
if (typeof (this.props.scroll.x) !== 'number' && this.contentTable.getBoundingClientRect().width !== this.contentDomWidth && this.firstDid) {
|
||||
this.computeTableWidth();
|
||||
|
|
@ -266,23 +260,10 @@ class Table extends Component {
|
|||
this.bodyTable.scrollTop = this.scrollTop;
|
||||
this.scrollTop = -1;
|
||||
}
|
||||
// 当表格没有数据时,重置滚动条位置,造成grid里面的表头列无法操作
|
||||
// if (prevProps.data.length === 0 || this.props.data.length === 0 ) {
|
||||
// this.resetScrollX();
|
||||
// }
|
||||
// 当懒加载手动设置的scroll.y发生变化时,滚动条回到顶部
|
||||
const prevScrollY = prevProps.scroll.y
|
||||
const currentScrollY = this.props.scroll.y
|
||||
if (prevScrollY && currentScrollY && (prevScrollY !== currentScrollY) && this.props.lazyLoad && !this.props.ignoreScrollYChange) {
|
||||
this.bodyTable.scrollTop = 0
|
||||
} else if (this.props.ignoreScrollYChange && currentScrollY && prevScrollY && (prevScrollY !== currentScrollY)) {
|
||||
const distance = this.bodyTable.scrollTop + (currentScrollY - prevScrollY)
|
||||
if (distance < 0) {
|
||||
this.bodyTable.scrollTop = 0
|
||||
} else {
|
||||
this.bodyTable.scrollTop = distance
|
||||
}
|
||||
if (prevProps.data.length === 0 || this.props.data.length === 0 ) {
|
||||
this.resetScrollX();
|
||||
}
|
||||
|
||||
// 是否传入 scroll中的y属性,如果传入判断是否是整数,如果是则进行比较 。bodyTable 的clientHeight进行判断
|
||||
this.isShowScrollY();
|
||||
}
|
||||
|
|
@ -450,7 +431,7 @@ class Table extends Component {
|
|||
getHeader(columns, fixed, leftFixedWidth, rightFixedWidth) {
|
||||
const { lastShowIndex } = this.state;
|
||||
const { filterDelay, onFilterChange, onFilterClear, filterable, showHeader, expandIconAsCell, clsPrefix, onDragStart, onDragEnter, onDragOver, onDrop,onDragEnd, draggable,
|
||||
onMouseDown, onMouseMove, onMouseUp, dragborder, onThMouseMove, dragborderKey, minColumnWidth, headerHeight,afterDragColWidth,headerScroll ,bordered,onDropBorder,onDraggingBorder, bodyDisplayInRow, headerEventNoStop, onCopy} = this.props;
|
||||
onMouseDown, onMouseMove, onMouseUp, dragborder, onThMouseMove, dragborderKey, minColumnWidth, headerHeight,afterDragColWidth,headerScroll ,bordered,onDropBorder,onDraggingBorder} = this.props;
|
||||
this.columnsChildrenList = []; //复杂表头拖拽,重新render表头前,将其置空
|
||||
const rows = this.getHeaderRows(columns);
|
||||
if (expandIconAsCell && fixed !== 'right') {
|
||||
|
|
@ -469,7 +450,7 @@ class Table extends Component {
|
|||
const trStyle = headerHeight&&!fixed ? { height: headerHeight } : (fixed ? this.getHeaderRowStyle(columns, rows) : null);
|
||||
let drop = draggable ? { onDragStart, onDragOver, onDrop,onDragEnd, onDragEnter, draggable } : {};
|
||||
let dragBorder = dragborder ? { onMouseDown, onMouseMove, onMouseUp, dragborder, onThMouseMove, dragborderKey,onDropBorder,onDraggingBorder } : {};
|
||||
let contentWidthDiff = 0;
|
||||
let contentWidthDiff = 0;
|
||||
//非固定表格,宽度不够时自动扩充
|
||||
if (!fixed) {
|
||||
contentWidthDiff = this.state.contentWidthDiff
|
||||
|
|
@ -500,9 +481,6 @@ class Table extends Component {
|
|||
bordered = {bordered}
|
||||
leftFixedWidth = {leftFixedWidth}
|
||||
rightFixedWidth = {rightFixedWidth}
|
||||
bodyDisplayInRow = {bodyDisplayInRow}
|
||||
eventNoStop = {headerEventNoStop}
|
||||
onCopy = {onCopy}
|
||||
/>
|
||||
) : null;
|
||||
}
|
||||
|
|
@ -589,7 +567,7 @@ class Table extends Component {
|
|||
}
|
||||
|
||||
getExpandedRow(key, content, visible, className, fixed) {
|
||||
const { clsPrefix, expandIconAsCell,onPaste, getCellClassName } = this.props;
|
||||
const { clsPrefix, expandIconAsCell } = this.props;
|
||||
let colCount;
|
||||
if (fixed === 'left') {
|
||||
colCount = this.columnManager.leftLeafColumns().length;
|
||||
|
|
@ -627,7 +605,6 @@ class Table extends Component {
|
|||
}
|
||||
return (
|
||||
<TableRow
|
||||
onPaste={onPaste}
|
||||
columns={columns}
|
||||
visible={visible}
|
||||
className={className}
|
||||
|
|
@ -638,11 +615,9 @@ class Table extends Component {
|
|||
store={this.store}
|
||||
dragborderKey={this.props.dragborderKey}
|
||||
rowDraggAble={this.props.rowDraggAble}
|
||||
useDragHandle={this.props.useDragHandle}
|
||||
onDragRow={this.onDragRow}
|
||||
onDragRowStart={this.onDragRowStart}
|
||||
height={expandedRowHeight}
|
||||
getCellClassName = {getCellClassName}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
|
@ -682,18 +657,11 @@ class Table extends Component {
|
|||
targetIndex = i;
|
||||
}
|
||||
});
|
||||
if (currentIndex > -1) {
|
||||
if (this.contentTable.dragType == 'top') {
|
||||
targetIndex = targetIndex-1
|
||||
}
|
||||
data = this.swapArray(data,currentIndex,targetIndex);
|
||||
this.props.onDropRow && this.props.onDropRow(data,record,targetIndex);
|
||||
this.setState({
|
||||
data,
|
||||
});
|
||||
} else {
|
||||
this.props.onDropRow && this.props.onDropRow(data,record,targetIndex);
|
||||
}
|
||||
data = this.swapArray(data,currentIndex,targetIndex);
|
||||
this.props.onDropRow && this.props.onDropRow(data,record);
|
||||
this.setState({
|
||||
data,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 数组元素交换位置
|
||||
|
|
@ -731,7 +699,6 @@ class Table extends Component {
|
|||
const childrenColumnName = props.childrenColumnName;
|
||||
const expandedRowRender = props.expandedRowRender;
|
||||
const expandRowByClick = props.expandRowByClick;
|
||||
const onPaste = props.onPaste;
|
||||
const { fixedColumnsBodyRowsHeight } = this.state;
|
||||
let rst = [];
|
||||
let height;
|
||||
|
|
@ -746,7 +713,7 @@ class Table extends Component {
|
|||
const expandIconColumnIndex = props.expandIconColumnIndex
|
||||
if(props.lazyLoad && props.lazyLoad.preHeight && indent == 0){
|
||||
rst.push(
|
||||
<TableRow onPaste={onPaste} height={props.lazyLoad.preHeight} columns={[]} className='' key={'table_row_first'} store={this.store} visible = {true}/>
|
||||
<TableRow height={props.lazyLoad.preHeight} columns={[]} className='' key={'table_row_first'} store={this.store} visible = {true}/>
|
||||
)
|
||||
}
|
||||
const lazyCurrentIndex = props.lazyLoad && props.lazyLoad.startIndex ?props.lazyLoad.startIndex :0;
|
||||
|
|
@ -818,11 +785,10 @@ class Table extends Component {
|
|||
}
|
||||
rst.push(
|
||||
<TableRow
|
||||
onPaste={onPaste}
|
||||
indent={indent}
|
||||
indentSize={props.indentSize}
|
||||
needIndentSpaced={needIndentSpaced}
|
||||
className={`${className}`}
|
||||
className={`${className} ${this.props.rowDraggAble?' row-dragg-able ':''}`}
|
||||
record={record}
|
||||
expandIconAsCell={expandIconAsCell}
|
||||
onDestroy={this.onRowDestroy}
|
||||
|
|
@ -854,8 +820,7 @@ class Table extends Component {
|
|||
rootIndex = {rootIndex}
|
||||
syncHover = {props.syncHover}
|
||||
bodyDisplayInRow = {props.bodyDisplayInRow}
|
||||
rowDraggAble={props.rowDraggAble}
|
||||
useDragHandle={props.useDragHandle}
|
||||
rowDraggAble={this.props.rowDraggAble}
|
||||
onDragRow={this.onDragRow}
|
||||
onDragRowStart={this.onDragRowStart}
|
||||
contentTable={this.contentTable}
|
||||
|
|
@ -867,7 +832,6 @@ class Table extends Component {
|
|||
centerColumnsLength={this.centerColumnsLength}
|
||||
leftColumnsLength={this.leftColumnsLength}
|
||||
expandIconCellWidth={expandIconCellWidth}
|
||||
getCellClassName = {props.getCellClassName}
|
||||
/>
|
||||
);
|
||||
this.treeRowIndex++;
|
||||
|
|
@ -889,7 +853,7 @@ class Table extends Component {
|
|||
|
||||
if(props.lazyLoad && props.lazyLoad.sufHeight && indent == 0){
|
||||
rst.push(
|
||||
<TableRow onPaste={onPaste} height={props.lazyLoad.sufHeight} key={'table_row_end'} columns={[]} className='' store={this.store} visible = {true}/>
|
||||
<TableRow height={props.lazyLoad.sufHeight} key={'table_row_end'} columns={[]} className='' store={this.store} visible = {true}/>
|
||||
)
|
||||
}
|
||||
if (!this.isTreeType) {
|
||||
|
|
@ -1153,7 +1117,7 @@ class Table extends Component {
|
|||
}
|
||||
// const leftFixedWidth = this.columnManager.getLeftColumnsWidth(this.contentWidth);
|
||||
// const rightFixedWidth = this.columnManager.getRightColumnsWidth(this.contentWidth);
|
||||
let expandIconWidth = expandIconAsCell ? 32 : 0;
|
||||
let expandIconWidth = expandIconAsCell ? 33 : 0;
|
||||
let parStyle = {}
|
||||
if(!fixed){
|
||||
parStyle = {'marginLeft':leftFixedWidth + expandIconWidth,'marginRight':rightFixedWidth}
|
||||
|
|
@ -1215,7 +1179,7 @@ class Table extends Component {
|
|||
let tdPaddingTop = this.getStyle(td,'paddingTop'),tdPaddingBottom = this.getStyle(td,'paddingBottom'),
|
||||
tdBorderTop = this.getStyle(td,'borderTopWidth'),tdBorderBottom = this.getStyle(td,'borderBottomWidth');
|
||||
return Number(tdPaddingTop.replace('px',''))+Number(tdPaddingBottom.replace('px',''))+Number(tdBorderTop.replace('px',''))+Number(tdBorderBottom.replace('px',''))
|
||||
|
||||
|
||||
}
|
||||
|
||||
syncFixedTableRowHeight() {
|
||||
|
|
@ -1234,7 +1198,7 @@ class Table extends Component {
|
|||
if(headerHeight){
|
||||
height = (getMaxColChildrenLength(columns)+1)*headerHeight;
|
||||
}
|
||||
return headerHeight ? height : (parseInt(row.getBoundingClientRect().height) || 'auto')}
|
||||
return headerHeight ? height : (row.getBoundingClientRect().height || 'auto')}
|
||||
);
|
||||
const fixedColumnsBodyRowsHeight = [].map.call(
|
||||
bodyRows, (row,index) =>{
|
||||
|
|
@ -1246,13 +1210,13 @@ class Table extends Component {
|
|||
// 内容折行显示,并又设置了 height 的情况下,也要获取主表高度
|
||||
if(heightConsistent || (!bodyDisplayInRow && rsHeight)){
|
||||
let leftHeight,rightHeight,currentHeight,maxHeight;
|
||||
leftHeight = leftBodyRows[index]?Number(leftBodyRows[index].getBoundingClientRect().height).toFixed(2):0; // 有些浏览器中,取到的高度是小数,直接parseInt有问题,保留两位小数处理
|
||||
rightHeight = rightBodyRows[index]?Number(rightBodyRows[index].getBoundingClientRect().height).toFixed(2):0;
|
||||
currentHeight = Number(row.getBoundingClientRect().height).toFixed(2)
|
||||
leftHeight = leftBodyRows[index]?leftBodyRows[index].getBoundingClientRect().height:0;
|
||||
rightHeight = rightBodyRows[index]?rightBodyRows[index].getBoundingClientRect().height:0;
|
||||
currentHeight = row.getBoundingClientRect().height
|
||||
maxHeight = Math.max(leftHeight,rightHeight,currentHeight);
|
||||
return maxHeight || 'auto'
|
||||
}else{
|
||||
return Number((Number(row.getBoundingClientRect().height)).toFixed(2)) || 'auto';
|
||||
return row.getBoundingClientRect().height || 'auto'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1260,25 +1224,23 @@ class Table extends Component {
|
|||
const fixedColumnsExpandedRowsHeight = {};
|
||||
// expandedRows为NodeList Array.prototype.forEach ie 下报错 对象不支持 “forEach” 方法
|
||||
expandedRows.length > 0 && Array.prototype.forEach.call(expandedRows,row => {
|
||||
let parentRowKey = row && row.previousSibling && row.previousSibling.getAttribute("data-row-key");
|
||||
let exHeight = row && parseInt(row.getBoundingClientRect().height) || 'auto';
|
||||
// fix: ie 展开表格计算渲染bug
|
||||
// try {//子表数据减少时,动态计算高度
|
||||
// let td = row.querySelector('td');
|
||||
// let tdPadding = this.getTdPadding(td);
|
||||
// let trueheight = parseInt(row.querySelectorAll('.u-table')[0].getBoundingClientRect().height);
|
||||
// exHeight = trueheight+tdPadding;
|
||||
// } catch (error) {
|
||||
|
||||
// }
|
||||
fixedColumnsExpandedRowsHeight[parentRowKey] = parseInt(exHeight);
|
||||
let parentRowKey = row && row.previousSibling && row.previousSibling.getAttribute("data-row-key"),
|
||||
height = row && row.getBoundingClientRect().height || 'auto';
|
||||
try {//子表数据减少时,动态计算高度
|
||||
let td = row.querySelector('td');
|
||||
let tdPadding = this.getTdPadding(td);
|
||||
let trueheight = row.querySelectorAll('.u-table')[0].getBoundingClientRect().height;
|
||||
height = trueheight+tdPadding;
|
||||
} catch (error) {
|
||||
|
||||
}
|
||||
fixedColumnsExpandedRowsHeight[parentRowKey] = height;
|
||||
})
|
||||
if (shallowequal(this.state.fixedColumnsHeadRowsHeight, fixedColumnsHeadRowsHeight) &&
|
||||
shallowequal(this.state.fixedColumnsBodyRowsHeight, fixedColumnsBodyRowsHeight) &&
|
||||
shallowequal(this.state.fixedColumnsExpandedRowsHeight, fixedColumnsExpandedRowsHeight)) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.setState({
|
||||
fixedColumnsHeadRowsHeight,
|
||||
fixedColumnsBodyRowsHeight,
|
||||
|
|
@ -1303,24 +1265,8 @@ class Table extends Component {
|
|||
isRowExpanded(record, index) {
|
||||
return typeof this.findExpandedRow(record, index) !== 'undefined';
|
||||
}
|
||||
|
||||
clearBodyMouseLeaveTimer = () => {
|
||||
if (this.bodyMouseLeaveTimmer) {
|
||||
clearTimeout(this.bodyMouseLeaveTimmer)
|
||||
this.bodyMouseLeaveTimmer = null
|
||||
}
|
||||
}
|
||||
|
||||
onBodyMouseLeave(e){
|
||||
this.hideHoverDom(e);
|
||||
const {onBodyMouseLeave} = this.props;
|
||||
if (typeof onBodyMouseLeave === 'function') {
|
||||
this.clearBodyMouseLeaveTimer();
|
||||
//因为鼠标移动到 hoverContent 中也会触发 onBodyMouseLeave,这是错误的
|
||||
//所以讲 onBodyMouseLeave 回调的调用放入 setTimeout中,
|
||||
// 当触发 hoverContent 的 onRowHoverMouseEnter 回调时,清除此定时器
|
||||
this.bodyMouseLeaveTimmer = setTimeout(onBodyMouseLeave, 0)
|
||||
}
|
||||
}
|
||||
|
||||
detectScrollTarget(e) {
|
||||
|
|
@ -1355,7 +1301,7 @@ class Table extends Component {
|
|||
if (e.target.scrollLeft === 0) {
|
||||
position='left';
|
||||
} else if (e.target.scrollLeft + 1 >=
|
||||
e.target.querySelector('table').getBoundingClientRect().width -
|
||||
e.target.children[0].getBoundingClientRect().width -
|
||||
e.target.getBoundingClientRect().width) {
|
||||
position='right';
|
||||
} else if (this.state.scrollPosition !== 'middle') {
|
||||
|
|
@ -1391,9 +1337,6 @@ class Table extends Component {
|
|||
debounce(
|
||||
handleScrollY(this.lastScrollTop,this.treeType,onBodyScroll),
|
||||
300)
|
||||
}else{
|
||||
//滚动回调
|
||||
onBodyScroll(this.lastScrollTop)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1430,11 +1373,8 @@ class Table extends Component {
|
|||
this.hoverDom.style.lineHeight = td.offsetHeight + 'px';
|
||||
this.hoverDom.style.display = 'block';
|
||||
}
|
||||
this.setState({
|
||||
currentHoverIndex: currentIndex,
|
||||
currentHoverRecord: record
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
onRowHover && onRowHover(currentIndex,record);
|
||||
|
|
@ -1447,7 +1387,6 @@ class Table extends Component {
|
|||
currentHoverKey: this.currentHoverKey,
|
||||
});
|
||||
this.hoverDom.style.display = 'block';
|
||||
this.clearBodyMouseLeaveTimer();
|
||||
|
||||
}
|
||||
onRowHoverMouseLeave = () =>{
|
||||
|
|
@ -1471,7 +1410,6 @@ class Table extends Component {
|
|||
}
|
||||
|
||||
render() {
|
||||
const { currentHoverRecord, currentHoverIndex } = this.state;
|
||||
const props = this.props;
|
||||
const clsPrefix = props.clsPrefix;
|
||||
const hasFixedLeft = this.columnManager.isAnyColumnsLeftFixed();
|
||||
|
|
@ -1488,9 +1426,6 @@ class Table extends Component {
|
|||
if (props.bordered) {
|
||||
className += ` ${clsPrefix}-bordered`;
|
||||
}
|
||||
if (props.onCopy) {
|
||||
className += ` copy`;
|
||||
}
|
||||
className += ` ${clsPrefix}-scroll-position-${this.state.scrollPosition}`;
|
||||
//如果传入height说明是固定高度
|
||||
//内容过多折行显示时,height 属性会失效,为了避免产生错行
|
||||
|
|
@ -1544,7 +1479,7 @@ class Table extends Component {
|
|||
container={this}
|
||||
{...loading} />
|
||||
{ props.hoverContent && <div className="u-row-hover"
|
||||
onMouseEnter={this.onRowHoverMouseEnter} onMouseLeave={this.onRowHoverMouseLeave} ref={el=> this.hoverDom = el }>{props.hoverContent(currentHoverRecord, currentHoverIndex)}</div>}
|
||||
onMouseEnter={this.onRowHoverMouseEnter} onMouseLeave={this.onRowHoverMouseLeave} ref={el=> this.hoverDom = el }>{props.hoverContent()}</div>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,9 +29,6 @@ $icon-color:#505F79;
|
|||
position: relative;
|
||||
line-height: $line-height;
|
||||
overflow: hidden;
|
||||
&.copy .u-table-thead th {
|
||||
user-select: unset
|
||||
}
|
||||
&-body{
|
||||
// overflow: hidden!important;
|
||||
position: relative;
|
||||
|
|
@ -746,7 +743,7 @@ $icon-color:#505F79;
|
|||
display: none;
|
||||
}
|
||||
|
||||
.drag-handle-column, .row-dragg-able{
|
||||
.row-dragg-able{
|
||||
cursor:move;
|
||||
}
|
||||
.u-table-drag-hidden-cont{
|
||||
|
|
|
|||
142
src/TableCell.js
142
src/TableCell.js
|
|
@ -14,8 +14,7 @@ const propTypes = {
|
|||
indent: PropTypes.number,
|
||||
indentSize: PropTypes.number,
|
||||
column: PropTypes.object,
|
||||
expandIcon: PropTypes.node,
|
||||
onPaste:PropTypes.func
|
||||
expandIcon: PropTypes.node
|
||||
};
|
||||
|
||||
class TableCell extends Component{
|
||||
|
|
@ -174,24 +173,10 @@ class TableCell extends Component{
|
|||
showDropdowm: false,
|
||||
})
|
||||
}
|
||||
onPaste=(e)=>{
|
||||
let { index:row,onPaste,fixed,col } = this.props
|
||||
let position = {
|
||||
row,
|
||||
col,
|
||||
fixed:!!fixed
|
||||
}
|
||||
onPaste(e,position)
|
||||
}
|
||||
|
||||
onCellMouseOver = (e)=> {
|
||||
const {column} = this.props
|
||||
this.props.stopRowDrag(column.notRowDrag)
|
||||
}
|
||||
|
||||
render() {
|
||||
const { record, indentSize, clsPrefix, indent,
|
||||
index, expandIcon, column ,fixed,showSum, bodyDisplayInRow,lazyStartIndex,lazyEndIndex, getCellClassName} = this.props;
|
||||
index, expandIcon, column ,fixed,showSum, bodyDisplayInRow,lazyStartIndex,lazyEndIndex} = this.props;
|
||||
const { dataIndex, render, fieldType, linkConfig, fontColor, bgColor,...other } = column;
|
||||
let {className = ''} = column;
|
||||
|
||||
|
|
@ -199,72 +184,66 @@ class TableCell extends Component{
|
|||
let tdProps;
|
||||
let colSpan;
|
||||
let rowSpan,title;
|
||||
let colMenu = this.renderColumnMenu(column.cellMenu, text, record, index);
|
||||
// 如果是固定列在主表格上就渲染null
|
||||
if(column.fixed && !fixed){
|
||||
text = null
|
||||
}else {
|
||||
if (render && !showSum) {
|
||||
text = render(text, record, index,{
|
||||
dataIndex, render, fieldType, linkConfig, fontColor, bgColor,...other
|
||||
});
|
||||
if (this.isInvalidRenderCellText(text)) {
|
||||
tdProps = text.props || {};
|
||||
rowSpan = (tdProps.rowSpan>lazyEndIndex && lazyEndIndex>5)?lazyEndIndex-index:tdProps.rowSpan;
|
||||
colSpan = tdProps.colSpan;
|
||||
text = text.children;
|
||||
}
|
||||
|
||||
if (render && !showSum) {
|
||||
text = render(text, record, index,{
|
||||
dataIndex, render, fieldType, linkConfig, fontColor, bgColor,...other
|
||||
});
|
||||
if (this.isInvalidRenderCellText(text)) {
|
||||
tdProps = text.props || {};
|
||||
rowSpan = (tdProps.rowSpan>lazyEndIndex && lazyEndIndex>5)?lazyEndIndex-index:tdProps.rowSpan;
|
||||
colSpan = tdProps.colSpan;
|
||||
text = text.children;
|
||||
}
|
||||
|
||||
|
||||
// 根据 fieldType 来渲染数据
|
||||
if(!render){
|
||||
switch(column.fieldType){
|
||||
case 'link':{
|
||||
text = this.renderLinkType(text, record, index, column.linkConfig);
|
||||
break;
|
||||
}
|
||||
|
||||
let colMenu = this.renderColumnMenu(column.cellMenu, text, record, index);
|
||||
// 根据 fieldType 来渲染数据
|
||||
if(!render){
|
||||
switch(column.fieldType){
|
||||
case 'link':{
|
||||
text = this.renderLinkType(text, record, index, column.linkConfig);
|
||||
break;
|
||||
}
|
||||
case 'bool':{
|
||||
text = this.renderBoolType(text, column.boolConfig);
|
||||
break;
|
||||
}
|
||||
case 'currency':{
|
||||
let config = {
|
||||
precision: 2, // 精度值,需要大于0
|
||||
thousand: true, // 是否显示千分符号
|
||||
makeUp: true, // 末位是否补零
|
||||
preSymbol: '', // 前置符号
|
||||
nextSymbol: '', // 后置符号
|
||||
}
|
||||
case 'bool':{
|
||||
text = this.renderBoolType(text, column.boolConfig);
|
||||
break;
|
||||
}
|
||||
case 'currency':{
|
||||
let config = {
|
||||
precision: 2, // 精度值,需要大于0
|
||||
thousand: true, // 是否显示千分符号
|
||||
makeUp: true, // 末位是否补零
|
||||
preSymbol: '', // 前置符号
|
||||
nextSymbol: '', // 后置符号
|
||||
}
|
||||
text = this.renderNumber(text, {...config,...column.currencyConfig}, column.width);
|
||||
break;
|
||||
}
|
||||
case 'number':{
|
||||
let config = {
|
||||
precision: 0, // 精度值,需要大于0
|
||||
thousand: true, // 是否显示千分符号
|
||||
makeUp: false, // 末位是否补零
|
||||
preSymbol: '', // 前置符号
|
||||
nextSymbol: '', // 后置符号
|
||||
}
|
||||
text = this.renderNumber(text, {...config,...column.numberConfig}, column.width);
|
||||
break;
|
||||
}
|
||||
case 'date':{
|
||||
text = this.renderDate(text, column.dateConfig);
|
||||
break;
|
||||
}
|
||||
case 'select':{
|
||||
text = this.renderSelect(text, column.selectConfig);
|
||||
break;
|
||||
}
|
||||
default : {
|
||||
break;
|
||||
text = this.renderNumber(text, {...config,...column.currencyConfig}, column.width);
|
||||
break;
|
||||
}
|
||||
case 'number':{
|
||||
let config = {
|
||||
precision: 0, // 精度值,需要大于0
|
||||
thousand: true, // 是否显示千分符号
|
||||
makeUp: false, // 末位是否补零
|
||||
preSymbol: '', // 前置符号
|
||||
nextSymbol: '', // 后置符号
|
||||
}
|
||||
text = this.renderNumber(text, {...config,...column.numberConfig}, column.width);
|
||||
break;
|
||||
}
|
||||
case 'date':{
|
||||
text = this.renderDate(text, column.dateConfig);
|
||||
break;
|
||||
}
|
||||
case 'select':{
|
||||
text = this.renderSelect(text, column.selectConfig);
|
||||
break;
|
||||
}
|
||||
default : {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (this.isInvalidRenderCellText(text)) {
|
||||
text = null;
|
||||
|
|
@ -303,22 +282,13 @@ class TableCell extends Component{
|
|||
if(colMenu){
|
||||
className += ' u-table-inline-icon'
|
||||
}
|
||||
|
||||
if(typeof getCellClassName == 'function') {
|
||||
const selfClassName = getCellClassName(record, index, column) || ''
|
||||
className += ` ${selfClassName}`
|
||||
}
|
||||
|
||||
if(colSpan==0)return null;
|
||||
return <td
|
||||
draggable={column.draggable}
|
||||
colSpan={colSpan}
|
||||
rowSpan={rowSpan}
|
||||
className={className}
|
||||
onClick={this.handleClick}
|
||||
title={title}
|
||||
onPaste={this.onPaste}
|
||||
onMouseOver={this.onCellMouseOver}
|
||||
style={{maxWidth:column.width, color:fontColor, backgroundColor:bgColor, ...column.style}}>
|
||||
{indentText}
|
||||
{expandIcon}
|
||||
|
|
|
|||
|
|
@ -100,32 +100,17 @@ class TableHeader extends Component {
|
|||
table.cols = tableDome.getElementsByTagName("col");
|
||||
table.ths = tableDome.getElementsByTagName("th");
|
||||
table.tr = tableDome.getElementsByTagName("tr");
|
||||
table.tableHeaderCols = contentTable.querySelector('.u-table-scroll .u-table-header') && contentTable.querySelector('.u-table-scroll .u-table-header').getElementsByTagName("col");
|
||||
table.tableBody = contentTable.querySelector('.u-table-scroll .u-table-body') && contentTable.querySelector('.u-table-scroll .u-table-body');
|
||||
table.tableBodyCols = contentTable.querySelector('.u-table-scroll .u-table-body') && contentTable.querySelector('.u-table-scroll .u-table-body').getElementsByTagName("col");
|
||||
table.bodyRows = table.tableBody && table.tableBody.querySelectorAll('tr') || [];
|
||||
|
||||
table.fixedLeftHeaderTable = contentTable.querySelector('.u-table-fixed-left .u-table-header') ;
|
||||
table.fixedRighHeadertTable = contentTable.querySelector('.u-table-fixed-right .u-table-header');
|
||||
table.contentTableHeader = contentTable.querySelector('.u-table-scroll .u-table-header');
|
||||
table.fixedLeftBodyTable = contentTable.querySelectorAll('.u-table-fixed-left .u-table-body-outer') ;
|
||||
if (table.fixedLeftBodyTable) {
|
||||
const leftBodyTableIndex = table.fixedLeftBodyTable.length-1 < 0 ? 0 : table.fixedLeftBodyTable.length-1
|
||||
table.fixedLeftBodyTable = table.fixedLeftBodyTable[leftBodyTableIndex]
|
||||
}
|
||||
|
||||
table.fixedRightBodyTable = contentTable.querySelectorAll('.u-table-fixed-right .u-table-body-outer') ;
|
||||
if (table.fixedRightBodyTable) {
|
||||
const rightBodyTableIndex = table.fixedRightBodyTable.length-1 < 0 ? 0 : table.fixedRightBodyTable.length-1
|
||||
table.fixedRightBodyTable = table.fixedRightBodyTable[rightBodyTableIndex]
|
||||
}
|
||||
|
||||
table.innerTableBody= contentTable.querySelector('.u-table-scroll .u-table-body table');
|
||||
table.fixedLeftBodyRows = table.fixedLeftBodyTable && table.fixedLeftBodyTable.querySelectorAll('tr') || [];
|
||||
table.fixedRightBodyRows = table.fixedRightBodyTable && table.fixedRightBodyTable.querySelectorAll('tr') || [];
|
||||
}
|
||||
|
||||
|
||||
table.fixedLeftHeaderTable = contentTable.querySelector('.u-table-fixed-left .u-table-header') ;
|
||||
table.fixedRighHeadertTable = contentTable.querySelector('.u-table-fixed-right .u-table-header');
|
||||
table.contentTableHeader = contentTable.querySelector('.u-table-scroll .u-table-header');
|
||||
table.fixedLeftBodyTable = contentTable.querySelector('.u-table-fixed-left .u-table-body-outer') ;
|
||||
table.fixedRightBodyTable = contentTable.querySelector('.u-table-fixed-right .u-table-body-outer') ;
|
||||
table.innerTableBody= contentTable.querySelector('.u-table-scroll .u-table-body table');
|
||||
|
||||
this.table = table;
|
||||
|
||||
if(!this.props.dragborder)return;
|
||||
|
|
@ -181,17 +166,14 @@ class TableHeader extends Component {
|
|||
*/
|
||||
dragBorderEventInit (){
|
||||
if(!this.props.dragborder )return;
|
||||
this.eventListen([{key:'mouseup', fun:this.onTrMouseUp}],'',document.body);
|
||||
this.eventListen([{key:'mousemove', fun:this.onTrMouseMove}],'',document.body);
|
||||
|
||||
// let events = [
|
||||
// {key:'mouseup', fun:this.onTrMouseUp},
|
||||
// {key:'mousemove', fun:this.onTrMouseMove},
|
||||
// // {key:'mousemove', fun:debounce(50,this.onTrMouseMove)},//函数节流后体验很差
|
||||
// ];
|
||||
// this.doEventList(this.table.tr,(tr)=>{
|
||||
// this.eventListen(events,'',tr);//表示把事件添加到th元素上
|
||||
// })
|
||||
let events = [
|
||||
{key:'mouseup', fun:this.onTrMouseUp},
|
||||
{key:'mousemove', fun:this.onTrMouseMove},
|
||||
// {key:'mousemove', fun:debounce(50,this.onTrMouseMove)},//函数节流后体验很差
|
||||
];
|
||||
this.doEventList(this.table.tr,(tr)=>{
|
||||
this.eventListen(events,'',tr);//表示把事件添加到th元素上
|
||||
})
|
||||
// this.eventListen(events,'',this.table.tr[0]);//表示把事件添加到th元素上
|
||||
}
|
||||
|
||||
|
|
@ -249,8 +231,7 @@ class TableHeader extends Component {
|
|||
* @memberof TableHeader
|
||||
*/
|
||||
onTrMouseDown = (e) => {
|
||||
const { eventNoStop } = this.props;
|
||||
!eventNoStop && Event.stopPropagation(e);
|
||||
Event.stopPropagation(e);
|
||||
let event = Event.getEvent(e) ,
|
||||
targetEvent = Event.getTarget(event);
|
||||
const { clsPrefix, contentTable,lastShowIndex,columnsChildrenList } = this.props;
|
||||
|
|
@ -258,7 +239,6 @@ class TableHeader extends Component {
|
|||
let currentElement = this.getTargetToType(targetEvent);
|
||||
if(!currentElement)return;
|
||||
let type = currentElement.getAttribute('data-type');
|
||||
const fixedType = currentElement.getAttribute('data-th-fixed');
|
||||
if(!this.props.dragborder && !this.props.draggable)return;
|
||||
if(type == 'online' && this.props.dragborder){
|
||||
// if(!this.props.dragborder)return;
|
||||
|
|
@ -278,33 +258,16 @@ class TableHeader extends Component {
|
|||
}
|
||||
let currentObj = this.table.cols[currentIndex];
|
||||
this.drag.currIndex = currentIndex;
|
||||
this.drag.oldLeft = event.clientX;
|
||||
this.drag.oldLeft = event.x;
|
||||
this.drag.oldWidth = parseInt((currentObj).style.width);
|
||||
this.drag.minWidth = currentObj.style.minWidth != ""?parseInt(currentObj.style.minWidth):defaultWidth;
|
||||
this.drag.tableWidth = parseInt(this.table.table.style.width ?this.table.table.style.width:this.table.table.scrollWidth);
|
||||
if(!this.tableOldWidth){
|
||||
this.tableOldWidth = this.drag.tableWidth;//this.getTableWidth();
|
||||
}
|
||||
|
||||
// if(!this.lastColumWidth){
|
||||
const contentT = this.table.tableHeaderCols || this.table.cols ;
|
||||
this.lastColumWidth = parseInt(contentT[lastShowIndex].style.width);
|
||||
// console.log('begin--lastColumnWidth',this.lastColumWidth);
|
||||
// }
|
||||
this.drag.contentTableCWidth = this.table.contentTableHeader.clientWidth;
|
||||
this.drag.contentTableSWidth = this.table.contentTableHeader.scrollWidth;
|
||||
if(fixedType) {
|
||||
const contentTablePar = this.table.contentTableHeader.parentNode;
|
||||
|
||||
if(contentTablePar) {
|
||||
const originL = parseInt(contentTablePar.style.marginLeft);
|
||||
const originR = parseInt(contentTablePar.style.marginRight);
|
||||
// 内容区表格marginLef
|
||||
this.drag.contentTableML = originL;
|
||||
this.drag.contentTableMR = originR;
|
||||
}
|
||||
if(!this.lastColumWidth){
|
||||
this.lastColumWidth = parseInt(this.table.cols[lastShowIndex].style.width);
|
||||
}
|
||||
this.drag.fixedType = fixedType;
|
||||
}else if(type != 'online' && this.props.draggable){
|
||||
// if (!this.props.draggable || targetEvent.nodeName.toUpperCase() != "TH") return;
|
||||
if (!this.props.draggable) return;
|
||||
|
|
@ -360,60 +323,31 @@ class TableHeader extends Component {
|
|||
*/
|
||||
onTrMouseMove = (e) => {
|
||||
if(!this.props.dragborder && !this.props.draggable)return;
|
||||
const { clsPrefix ,dragborder,contentDomWidth,scrollbarWidth,contentTable,headerScroll,lastShowIndex,onDraggingBorder, leftFixedWidth, rightFixedWidth, bodyDisplayInRow, eventNoStop} = this.props;
|
||||
!eventNoStop && Event.stopPropagation(e);
|
||||
const { clsPrefix ,dragborder,contentDomWidth,scrollbarWidth,contentTable,headerScroll,lastShowIndex,onDraggingBorder, leftFixedWidth, rightFixedWidth} = this.props;
|
||||
Event.stopPropagation(e);
|
||||
let event = Event.getEvent(e);
|
||||
if(this.props.dragborder && this.drag.option == "border"){
|
||||
//移动改变宽度
|
||||
let currentCols = this.table.cols[this.drag.currIndex];
|
||||
let diff = (event.clientX - this.drag.oldLeft);
|
||||
let diff = (event.x - this.drag.oldLeft);
|
||||
let newWidth = this.drag.oldWidth + diff;
|
||||
this.drag.newWidth = newWidth > 0 ? newWidth : this.minWidth;
|
||||
if(newWidth > this.minWidth){
|
||||
currentCols.style.width = newWidth +'px';
|
||||
|
||||
// displayinrow 判断、 固定行高判断
|
||||
if(!bodyDisplayInRow) {
|
||||
this.table.bodyRows.forEach((row,index)=>{
|
||||
const leftRow = this.table.fixedLeftBodyRows[index];
|
||||
const rightRow = this.table.fixedRightBodyRows[index];
|
||||
if(leftRow || rightRow) {
|
||||
const height = row.getBoundingClientRect().height;
|
||||
leftRow && (leftRow.style.height = height + "px")
|
||||
rightRow && (rightRow.style.height = height + "px")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
//hao 支持固定表头拖拽 修改表体的width
|
||||
if(this.fixedTable.cols){
|
||||
this.fixedTable.cols[this.drag.currIndex].style.width = newWidth + "px";
|
||||
}
|
||||
|
||||
const contentTableSWidth = this.drag.contentTableSWidth - this.drag.contentTableCWidth;
|
||||
// console.log('contentTableSWidth+diff',contentTableSWidth+diff,'diff',diff);
|
||||
if(diff<0 && contentTableSWidth+diff < 0) {
|
||||
const headerCols = this.table.tableHeaderCols || this.table.cols;
|
||||
const lastWidth =this.lastColumWidth - (contentTableSWidth+diff);
|
||||
// console.log('lastWidth',lastWidth,'lastShowIndex',lastShowIndex);
|
||||
headerCols[lastShowIndex].style.width = lastWidth +"px";//同步表头
|
||||
this.table.tableBodyCols[lastShowIndex].style.width = lastWidth + "px";//同步表体
|
||||
}
|
||||
// 内容区非固定列场景拖拽
|
||||
if(!this.drag.fixedType) {
|
||||
|
||||
// let newDiff = (parseInt(currentCols.style.minWidth) - parseInt(currentCols.style.width));
|
||||
// if(newDiff > 0){//缩小
|
||||
// let lastWidth = this.lastColumWidth + newDiff;
|
||||
// this.table.cols[lastShowIndex].style.width = lastWidth +"px";//同步表头
|
||||
// this.table.tableBodyCols[lastShowIndex].style.width = lastWidth + "px";//同步表体
|
||||
|
||||
// }
|
||||
|
||||
let showScroll = contentDomWidth - (leftFixedWidth + rightFixedWidth) - (this.drag.tableWidth + diff) - scrollbarWidth ;
|
||||
|
||||
//表头滚动条处理
|
||||
if(headerScroll){
|
||||
let newDiff = (parseInt(currentCols.style.minWidth) - parseInt(currentCols.style.width));
|
||||
if(newDiff > 0){//缩小
|
||||
let lastWidth = this.lastColumWidth + newDiff;
|
||||
this.table.cols[lastShowIndex].style.width = lastWidth +"px";//同步表头
|
||||
this.table.tableBodyCols[lastShowIndex].style.width = lastWidth + "px";//同步表体
|
||||
}
|
||||
let showScroll = contentDomWidth - (leftFixedWidth + rightFixedWidth) - (this.drag.tableWidth + diff) - scrollbarWidth ;
|
||||
//表头滚动条处理
|
||||
if(headerScroll){
|
||||
if(showScroll < 0){ //小于 0 出现滚动条
|
||||
//找到固定列表格,设置表头的marginBottom值为scrollbarWidth;
|
||||
this.table.contentTableHeader.style.overflowX = 'scroll';
|
||||
|
|
@ -424,7 +358,7 @@ class TableHeader extends Component {
|
|||
this.optTableMargin( this.table.fixedLeftHeaderTable,0);
|
||||
this.optTableMargin( this.table.fixedRighHeadertTable,0);
|
||||
}
|
||||
}else{
|
||||
}else{
|
||||
if(showScroll < 0){
|
||||
this.table.tableBody.style.overflowX = 'auto';
|
||||
this.optTableMargin( this.table.fixedLeftBodyTable,'-'+scrollbarWidth);
|
||||
|
|
@ -438,36 +372,7 @@ class TableHeader extends Component {
|
|||
this.optTableScroll( this.table.fixedLeftBodyTable,{x:'auto'});
|
||||
this.optTableScroll( this.table.fixedRightBodyTable,{x:'auto'});
|
||||
}
|
||||
}
|
||||
}else if(this.drag.fixedType) {
|
||||
if(this.table.ths[this.drag.currIndex]) {
|
||||
this.table.ths[this.drag.currIndex].width = newWidth
|
||||
}
|
||||
// console.log('this.drag.contentTableML',this.drag.contentTableML,'diff',diff);
|
||||
// debugger
|
||||
|
||||
const contentTablePar = this.table.contentTableHeader.parentNode;
|
||||
// left、right缩小的内容,在没有滚动条时,需要将宽度同步到到最后一列
|
||||
// diff<0 往里拖,
|
||||
// const contentTableSWidth = this.drag.contentTableSWidth - this.drag.contentTableCWidth;
|
||||
// console.log('contentTableSWidth+diff',contentTableSWidth+diff,'diff',diff);
|
||||
// if(diff<0 && contentTableSWidth+diff < 0) {
|
||||
// const headerCols = this.table.tableHeaderCols || this.table.cols;
|
||||
// const lastWidth =this.lastColumWidth - (contentTableSWidth+diff);
|
||||
// console.log('lastWidth',lastWidth,'lastShowIndex',lastShowIndex);
|
||||
// headerCols[lastShowIndex].style.width = lastWidth +"px";//同步表头
|
||||
// this.table.tableBodyCols[lastShowIndex].style.width = lastWidth + "px";//同步表体
|
||||
// }
|
||||
if(this.drag.fixedType == 'left') {
|
||||
contentTablePar.style.marginLeft = this.drag.contentTableML + diff + 'px'
|
||||
|
||||
}else {
|
||||
contentTablePar.style.marginRight = this.drag.contentTableMR + diff + 'px'
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}else {
|
||||
this.drag.newWidth = this.minWidth;
|
||||
}
|
||||
|
|
@ -623,8 +528,6 @@ class TableHeader extends Component {
|
|||
}
|
||||
let event = Event.getEvent(e) ,
|
||||
target = Event.getTarget(event);
|
||||
event.preventDefault()
|
||||
event.stopPropagation();
|
||||
this.currentDome.setAttribute('draggable',false);//添加交换列效果
|
||||
// let data = this.getCurrentEventData(this._dragCurrent);
|
||||
// if(!data){
|
||||
|
|
@ -654,8 +557,6 @@ class TableHeader extends Component {
|
|||
let event = Event.getEvent(e) ,
|
||||
target = Event.getTarget(event);
|
||||
this._dragCurrent.setAttribute("style","");
|
||||
event.preventDefault()
|
||||
event.stopPropagation();
|
||||
// this._dragCurrent.style = "";
|
||||
document.getElementById(this._table_none_cont_id).innerHTML = "";
|
||||
|
||||
|
|
@ -756,7 +657,7 @@ class TableHeader extends Component {
|
|||
clsPrefix={clsPrefix}//css前缀
|
||||
className={`${clsPrefix} filter-text`}
|
||||
dataIndex={dataIndex}//字段
|
||||
onFilterChange={debounce(filterDelay || 300, this.handlerFilterChange)}//输入框回调
|
||||
onFilterChange={this.handlerFilterChange}//输入框回调
|
||||
onFilterClear={this.handlerFilterClear}//清除回调
|
||||
filterDropdown={rows[1][index]["filterdropdown"]}//是否显示下拉条件
|
||||
filterDropdownType={rows[1][index]["filterdropdowntype"]}//下拉的条件类型为string,number
|
||||
|
|
@ -906,12 +807,6 @@ class TableHeader extends Component {
|
|||
}
|
||||
};
|
||||
|
||||
onCopy = (data,index, event) => {
|
||||
if(this.props.onCopy) {
|
||||
this.props.onCopy(Object.assign(data,{col: index}),event)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
render() {
|
||||
const { clsPrefix, rowStyle,draggable,
|
||||
|
|
@ -979,13 +874,13 @@ class TableHeader extends Component {
|
|||
thClassName += ` ${fixedStyle}`;
|
||||
if(!da.fixed ){
|
||||
return (<th {...da} {...keyTemp} className={thClassName} data-th-fixed={da.fixed} data-line-key={da.key}
|
||||
data-line-index={columIndex} data-th-width={da.width} data-type="draggable" onCopy={(event) => {this.onCopy(da,columIndex,event)}}>
|
||||
data-line-index={columIndex} data-th-width={da.width} data-type="draggable">
|
||||
{da.children}
|
||||
{
|
||||
// && columIndex != _rowLeng
|
||||
dragborder && lastObj && da.key != lastObj.key ? <div ref={el => (this.gap = el)} data-line-key={da.key}
|
||||
data-line-index={columIndex} data-th-width={da.width}
|
||||
data-type="online" data-th-fixed={da.fixed} className = {`${clsPrefix}-thead-th-drag-gap`}>
|
||||
data-type="online" className = {`${clsPrefix}-thead-th-drag-gap`}>
|
||||
<div className='online' /></div>:""
|
||||
}
|
||||
</th>)
|
||||
|
|
@ -995,16 +890,7 @@ class TableHeader extends Component {
|
|||
className:`${thClassName} ${fixedStyle}`,
|
||||
};
|
||||
da.onClick ?thDefaultObj.onClick = (e)=>{da.onClick(da, e)}:"";
|
||||
return (<th {...thDefaultObj} {...keyTemp} data-th-fixed={da.fixed} style={{maxWidth: da.width}} onCopy={this.onCopy}>
|
||||
{da.children}
|
||||
{
|
||||
// && columIndex != _rowLeng
|
||||
dragborder ? <div ref={el => (this.gap = el)} data-line-key={da.key}
|
||||
data-line-index={columIndex} data-th-width={da.width}
|
||||
data-type="online" data-th-fixed={da.fixed} className = {`${clsPrefix}-thead-th-drag-gap`}>
|
||||
<div className='online' /></div>:""
|
||||
}
|
||||
</th>)
|
||||
return (<th {...thDefaultObj} {...keyTemp} data-th-fixed={da.fixed} style={{maxWidth: da.width}}/>)
|
||||
}
|
||||
})}
|
||||
</tr>
|
||||
|
|
|
|||
|
|
@ -33,7 +33,6 @@ const propTypes = {
|
|||
rowDraggAble: PropTypes.bool,
|
||||
onDragRow: PropTypes.func,
|
||||
onDragRowStart: PropTypes.func,
|
||||
syncRowHeight:PropTypes.bool
|
||||
};
|
||||
|
||||
const defaultProps = {
|
||||
|
|
@ -47,7 +46,6 @@ const defaultProps = {
|
|||
setRowParentIndex:()=>{},
|
||||
rowDraggAble:false,
|
||||
// onDragRow:()=>{}
|
||||
syncRowHeight:false
|
||||
};
|
||||
|
||||
class TableRow extends Component{
|
||||
|
|
@ -140,20 +138,20 @@ class TableRow extends Component{
|
|||
*/
|
||||
onDragStart = (e) => {
|
||||
let {onDragRowStart} = this.props;
|
||||
if (!this.props.rowDraggAble || this.notRowDrag) return;
|
||||
if (!this.props.rowDraggAble) return;
|
||||
let event = Event.getEvent(e) ,
|
||||
target = Event.getTarget(event);
|
||||
if (target.tagName === 'TD') {
|
||||
target = target.parentNode;
|
||||
}
|
||||
this.currentIndex = target.getAttribute("data-row-key");
|
||||
this.currentIndex = target.getAttribute("data-row-key");
|
||||
this._dragCurrent = target;
|
||||
|
||||
// 拖拽其实index
|
||||
this.props.contentTable.startI = target.getAttribute("data-row-index");
|
||||
this._dragCurrent = target;
|
||||
event.dataTransfer.effectAllowed = "move";
|
||||
event.dataTransfer.setData("Text", this.currentIndex);
|
||||
onDragRowStart && onDragRowStart(this.currentIndex);
|
||||
//TODO 自定义图像后续需要增加。
|
||||
// let crt = this.synchronizeTableTrShadow();
|
||||
// document.getElementById(this.props.tableUid).appendChild(crt);
|
||||
// event.dataTransfer.setDragImage(crt, 0, 0);
|
||||
event.dataTransfer.effectAllowed = "move";
|
||||
event.dataTransfer.setData("Text", this.currentIndex);
|
||||
|
||||
onDragRowStart && onDragRowStart(this.currentIndex);
|
||||
}
|
||||
|
||||
onDragOver = (e) => {
|
||||
|
|
@ -166,12 +164,11 @@ class TableRow extends Component{
|
|||
* @memberof TableHeader
|
||||
*/
|
||||
onDrop = (e) => {
|
||||
let {onDragRow, contentTable} = this.props;
|
||||
let {rowDraggAble,onDragRow} = this.props;
|
||||
let event = Event.getEvent(e) ,
|
||||
_target = Event.getTarget(event),
|
||||
target = _target.parentNode;
|
||||
event.preventDefault()
|
||||
event.stopPropagation();
|
||||
|
||||
let currentKey = event.dataTransfer.getData("text");
|
||||
let targetKey = target.getAttribute("data-row-key");
|
||||
|
||||
|
|
@ -179,6 +176,8 @@ class TableRow extends Component{
|
|||
if(target.nodeName.toUpperCase() === "TR"){
|
||||
this.synchronizeTableTr(currentKey,null);
|
||||
this.synchronizeTableTr(targetKey,null);
|
||||
// target.setAttribute("style","");
|
||||
// this.synchronizeTrStyle(this.currentIndex,false);
|
||||
}
|
||||
onDragRow && onDragRow(currentKey,targetKey);
|
||||
};
|
||||
|
|
@ -317,27 +316,22 @@ class TableRow extends Component{
|
|||
currentObj = element;
|
||||
}
|
||||
}
|
||||
if(type == 'down'){
|
||||
currentObj && currentObj.setAttribute("style","border-bottom:2px solid #02B1FD");
|
||||
}else if(type){
|
||||
currentObj && currentObj.setAttribute("style","border-top:2px solid #02B1FD");
|
||||
if(type){
|
||||
currentObj && currentObj.setAttribute("style","border-bottom:2px dashed rgb(30, 136, 229)");
|
||||
}else{
|
||||
currentObj && currentObj.setAttribute("style","");
|
||||
}
|
||||
}
|
||||
|
||||
onDragEnter = (e) => {
|
||||
const {contentTable} = this.props;
|
||||
let event = Event.getEvent(e) ,
|
||||
_target = Event.getTarget(event),target = _target.parentNode;
|
||||
let currentIndex = target.getAttribute("data-row-key");
|
||||
let dragEnterIndex = target.getAttribute("data-row-index");
|
||||
if(!currentIndex || currentIndex === this.currentIndex)return;
|
||||
const dragType = parseInt(dragEnterIndex) > parseInt(contentTable.startI) ? 'down' : 'top'
|
||||
|
||||
contentTable.dragType = dragType;
|
||||
if(target.nodeName.toUpperCase() === "TR"){
|
||||
this.synchronizeTableTr(currentIndex,dragType);
|
||||
this.synchronizeTableTr(currentIndex,true);
|
||||
// target.setAttribute("style","border-bottom:2px dashed rgba(5,0,0,0.25)");
|
||||
// // target.style.backgroundColor = 'rgb(235, 236, 240)';
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -352,19 +346,17 @@ class TableRow extends Component{
|
|||
}
|
||||
|
||||
componentDidUpdate(prevProps) {
|
||||
const { rowDraggAble,syncRowHeight } = this.props;
|
||||
const { rowDraggAble } = this.props;
|
||||
if(!this.event){
|
||||
this.event = true;
|
||||
if(rowDraggAble){
|
||||
this.initEvent();
|
||||
}
|
||||
}
|
||||
|
||||
if(this.props.treeType){
|
||||
this.setRowParentIndex();
|
||||
}
|
||||
// if(syncRowHeight){
|
||||
// this.setRowHeight()
|
||||
// }
|
||||
this.setRowHeight()
|
||||
}
|
||||
|
||||
|
|
@ -442,16 +434,6 @@ class TableRow extends Component{
|
|||
onHover(false, hoverKey,e,fixedIndex,record);
|
||||
}
|
||||
|
||||
stopRowDrag = (isStop) => {
|
||||
const {rowDraggAble} = this.props;
|
||||
const {notRowDrag} = this.state;
|
||||
if(rowDraggAble && isStop!== notRowDrag) {
|
||||
this.setState({
|
||||
notRowDrag: isStop
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
set =(fn)=> {
|
||||
this.clear();
|
||||
this._timeout = window.setTimeout(fn, 300);
|
||||
|
|
@ -469,12 +451,11 @@ class TableRow extends Component{
|
|||
|
||||
render() {
|
||||
const {
|
||||
clsPrefix, columns, record, height, visible, index,onPaste,
|
||||
expandIconColumnIndex, expandIconAsCell, expanded, useDragHandle,rowDraggAble,
|
||||
clsPrefix, columns, record, height, visible, index,
|
||||
expandIconColumnIndex, expandIconAsCell, expanded, expandRowByClick,rowDraggAble,
|
||||
expandable, onExpand, needIndentSpaced, indent, indentSize,isHiddenExpandIcon,fixed,bodyDisplayInRow
|
||||
,expandedIcon,collapsedIcon, hoverKey,lazyStartIndex,lazyEndIndex, expandIconCellWidth, getCellClassName
|
||||
,expandedIcon,collapsedIcon, hoverKey,lazyStartIndex,lazyEndIndex, expandIconCellWidth
|
||||
} = this.props;
|
||||
const {notRowDrag} = this.state;
|
||||
let showSum = false;
|
||||
let { className } = this.props;
|
||||
if (this.state.hovered) {
|
||||
|
|
@ -507,8 +488,7 @@ class TableRow extends Component{
|
|||
expandIndexInThisTable = expandIconColumnIndex
|
||||
}
|
||||
for (let i = 0; i < columns.length; i++) {
|
||||
if (expandIconAsCell && i === 0) {
|
||||
showSum ? cells.push(<td width={expandIconCellWidth}></td>) :
|
||||
if (expandIconAsCell && i === 0 && !showSum ) {
|
||||
cells.push(
|
||||
<td
|
||||
className={`${clsPrefix}-expand-icon-cell ${isExpandIconAsCell}`}
|
||||
|
|
@ -537,10 +517,6 @@ class TableRow extends Component{
|
|||
bodyDisplayInRow = {bodyDisplayInRow}
|
||||
lazyStartIndex={lazyStartIndex}
|
||||
lazyEndIndex={lazyEndIndex}
|
||||
onPaste={onPaste}
|
||||
stopRowDrag={this.stopRowDrag}
|
||||
col={i}
|
||||
getCellClassName = {getCellClassName}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
|
@ -551,14 +527,9 @@ class TableRow extends Component{
|
|||
if(record && record._checked){
|
||||
className += ' selected';
|
||||
}
|
||||
|
||||
if(rowDraggAble && !useDragHandle && !notRowDrag) {
|
||||
className += ' row-dragg-able'
|
||||
}
|
||||
|
||||
return (
|
||||
<tr
|
||||
draggable={rowDraggAble && !useDragHandle && !notRowDrag}
|
||||
draggable={rowDraggAble}
|
||||
onClick={this.onRowClick}
|
||||
onDoubleClick={this.onRowDoubleClick}
|
||||
onMouseEnter={this.onMouseEnter}
|
||||
|
|
@ -566,7 +537,6 @@ class TableRow extends Component{
|
|||
className={`${clsPrefix} ${className} ${clsPrefix}-level-${indent}`}
|
||||
style={style}
|
||||
data-row-key={record && record.key?record.key:hoverKey}
|
||||
data-row-index={this.props.index}
|
||||
// key={hoverKey}
|
||||
ref={this.bindElement}
|
||||
>
|
||||
|
|
|
|||
|
|
@ -73,12 +73,9 @@ export default function bigData(Table) {
|
|||
_this.cachedRowParentIndex = [];
|
||||
_this.computeCachedRowParentIndex(newData);
|
||||
// fix:切换数据源,startIndex、endIndex错误
|
||||
if(_this.scrollTop <= 0) { // 增加scrollTop 判断,ncc场景下滚动条不在最上层, 会出现空白,因为重置了currentIndex没有重置滚动条
|
||||
_this.currentIndex = 0;
|
||||
_this.startIndex = _this.currentIndex; //数据开始位置
|
||||
_this.endIndex = _this.currentIndex + _this.loadCount;
|
||||
}
|
||||
|
||||
_this.currentIndex = 0;
|
||||
_this.startIndex = _this.currentIndex; //数据开始位置
|
||||
_this.endIndex = _this.currentIndex + _this.loadCount;
|
||||
}
|
||||
_this.treeData = [];
|
||||
_this.flatTreeData = [];
|
||||
|
|
@ -90,7 +87,7 @@ export default function bigData(Table) {
|
|||
}
|
||||
}
|
||||
//如果传currentIndex,会判断该条数据是否在可视区域,如果没有的话,则重新计算startIndex和endIndex
|
||||
if(currentIndex != -1 && currentIndex !== this.currentIndex){
|
||||
if(currentIndex!==-1 && currentIndex !== this.currentIndex){
|
||||
_this.setStartAndEndIndex(currentIndex,dataLen);
|
||||
}
|
||||
}
|
||||
|
|
@ -295,7 +292,7 @@ export default function bigData(Table) {
|
|||
if (this.cachedRowHeight[i] == undefined) {
|
||||
if (this.treeType) {
|
||||
// currentKey = this.keys[i];
|
||||
currentKey = this.flatTreeData[i] && this.flatTreeData[i].key;
|
||||
currentKey = this.flatTreeData[i].key;
|
||||
currentRowHeight = 0;
|
||||
if (
|
||||
this.flatTreeKeysMap.hasOwnProperty(currentKey)
|
||||
|
|
|
|||
|
|
@ -27,47 +27,24 @@ export default function sort(Table, Icon) {
|
|||
let flatColumns = [];
|
||||
this._toFlatColumn(props.columns,-1,flatColumns);
|
||||
this.state = { data: this.props.data, columns: props.columns,flatColumns:flatColumns };
|
||||
this._initSort();
|
||||
|
||||
}
|
||||
static defaultProps = { sort: { mode: "single", backSource: false } }; //默认是前端排序,值为true为后端排序
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
|
||||
if (nextProps.columns !== this.props.columns) {
|
||||
let flatColumns = [];
|
||||
this._toFlatColumn(nextProps.columns,-1,flatColumns);
|
||||
this.setState({ columns: nextProps.columns ,flatColumns});
|
||||
}
|
||||
|
||||
if (nextProps.data !== this.props.data) {
|
||||
this.setState({
|
||||
data: nextProps.data,
|
||||
oldData: nextProps.data.concat()
|
||||
}, function(){
|
||||
this._initSort(); // 数据更新后需要重新排序
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
_initSort = () => {
|
||||
const {flatColumns} = this.state;
|
||||
let needSort = false;
|
||||
flatColumns.forEach(item => {
|
||||
if(item.order == 'descend' || item.order == 'ascend') {
|
||||
needSort = true;
|
||||
return
|
||||
}
|
||||
})
|
||||
if(needSort) {
|
||||
const data = this.multiSort(flatColumns)
|
||||
this.setState({
|
||||
data
|
||||
})
|
||||
if (nextProps.columns !== this.props.columns) {
|
||||
let flatColumns = [];
|
||||
this._toFlatColumn(nextProps.columns,-1,flatColumns);
|
||||
this.setState({ columns: nextProps.columns ,flatColumns});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*column扁平化处理,适应多表头避免递归操作
|
||||
*
|
||||
|
|
@ -163,7 +140,7 @@ export default function sort(Table, Icon) {
|
|||
* 多列排序 先排order为1的,其他的基于已排序的数据排
|
||||
*/
|
||||
multiSort = columns => {
|
||||
let { data, oldData=[] } = this.state;
|
||||
let { data, oldData } = this.state;
|
||||
const self = this;
|
||||
let orderCols = {},
|
||||
orderColslen = 0;
|
||||
|
|
@ -185,7 +162,7 @@ export default function sort(Table, Icon) {
|
|||
};
|
||||
|
||||
toggleSortOrder = (order, column) => {
|
||||
let { data, oldData = [], flatColumns } = this.state;
|
||||
let { data, oldData, flatColumns } = this.state;
|
||||
let { sort } = this.props;
|
||||
let seleObj;
|
||||
if (!oldData) {
|
||||
|
|
@ -223,7 +200,7 @@ export default function sort(Table, Icon) {
|
|||
} else {
|
||||
data = oldData.concat();
|
||||
}
|
||||
typeof sort.sortFun === "function" && sort.sortFun(sortCol,data,oldData);
|
||||
typeof sort.sortFun === "function" && sort.sortFun(sortCol,data);
|
||||
}
|
||||
} else {
|
||||
seleObj = flatColumns.find(da => da.key == column.key);
|
||||
|
|
@ -239,7 +216,7 @@ export default function sort(Table, Icon) {
|
|||
sort.sortFun(sortCol);
|
||||
} else {
|
||||
data = this.multiSort(flatColumns);
|
||||
typeof sort.sortFun === "function" && sort.sortFun(sortCol,data,oldData);
|
||||
typeof sort.sortFun === "function" && sort.sortFun(sortCol,data);
|
||||
}
|
||||
}
|
||||
this.setState({ data, oldData, flatColumns });
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import React from "react";
|
||||
|
||||
import {DicimalFormater} from "./utils";
|
||||
export default function sum(Table,precision=2) {
|
||||
export default function sum(Table) {
|
||||
return class SumTable extends React.Component {
|
||||
//无状态
|
||||
constructor(props) {
|
||||
|
|
@ -23,7 +23,7 @@ export default function sum(Table,precision=2) {
|
|||
|
||||
/**
|
||||
* 获取当前的表格类型。
|
||||
*
|
||||
*
|
||||
*/
|
||||
getTableType=()=>{
|
||||
const {columns} = this.props;
|
||||
|
|
@ -37,18 +37,7 @@ export default function sum(Table,precision=2) {
|
|||
return type;
|
||||
}
|
||||
|
||||
toThousands(num) {
|
||||
let result = '', counter = 0;
|
||||
num = (num || 0).toString();
|
||||
const numArr = num.split('.')
|
||||
num = numArr[0]
|
||||
for (var i = num.length - 1; i >= 0; i--) {
|
||||
counter++;
|
||||
result = num.charAt(i) + result;
|
||||
if (!(counter % 3) && i != 0) { result = ',' + result; }
|
||||
}
|
||||
return numArr.length === 1 ? result : result +'.' +numArr[1];
|
||||
}
|
||||
|
||||
|
||||
addSumData=()=>{
|
||||
let {data=[],columns=[]} = this.props;
|
||||
|
|
@ -67,29 +56,21 @@ export default function sum(Table,precision=2) {
|
|||
if(column.sumCol){
|
||||
let count = 0;
|
||||
data.forEach((da,i)=>{
|
||||
|
||||
|
||||
let _num = parseFloat(da[column.key]);
|
||||
//排查字段值为NAN情况
|
||||
if(_num == _num){
|
||||
count += _num;
|
||||
}
|
||||
|
||||
|
||||
})
|
||||
let sum = DicimalFormater(count,precision);
|
||||
if(column.sumThousandth) {
|
||||
sum = this.toThousands(sum)
|
||||
}
|
||||
sumdata[column.dataIndex] = sum;
|
||||
if(column.sumRender&&typeof column.sumRender =='function'){
|
||||
sumdata[column.dataIndex] = column.sumRender(sum)
|
||||
}
|
||||
|
||||
sumdata[column.dataIndex] = DicimalFormater(count,2);
|
||||
}
|
||||
if(index == 0){
|
||||
sumdata[column.dataIndex] = "合计 "+sumdata[column.dataIndex];
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
newData.push(sumdata);
|
||||
return newData;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue