bee-table
Version:
Table ui component for react
1,262 lines (1,148 loc) • 106 kB
JavaScript
'use strict';
Object.defineProperty(exports, "__esModule", {
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; };
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _TableRow = require('./TableRow');
var _TableRow2 = _interopRequireDefault(_TableRow);
var _TableHeader = require('./TableHeader');
var _TableHeader2 = _interopRequireDefault(_TableHeader);
var _utils = require('./lib/utils');
var _shallowequal = require('shallowequal');
var _shallowequal2 = _interopRequireDefault(_shallowequal);
var _ColumnManager = require('./ColumnManager');
var _ColumnManager2 = _interopRequireDefault(_ColumnManager);
var _createStore = require('./createStore');
var _createStore2 = _interopRequireDefault(_createStore);
var _beeLoading = require('bee-loading');
var _beeLoading2 = _interopRequireDefault(_beeLoading);
var _beeIcon = require('bee-icon');
var _beeIcon2 = _interopRequireDefault(_beeIcon);
var _util = require('./lib/util');
var _i18n = require('./lib/i18n');
var _i18n2 = _interopRequireDefault(_i18n);
var _tool = require('bee-locale/build/tool');
var _resizeObserverPolyfill = require('resize-observer-polyfill');
var _resizeObserverPolyfill2 = _interopRequireDefault(_resizeObserverPolyfill);
var _DragResizerLine = require('./DragResizerLine');
var _DragResizerLine2 = _interopRequireDefault(_DragResizerLine);
var _DragRowLine = require('./DragRowLine');
var _DragRowLine2 = _interopRequireDefault(_DragRowLine);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; }
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
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); }
var prefix = 'u';
var propTypes = {
data: _propTypes2["default"].array,
expandIconAsCell: _propTypes2["default"].bool,
defaultExpandAllRows: _propTypes2["default"].bool,
expandedRowKeys: _propTypes2["default"].array,
defaultExpandedRowKeys: _propTypes2["default"].array,
useFixedHeader: _propTypes2["default"].bool,
columns: _propTypes2["default"].array,
clsPrefix: _propTypes2["default"].string,
bodyStyle: _propTypes2["default"].object,
style: _propTypes2["default"].object,
//特殊的渲染规则的key值
rowKey: _propTypes2["default"].oneOfType([_propTypes2["default"].string, _propTypes2["default"].func]),
rowClassName: _propTypes2["default"].func,
//column的主键,和 column.key 作用相同
columnKey: _propTypes2["default"].string,
expandedRowClassName: _propTypes2["default"].func,
childrenColumnName: _propTypes2["default"].string,
onExpand: _propTypes2["default"].func,
onRowHover: _propTypes2["default"].func,
onExpandedRowsChange: _propTypes2["default"].func,
indentSize: _propTypes2["default"].number,
onRowClick: _propTypes2["default"].func,
onRowDoubleClick: _propTypes2["default"].func,
expandIconColumnIndex: _propTypes2["default"].number,
//是否显示表头
showHeader: _propTypes2["default"].bool,
title: _propTypes2["default"].func,
footer: _propTypes2["default"].func,
emptyText: _propTypes2["default"].func,
scroll: _propTypes2["default"].object,
rowRef: _propTypes2["default"].func,
getBodyWrapper: _propTypes2["default"].func,
children: _propTypes2["default"].node,
draggable: _propTypes2["default"].bool,
minColumnWidth: _propTypes2["default"].number,
filterable: _propTypes2["default"].bool,
filterDelay: _propTypes2["default"].number,
onFilterChange: _propTypes2["default"].func,
onFilterClear: _propTypes2["default"].func,
syncHover: _propTypes2["default"].bool,
tabIndex: _propTypes2["default"].string,
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,
originWidth: _propTypes2["default"].number,
scrollTop: _propTypes2["default"].number,
lazyLoad: _propTypes2["default"].bool,
ignoreScrollYChange: _propTypes2["default"].func,
onResize: _propTypes2["default"].func,
bordered: _propTypes2["default"].bool,
onDragStart: _propTypes2["default"].func,
onDragEnter: _propTypes2["default"].func,
onDragOver: _propTypes2["default"].func,
onDrop: _propTypes2["default"].func,
onDragEnd: _propTypes2["default"].func,
onMouseDown: _propTypes2["default"].func,
onMouseMove: _propTypes2["default"].func,
onMouseUp: _propTypes2["default"].func,
dragborder: _propTypes2["default"].bool,
onDropBorder: _propTypes2["default"].func,
onDraggingBorder: _propTypes2["default"].func,
dragborderKey: _propTypes2["default"].string,
headerHeight: _propTypes2["default"].string,
afterDragColWidth: _propTypes2["default"].number,
headerScroll: _propTypes2["default"].func,
headerEventNoStop: _propTypes2["default"].bool,
onCopy: _propTypes2["default"].func,
resetScroll: _propTypes2["default"].func,
footerScroll: _propTypes2["default"].func,
hideHeaderScroll: _propTypes2["default"].func,
locale: _propTypes2["default"].string,
getCellClassName: _propTypes2["default"].string,
useDragHandle: _propTypes2["default"].func,
expandedRowRender: _propTypes2["default"].any,
expandRowByClick: _propTypes2["default"].func,
haveExpandIcon: _propTypes2["default"].any,
expandedIcon: _propTypes2["default"].any,
collapsedIcon: _propTypes2["default"].any,
height: _propTypes2["default"].number,
showSum: _propTypes2["default"].bool,
heightConsistent: _propTypes2["default"].bool,
syncFixedRowHeight: _propTypes2["default"].bool,
setRowHeight: _propTypes2["default"].func,
setRowParentIndex: _propTypes2["default"].func,
handleScrollY: _propTypes2["default"].func,
handleScrollX: _propTypes2["default"].func,
onKeyTab: _propTypes2["default"].func,
onKeyUp: _propTypes2["default"].func,
onKeyDown: _propTypes2["default"].func,
onTableKeyDown: _propTypes2["default"].func,
focusable: _propTypes2["default"].bool,
loading: _propTypes2["default"].bool
};
var defaultProps = {
data: [],
useFixedHeader: true,
expandIconAsCell: false,
defaultExpandAllRows: false,
defaultExpandedRowKeys: [],
columnKey: 'key',
rowKey: 'key',
rowClassName: function rowClassName() {
return '';
},
expandedRowClassName: function expandedRowClassName() {
return '';
},
onExpand: function onExpand() {},
onExpandedRowsChange: function onExpandedRowsChange() {},
onRowClick: function onRowClick() {},
// onRowDoubleClick() { },
clsPrefix: prefix + '-table',
bodyStyle: {},
style: {},
childrenColumnName: 'children',
indentSize: 15,
expandIconColumnIndex: 0,
showHeader: true,
scroll: {},
rowRef: function rowRef() {
return null;
},
getBodyWrapper: function getBodyWrapper(body) {
return body;
},
// emptyText: () => <div><Icon type="uf-nodata" className="table-nodata"></Icon><span>{locale["no_data"]}</span></div>,
columns: [],
minColumnWidth: 80,
locale: {},
syncHover: true,
// 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,
headerHeight: null,
showRowNum: false,
onPaste: function onPaste() {},
originWidth: null //做什么用??
};
var expandIconCellWidth = Number(43);
var tableUUID = function tableUUID() {
return "_table_uid_" + new Date().getTime();
};
var browserInfo = {};
var Table = function (_Component) {
_inherits(Table, _Component);
function Table(props) {
_classCallCheck(this, Table);
var _this = _possibleConstructorReturn(this, _Component.call(this, props));
_initialiseProps.call(_this);
browserInfo = (0, _utils.myBrowser)();
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.store = (0, _createStore2["default"])({ currentHoverKey: null });
_this.firstDid = true;
_this.scrollYChanged = false;
if (props.defaultExpandAllRows) {
for (var i = 0; i < rows.length; i++) {
var row = rows[i];
expandedRowKeys.push(_this.getRowKey(row, i));
rows = rows.concat(row[props.childrenColumnName] || []);
}
} else {
expandedRowKeys = props.expandedRowKeys || props.defaultExpandedRowKeys;
}
_this.state = {
expandedRowKeys: expandedRowKeys,
data: props.data,
currentHoverKey: null,
scrollPosition: 'left',
fixedColumnsHeadRowsHeight: null,
fixedColumnsBodyRowsHeight: [],
fixedColumnsExpandedRowsHeight: {} //扩展行的高度
};
_this.onExpandedRowsChange = _this.onExpandedRowsChange.bind(_this);
_this.onExpanded = _this.onExpanded.bind(_this);
_this.onRowDestroy = _this.onRowDestroy.bind(_this);
_this.getRowKey = _this.getRowKey.bind(_this);
_this.getExpandedRows = _this.getExpandedRows.bind(_this);
_this.getHeader = _this.getHeader.bind(_this);
_this.getHeaderRows = _this.getHeaderRows.bind(_this);
_this.getExpandedRow = _this.getExpandedRow.bind(_this);
_this.getRowsByData = _this.getRowsByData.bind(_this);
_this.getRows = _this.getRows.bind(_this);
_this.getColGroup = _this.getColGroup.bind(_this);
_this.getLeftFixedTable = _this.getLeftFixedTable.bind(_this);
_this.getRightFixedTable = _this.getRightFixedTable.bind(_this);
_this.getTable = _this.getTable.bind(_this);
_this.getTitle = _this.getTitle.bind(_this);
_this.getFooter = _this.getFooter.bind(_this);
_this.getEmptyText = _this.getEmptyText.bind(_this);
_this.syncFixedTableRowHeight = _this.syncFixedTableRowHeight.bind(_this);
_this.resetScrollX = _this.resetScrollX.bind(_this);
_this.findExpandedRow = _this.findExpandedRow.bind(_this);
_this.isRowExpanded = _this.isRowExpanded.bind(_this);
// this.detectScrollTarget = this.detectScrollTarget.bind(this);
_this.handleBodyScroll = _this.handleBodyScroll.bind(_this);
_this.handleRowHover = _this.handleRowHover.bind(_this);
_this.computeTableWidth = _this.computeTableWidth.bind(_this);
_this.onBodyMouseLeave = _this.onBodyMouseLeave.bind(_this);
_this.tableUid = tableUUID();
_this.contentTable = null;
_this.leftColumnsLength; //左侧固定列的长度
_this.centerColumnsLength; //非固定列的长度// this.columnsChildrenList = [];//复杂表头、所有叶子节点
_this.dataChanged = false; // 数据是否改变
//同步行高时使用的缓存
_this.fixedColumnsBodyRowsHeightCache = null;
_this.fixedColumnsExpandedRowsHeightCache = null;
return _this;
}
Table.prototype.componentWillMount = function componentWillMount() {
this.centerColumnsLength = this.columnManager.centerColumns().length;
this.leftColumnsLength = this.columnManager.leftColumns().length;
};
Table.prototype.componentDidMount = function componentDidMount() {
var _this2 = this;
// this.getTableUID();
_utils.EventUtil.addHandler(this.contentTable, 'keydown', this.onKeyDown);
_utils.EventUtil.addHandler(this.contentTable, 'focus', this.onFocus);
setTimeout(this.resetScrollX, 300);
//含有纵向滚动条
// if(this.props.scroll.y){
// this.scrollbarWidth = measureScrollbar(`.u-table`);
// }
this.scrollbarWidth = (0, _utils.measureScrollbar)('.' + this.props.clsPrefix); //dom装载后获取浏览器下的滚动条宽度
//后续也放在recevice里面
if (!this.props.originWidth) {
this.computeTableWidth();
}
var _props = this.props,
useFixedHeader = _props.useFixedHeader,
_props$scroll = _props.scroll,
scroll = _props$scroll === undefined ? {} : _props$scroll;
if (this.columnManager.isAnyColumnsFixed()) {
this.syncFixedTableRowHeight(); //同步固定列的内容行高度
var targetNode = this.contentTable;
if (targetNode) {
this.resizeObserver = new _resizeObserverPolyfill2["default"](function () {
_this2.resize();
});
this.resizeObserver.observe(targetNode);
}
}
if (scroll.y) {
//固定列头存在则执行head和body的宽度
this.syncFixedTableScrollWidth(); //同步固定列的滚动宽度
}
};
Table.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
var _props2 = this.props,
hideDragHandle = _props2.hideDragHandle,
rowDraggAble = _props2.rowDraggAble,
showRowNum = _props2.showRowNum,
clsPrefix = _props2.clsPrefix;
// 清除同步行高时使用的缓存
this.fixedColumnsBodyRowsHeightCache = null;
this.fixedColumnsExpandedRowsHeightCache = null;
if ('data' in nextProps) {
this.setState({
data: nextProps.data
});
}
if ('defaultExpandAllRows' in nextProps) {
var defaultExpandAllRows = nextProps.defaultExpandAllRows,
data = nextProps.data,
expandedRowKeys = nextProps.expandedRowKeys,
_nextProps$childrenCo = nextProps.childrenColumnName,
childrenColumnName = _nextProps$childrenCo === undefined ? 'children' : _nextProps$childrenCo;
if (defaultExpandAllRows && !expandedRowKeys) {
var _expandedRowKeys = [];
var rows = [].concat(_toConsumableArray(data || []));
for (var i = 0; i < rows.length; i++) {
var row = rows[i];
_expandedRowKeys.push(this.getRowKey(row, i));
rows = rows.concat(row[childrenColumnName] || []);
}
this.setState({
expandedRowKeys: _expandedRowKeys
});
} else if (!defaultExpandAllRows && !expandedRowKeys) {
this.expandedRowKeys = [];
}
}
if ('expandedRowKeys' in nextProps) {
this.setState({
expandedRowKeys: nextProps.expandedRowKeys
});
}
if (nextProps.columns && !(0, _shallowequal2["default"])(nextProps.columns, this.props.columns)) {
this.columnManager.reset(nextProps.columns, null, showRowNum, !hideDragHandle && rowDraggAble); // 加入this.props.showRowNum参数
if (nextProps.columns.length !== this.props.columns.length && 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参数
}
//适配lazyload
if (nextProps.scrollTop > -1) {
// this.bodyTable.scrollTop = nextProps.scrollTop;
this.scrollTop = nextProps.scrollTop;
}
// fix:模态框中使用table,计算的滚动条宽度为0的bug
// fix:表格首次渲染时 display:none,再显示时,未重新计算,导致表行出现错位的bug
// if(this.scrollbarWidth<=0 && this.props.scroll.y){
// this.scrollbarWidth = measureScrollbar(`.${clsPrefix}`);
// }
if (!nextProps.originWidth) {
this.computeTableWidth();
this.firstDid = true; //避免重复update
}
if (nextProps.resetScroll) {
this.resetScrollX();
}
// console.log('this.scrollTop**********',this.scrollTop);
};
Table.prototype.componentDidUpdate = function componentDidUpdate(prevProps, prevState) {
// todo: IE 大数据渲染,行高不固定,且设置了 heightConsistent={true} 时,滚动加载操作会导致 ie11 浏览器崩溃
// https://github.com/tinper-bee/bee-table/commit/bd2092cdbaad236ff89477304e58dea93325bf09
var _props3 = this.props,
useFixedHeader = _props3.useFixedHeader,
_props3$scroll = _props3.scroll,
scroll = _props3$scroll === undefined ? {} : _props3$scroll;
if (this.columnManager.isAnyColumnsFixed()) {
(0, _utils.debounce)(this.syncFixedTableRowHeight(), 200); //同步固定列内容行的高度
}
if (scroll.y) {
//固定列头存在则执行head和body的宽度
(0, _utils.debounce)(this.syncFixedTableScrollWidth(), 200); //同步固定列的滚动宽度
}
//适应模态框中表格、以及父容器宽度变化的情况
if (typeof this.props.scroll.x !== 'number' && this.contentTable.getBoundingClientRect().width !== this.contentDomWidth && this.firstDid) {
this.computeTableWidth();
this.firstDid = false; //避免重复update
}
if (this.scrollTop > -1) {
this.fixedLeftBodyInner && (this.fixedLeftBodyInner.scrollTop = this.scrollTop);
this.fixedRightBodyInner && (this.fixedRightBodyInner.scrollTop = this.scrollTop);
this.bodyTable.scrollTop = this.scrollTop;
this.scrollTop = -1;
}
// 当表格没有数据时,重置滚动条位置,造成grid里面的表头列无法操作
// if (prevProps.data.length === 0 || this.props.data.length === 0 ) {
// this.resetScrollX();
// }
// 当懒加载手动设置的scroll.y发生变化时,滚动条回到顶部
var prevScrollY = prevProps.scroll.y;
var 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) {
if (prevScrollY !== currentScrollY) {
this.scrollYChanged = true;
var bodyScrollTop = this.bodyTable.scrollTop;
if (bodyScrollTop === 0) {
// 在顶部的时候,滚动条不用动
this.bodyTable.scrollTop = 0;
} else {
var distance = bodyScrollTop + currentScrollY - prevScrollY;
if (distance < 0) {
this.bodyTable.scrollTop = 0;
} else {
var _bodyTable = this.bodyTable,
scrollHeight = _bodyTable.scrollHeight,
scrollTop = _bodyTable.scrollTop;
var bottomDistance = Math.abs(scrollHeight - scrollTop - prevScrollY); // 在最底部的时候也不用滚动滚动条
if (bottomDistance < 5) {
// 有些dom计算不是十分精确,设置一个值来缓冲一下
this.bodyTable.scrollTop = scrollTop + prevScrollY - currentScrollY;
} else {
this.bodyTable.scrollTop = distance;
}
}
}
} else if (this.scrollYChanged) {
this.bodyTable.scrollTop += 1;
this.scrollYChanged = false;
}
}
// 是否传入 scroll中的y属性,如果传入判断是否是整数,如果是则进行比较 。bodyTable 的clientHeight进行判断
// this.isShowScrollY();
// gx为了解决底部滚动条显示的问题
// if (this.bodyTable) {
// const currentOverflowX = window.getComputedStyle(this.bodyTable).overflowX;
// if (this.props.scroll.x && currentOverflowX !== 'scroll') {
// // 此处应该对比一下实际的
// if (this.computeWidth > this.contentDomWidth) {
// this.bodyTable.style.overflowX = 'scroll';
// }
// }
// }
// let scrollContainerWidth = window.getComputedStyle(this.bodyTableOuter.querySelector('.scroll-container')).width; // scroll-container层元素的宽度
// let scrollContainerTableWidth = this.bodyTableOuter.querySelector('.table-bordered').style.width; // scroll-container内层table元素的宽度
// // 有左右固定列时,scroll-container因为有竖直滚动条,使得scroll-container实际宽度(不包括滚动条的宽度)小于内部table宽度出现水平方向滚动条,导致滚动到底部不对齐
// if ((parseFloat(scrollContainerWidth) >= parseFloat(scrollContainerTableWidth)) && (this.columnManager.leftLeafColumns().length > 0 || this.columnManager.rightLeafColumns().length > 0)) {
// this.bodyTable.style.overflowX = 'hidden';
// } else {
// this.bodyTable.style.overflowX = 'auto';
// }
// if (this.bodyTableOuter) { // 隐藏几个不需要真正滚动的父元素的滚动条
// this.bodyTableOuter.style.overflowY = 'hidden'
// }
// if (this.fixedColumnsBodyLeftOuter) {
// this.fixedColumnsBodyLeftOuter.style.overflowY = 'hidden'
// }
// if (this.fixedColumnsBodyRightOuter) {
// this.fixedColumnsBodyRightOuter.style.overflowY = 'hidden'
// }
};
Table.prototype.componentWillUnmount = function componentWillUnmount() {
// 移除绑定事件,避免内存泄漏
this.contentTable = null;
_utils.EventUtil.removeHandler(this.contentTable, 'keydown', this.onKeyDown);
_utils.EventUtil.removeHandler(this.contentTable, 'focus', this.onFocus);
if (this.resizeObserver) {
this.resizeObserver.disconnect();
}
};
/*
getTableUID =()=>{
let uid = "_table_uid_"+new Date().getTime();
this.tableUid = uid;
let div = document.createElement("div");
div.className = "u-table-drag-hidden-cont";
div.id = uid;
this.contentTable.appendChild(div);
}
*/
//计算表格宽度 --- 这块有必要?待确认 待废除 zzj
Table.prototype.computeTableWidth = function computeTableWidth() {
var expandIconAsCell = this.props.expandIconAsCell;
//如果用户传了scroll.x按用户传的为主
var setWidthParam = this.props.scroll.x;
if (typeof setWidthParam == 'number') {
var numSetWidthParam = parseInt(setWidthParam);
this.contentWidth = numSetWidthParam;
} else {
// this.preContentDomWidth = this.contentDomWidth;
//计算总表格宽度、根据表格宽度和各列的宽度和比较,重置最后一列
this.contentDomWidth = this.contentTable.getBoundingClientRect().width; //表格容器宽度
this.contentWidth = this.contentDomWidth; //默认与容器宽度一样
}
var computeObj = this.columnManager.getColumnWidth(this.contentWidth);
var expandColWidth = expandIconAsCell ? expandIconCellWidth : 0;
var lastShowIndex = computeObj.lastShowIndex;
this.computeWidth = computeObj.computeWidth + expandColWidth;
this.domWidthDiff = this.contentDomWidth - this.computeWidth;
if (typeof setWidthParam == 'string' && setWidthParam.indexOf('%')) {
this.contentWidth = this.contentWidth * parseInt(setWidthParam) / 100;
this.domWidthDiff = this.contentDomWidth - this.contentWidth;
}
if (this.computeWidth < this.contentWidth) {
var contentWidthDiff = this.scrollbarWidth ? this.contentWidth - this.computeWidth - this.scrollbarWidth : this.contentWidth - this.computeWidth;
//bordered的表格需要减去边框的差值1
if (this.props.bordered) {
contentWidthDiff = contentWidthDiff - 1;
}
this.setState({ contentWidthDiff: contentWidthDiff, lastShowIndex: lastShowIndex });
} else {
this.contentWidth = this.computeWidth;
this.setState({ contentWidthDiff: 0, lastShowIndex: lastShowIndex }); //重新渲染,为了显示滚动条
}
};
/*
//根据内容动态的判断是否显示纵向滚动条
isShowScrollY(){
const props = this.props;
const y = props.scroll && props.scroll.y;
if(y){
const bodyH = this.bodyTable.clientHeight;
const bodyContentH = this.bodyTable.querySelector('table').clientHeight;
const rightBodyTable = this.fixedRightBodyInner;
// const leftBodyTable = this.fixedLeftBodyInner;
const overflowy = bodyContentH <= bodyH ? 'auto':'scroll';
this.bodyTable.style.overflowY = overflowy;
this.headTable.style.overflowY = overflowy;
rightBodyTable && (rightBodyTable.style.overflowY = overflowy);
}
}
*/
//同步固定列情况下部分区域滚动条出现引起的错位问题
Table.prototype.onExpandedRowsChange = function onExpandedRowsChange(expandedRowKeys) {
if (!this.props.expandedRowKeys) {
this.setState({ expandedRowKeys: expandedRowKeys });
}
this.props.onExpandedRowsChange(expandedRowKeys);
};
Table.prototype.onExpanded = function onExpanded(expanded, record, index, e) {
if (e) {
e.preventDefault();
e.stopPropagation();
}
var info = this.findExpandedRow(record);
if (typeof info !== 'undefined' && !expanded) {
this.onRowDestroy(record, index, true);
} else if (!info && expanded) {
var expandedRows = this.getExpandedRows().concat();
expandedRows.push(this.getRowKey(record, index));
this.onExpandedRowsChange(expandedRows);
}
this.props.onExpand(expanded, record, index);
};
Table.prototype.onRowDestroy = function onRowDestroy(record, rowIndex, isExpandOperation) {
var expandedRows = this.getExpandedRows().concat();
var rowKey = this.getRowKey(record, rowIndex);
var index = -1;
expandedRows.forEach(function (r, i) {
if (r === rowKey) {
index = i;
}
});
if (index !== -1) {
expandedRows.splice(index, 1);
}
//
if (this.currentHoverKey == rowKey && this.hoverDom) {
this.hoverDom.style.display = 'none';
}
// todo:如果是TableRow组件卸载触发的该方法,需要加判断,解决懒加载时,持续触发onExpandedRowsChange的问题
if (isExpandOperation) {
this.onExpandedRowsChange(expandedRows);
} else {
var info = this.findExpandedRow(record);
if (typeof info === 'undefined') {
this.onExpandedRowsChange(expandedRows);
}
}
};
Table.prototype.getRowKey = function getRowKey(record, index) {
var rowKey = this.props.rowKey;
var key = typeof rowKey === 'function' ? rowKey(record, index) : record[rowKey];
(0, _utils.warningOnce)(key !== undefined, 'Each record in table should have a unique `key` prop,' + 'or set `rowKey` to an unique primary key.');
return key;
};
Table.prototype.getExpandedRows = function getExpandedRows() {
return this.props.expandedRowKeys || this.state.expandedRowKeys;
};
Table.prototype.getHeader = function getHeader(columns, fixed, leftFixedWidth, rightFixedWidth) {
var _props4 = this.props,
filterDelay = _props4.filterDelay,
onFilterChange = _props4.onFilterChange,
onFilterClear = _props4.onFilterClear,
filterable = _props4.filterable,
showHeader = _props4.showHeader,
expandIconAsCell = _props4.expandIconAsCell,
clsPrefix = _props4.clsPrefix,
onDragStart = _props4.onDragStart,
onDragEnter = _props4.onDragEnter,
onDragOver = _props4.onDragOver,
onDrop = _props4.onDrop,
onDragEnd = _props4.onDragEnd,
draggable = _props4.draggable,
onMouseDown = _props4.onMouseDown,
onMouseMove = _props4.onMouseMove,
onMouseUp = _props4.onMouseUp,
dragborder = _props4.dragborder,
dragborderKey = _props4.dragborderKey,
minColumnWidth = _props4.minColumnWidth,
headerHeight = _props4.headerHeight,
afterDragColWidth = _props4.afterDragColWidth,
headerScroll = _props4.headerScroll,
bordered = _props4.bordered,
onDropBorder = _props4.onDropBorder,
onDraggingBorder = _props4.onDraggingBorder,
bodyDisplayInRow = _props4.bodyDisplayInRow,
headerEventNoStop = _props4.headerEventNoStop,
onCopy = _props4.onCopy;
var columnsChildrenList = []; //复杂表头拖拽,重新render表头前,将其置空
var rows = this.getHeaderRows({ columns: columns, columnsChildrenList: columnsChildrenList });
if (expandIconAsCell) {
var hasLeftFixed = this.columnManager.isAnyColumnsLeftFixed();
if (hasLeftFixed && fixed == 'left' || //存在左侧固定列则展开图标独立到左侧区域
!hasLeftFixed && !fixed //不存在左侧固定列则展开图标独立到中间区域
) {
rows[0].unshift({
key: prefix + '-table-expandIconAsCell',
className: clsPrefix + '-expand-icon-th',
title: '',
rowSpan: rows.length,
width: expandIconCellWidth
});
columnsChildrenList.unshift({
className: prefix + '-table-expand-icon-column',
key: "expand-icon"
});
}
}
if (fixed) {
columnsChildrenList = columnsChildrenList.filter(function (col) {
return col.fixed == fixed;
}); //只获取对应的固定列
} else {
columnsChildrenList = columnsChildrenList.filter(function (col) {
return !col.fixed;
}); //只获取非固定的列
}
// const trStyle = headerHeight&&!fixed ? { height: headerHeight } : (fixed ? this.getHeaderRowStyle(columns, rows) : null);
var trStyle = this.getHeaderRowStyle(columns, rows); //确保固定列和非固定列表头行高一致
var drop = draggable ? { onDragStart: onDragStart, onDragOver: onDragOver, onDrop: onDrop, onDragEnd: onDragEnd, onDragEnter: onDragEnter, draggable: draggable } : {};
var dragBorder = dragborder ? { onMouseDown: this.onDragBorderMouseDown, onMouseMove: onMouseMove, onMouseUp: onMouseUp, dragborder: dragborder, dragborderKey: dragborderKey, onDropBorder: onDropBorder, onDraggingBorder: onDraggingBorder } : {};
return showHeader ? _react2["default"].createElement(_TableHeader2["default"], _extends({}, drop, dragBorder, {
columnManager: this.columnManager,
columnsChildrenList: columnsChildrenList,
locale: this.props.locale,
minColumnWidth: minColumnWidth,
contentWidthDiff: !fixed ? this.state.contentWidthDiff : 0
// contentWidth={this.contentWidth}
, clsPrefix: clsPrefix,
rows: rows,
contentTable: this.contentTable,
rowStyle: trStyle,
fixed: fixed,
filterable: filterable,
onFilterChange: onFilterChange,
onFilterClear: onFilterClear,
filterDelay: filterDelay,
afterDragColWidth: afterDragColWidth,
contentDomWidth: this.contentDomWidth,
scrollbarWidth: this.scrollbarWidth,
headerScroll: headerScroll,
bordered: bordered,
tableUid: this.tableUid,
leftFixedWidth: leftFixedWidth,
rightFixedWidth: rightFixedWidth,
bodyDisplayInRow: bodyDisplayInRow,
eventNoStop: headerEventNoStop,
onCopy: onCopy
})) : null;
};
Table.prototype.getHeaderRows = function getHeaderRows(options) {
var _this3 = this;
var columns = options.columns,
_options$currentRow = options.currentRow,
currentRow = _options$currentRow === undefined ? 0 : _options$currentRow,
rows = options.rows,
columnsChildrenList = options.columnsChildrenList;
var columnKey = this.props.columnKey;
// let { contentWidthDiff = 0, lastShowIndex = -1 } = this.state;
var filterCol = [];
rows = rows || [];
rows[currentRow] = rows[currentRow] || [];
// let centerShowColCount = 0;
columns.forEach(function (column, i) {
if (!column.key) {
column.key = column[columnKey];
}
if (column.rowSpan && rows.length < column.rowSpan) {
while (rows.length < column.rowSpan) {
rows.push([]);
}
}
var width = column.width;
if (typeof width == 'string' && width.indexOf('%') > -1 && _this3.contentWidth) {
width = Math.ceil(_this3.contentWidth * parseInt(width) / 100);
} else if (width) {
width = parseInt(width);
}
// if (!column.fixed && column.ifshow) {
// centerShowColCount++;//非固定列显示的个数
// if(lastShowIndex+1 == centerShowColCount && width){//对最后一列进行补全宽度
// width = width + contentWidthDiff;
// }
// }
var cell = {
key: column.key,
className: column.className || '',
children: column.title,
drgHover: column.drgHover,
fixed: column.fixed,
width: width,
dataIndex: column.dataIndex,
textAlign: column.textAlign,
titleAlign: column.titleAlign, // 标题水平对齐方式
required: column.required, // 标题是否展示必填标志
dragborder: column.dragborder || '' // 禁止某列拖动
};
if (column.onHeadCellClick) {
cell.onClick = column.onHeadCellClick;
}
if (column.children) {
_this3.getHeaderRows({ columns: column.children, currentRow: currentRow + 1, rows: rows, columnsChildrenList: columnsChildrenList });
} else {
columnsChildrenList && columnsChildrenList.push(column); //复杂表头拖拽,所有叶子节点
}
if ('colSpan' in column) {
cell.colSpan = column.colSpan;
}
if ('rowSpan' in column) {
cell.rowSpan = column.rowSpan;
}
if (cell.colSpan !== 0) {
rows[currentRow].push(cell);
}
//判断是否启用过滤
if (_this3.props.filterable) {
//组装Filter需要的Col
filterCol.push({
key: column.key,
children: "过滤渲染",
width: column.width,
fixed: column.fixed, // fixed
filtertype: column.filterType, //下拉的类型 包括['text','dropdown','date','daterange','number']
dataIndex: column.dataIndex, //field
datasource: _this3.props.data, //需要单独拿到数据处理
format: column.format, //设置日期的格式
filterdropdown: column.filterDropdown, //是否显示 show hide
filterdropdownauto: column.filterDropdownAuto, //是否自定义数据
filterdropdowndata: column.filterDropdownData, //自定义数据格式
filterdropdownfocus: column.filterDropdownFocus, //焦点触发函数回调
filterdropdowntype: column.filterDropdownType, //下拉的类型分为 String,Number 默认是String
filterdropdownincludekeys: column.filterDropdownIncludeKeys, //下拉条件按照指定的keys去显示
filterinputnumberoptions: column.filterInputNumberOptions //设置数值框内的详细属性
});
}
});
if (this.props.filterable) {
rows.push(filterCol);
}
return rows.filter(function (row) {
return row.length > 0;
});
};
Table.prototype.getExpandedRow = function getExpandedRow(key, content, visible, className, fixed, record, index) {
var _props5 = this.props,
clsPrefix = _props5.clsPrefix,
expandIconAsCell = _props5.expandIconAsCell,
onPaste = _props5.onPaste,
getCellClassName = _props5.getCellClassName;
var colCount = void 0;
if (fixed === 'left') {
colCount = this.columnManager.leftLeafColumns().length;
} else if (fixed === 'right') {
colCount = this.columnManager.rightLeafColumns().length;
} else {
colCount = this.columnManager.centerColumns().length; //计算非固定列的个数,fix: 嵌套表格场景,右侧列断开的问题
}
var hasLeftFixed = this.columnManager.isAnyColumnsLeftFixed();
var expandedRowHeight = this.state.fixedColumnsExpandedRowsHeight[key] || 'auto';
function contentContainer() {
if (content && content.props && content.props.style) {
return _react2["default"].createElement('div', { style: { height: content.props.style.height } });
} else {
return ' ';
}
}
var columns = [{
key: 'extra-row',
render: function render() {
return {
props: {
colSpan: colCount
},
children: !fixed ? content : contentContainer()
};
}
}];
if (expandIconAsCell) {
if (hasLeftFixed && fixed == 'left' || !hasLeftFixed && !fixed) {
columns.unshift({
key: 'expand-icon-placeholder',
className: 'expand-icon-placeholder',
render: function render() {
return null;
}
});
}
}
return _react2["default"].createElement(_TableRow2["default"], {
record: record,
index: index,
tableUid: this.tableUid,
onPaste: onPaste,
columns: columns,
visible: visible,
className: className,
key: key + '-extra-row',
hoverKey: key,
clsPrefix: clsPrefix + '-expanded-row',
indent: 1,
expandIconAsCell: false,
expandable: false,
store: this.store,
dragborderKey: this.props.dragborderKey,
rowDraggAble: this.props.rowDraggAble,
useDragHandle: this.props.useDragHandle,
height: expandedRowHeight,
getCellClassName: getCellClassName,
setRowHeight: this.props.setRowHeight,
isExpandedRow: true
});
};
//列宽度拖拽-鼠标按下的事件
//列宽度拖拽-鼠标松开的事件
//列宽度拖拽-取消事件
//列宽度拖拽-鼠标移动的事件
/**
* 行拖拽开始时触发
* @param currentKey 当前拖拽目标的key
*/
/**
* 行拖拽结束时触发
*/
/**
*
*
* @param {*} data
* @param {*} visible
* @param {*} indent 层级
* @param {*} columns
* @param {*} fixed
* @param {number} [rootIndex=-1] 祖级节点
* @returns
* @memberof Table
*/
Table.prototype.getRowsByData = function getRowsByData(data, visible, indent, columns, fixed) {
var rootIndex = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : -1;
var props = this.props;
var childrenColumnName = props.childrenColumnName;
var expandedRowRender = props.expandedRowRender;
var expandRowByClick = props.expandRowByClick;
var onPaste = props.onPaste;
var anyColumnsFixed = this.columnManager.isAnyColumnsFixed();
var hasLeftFixed = this.columnManager.isAnyColumnsLeftFixed();
var fixedColumnsBodyRowsHeight = this.state.fixedColumnsBodyRowsHeight;
var rst = [];
var height = void 0;
var rowClassName = props.rowClassName;
var rowRef = props.rowRef;
var expandedRowClassName = props.expandedRowClassName;
var needIndentSpaced = props.data.some(function (record) {
return record[childrenColumnName];
});
var onRowClick = props.onRowClick;
var onRowDoubleClick = props.onRowDoubleClick;
//const expandIconAsCell = fixed !== 'right' ? props.expandIconAsCell : false;
var expandIconColumnIndex = props.expandIconColumnIndex;
if (props.lazyLoad && props.lazyLoad.preHeight && indent == 0) {
// console.log("AAA--->lazyLoad--first->"+props.lazyLoad.preHeight);
rst.push(_react2["default"].createElement(_TableRow2["default"], { onPaste: onPaste, height: props.lazyLoad.preHeight, columns: [], className: 'table_lazyload_row_first', key: 'table_lazyload_row_first', store: this.store, visible: true }));
}
var leafColumns = void 0;
if (fixed === 'left') {
leafColumns = this.columnManager.leftLeafColumns();
} else if (fixed === 'right') {
leafColumns = this.columnManager.rightLeafColumns();
} else {
leafColumns = this.columnManager.leafColumns();
}
var lazyCurrentIndex = props.lazyLoad && props.lazyLoad.startIndex ? props.lazyLoad.startIndex : 0;
var lazyParentIndex = props.lazyLoad && props.lazyLoad.startParentIndex ? props.lazyLoad.startParentIndex : 0;
var lazyEndIndex = props.lazyLoad && props.lazyLoad.endIndex ? props.lazyLoad.endIndex : -1;
var lazyLoadEnable = props.lazyLoad && props.lazyLoad.startIndex > -1 && props.lazyLoad.endIndex > -1;
for (var i = 0; i < data.length; i++) {
var isHiddenExpandIcon = void 0;
var record = data[i];
var key = this.getRowKey(record, i);
// 兼容 NCC 以前的业务逻辑,支持外部通过 record 中的 isleaf 字段,判断是否为叶子节点
// record['_isLeaf'] = typeof record['isleaf'] === 'boolean' ? record['isleaf'] : record['_isLeaf'];
if (typeof record['isleaf'] === 'boolean') {
record['_isLeaf'] = record['isleaf']; //如果isleaf存在并且为boolean的情况下才生成_isLeaf,否则无需生成
}
// _isLeaf 字段是在 bigData 里添加的,只有层级树大数据场景需要该字段
// _isLeaf 有三种取值情况:true / false / null。(Table内部字段)
var _isLeaf = typeof record['_isLeaf'] === 'boolean' ? record['_isLeaf'] : null;
var childrenColumn = _isLeaf ? false : record[childrenColumnName];
var isRowExpanded = this.isRowExpanded(record, i);
var expandedRowContent = void 0;
var expandedContentHeight = 0;
//fixedIndex一般是跟index是一个值的,只有是树结构时,会讲子节点的值也累计上
var fixedIndex = i;
//判断是否是tree结构
if (this.treeType) {
fixedIndex = this.treeRowIndex;
}
if (expandedRowRender && isRowExpanded) {
expandedRowContent = expandedRowRender(record, fixedIndex + lazyCurrentIndex, indent);
expandedContentHeight = parseInt(expandedRowContent.props && expandedRowContent.props.style && expandedRowContent.props.style.height ? expandedRowContent.props.style.height : 0);
}
//只有当使用expandedRowRender参数的时候才去识别isHiddenExpandIcon(隐藏行展开的icon)
if (expandedRowRender && typeof props.haveExpandIcon == 'function') {
isHiddenExpandIcon = props.haveExpandIcon(record, i);
}
if (props.bodyDisplayInRow) {
//内容显示不换行,即显示为"..."
if (anyColumnsFixed) {
//存在固定列则强制同步行高度,以确保行不会错位
height = props.height ? props.height : fixedColumnsBodyRowsHeight[fixedIndex];
} else {
//不存在固定列,则按指定高度呈现行
height = props.height || 40;
}
} else {
//内容自适应行高
if (anyColumnsFixed) {
//存在固定列则强制同步行高度,以确保行不会错位
height = fixedColumnsBodyRowsHeight[fixedIndex];
} else {
//不存在固定列,则按内容高度自行呈现
}
}
// if (props.bodyDisplayInRow && props.height) {
// height = props.height
// } else if(fixed || props.heightConsistent) {
// height = fixedColumnsBodyRowsHeight[fixedIndex];
// }
var className = rowClassName(record, fixedIndex + lazyCurrentIndex, indent);
//合计代码如果是最后一行并且有合计功能时,最后一行为合计列
if (i == data.length - 1 && props.showSum) {
className = className + ' sumrow';
}
var paramRootIndex = rootIndex;
//小于0说明为第一层节点,她的子孙节点要保存自己的根节点
if (paramRootIndex < 0) {
paramRootIndex = i + lazyParentIndex;
}
var index = i;
if (rootIndex == -1) {
index = i + lazyParentIndex;
}
if (lazyLoadEnable && this.treeType && (record.index < lazyCurrentIndex || record.index > lazyEndIndex)) {
// 大数据表格下,如果是树表,父节点如果已经不在区域范围则无需渲染dom,解决快速向上滚动父级树节点闪现的问题
fixedIndex--;
this.treeRowIndex--;
} else {
rst.push(_react2["default"].createElement(_TableRow2["default"], {
onPaste: onPaste,
indent: indent,
indentSize: props.indentSize,
needIndentSpaced: needIndentSpaced,
className: '' + className,
record: record,
hasLeftFixed: hasLeftFixed,
expandIconAsCell: props.expandIconAsCell,
onDestroy: this.onRowDestroy,
index: index,
visible: visible,
expandRowByClick: expandRowByClick,
onExpand: this.onExpanded,
expandable: expandedRowRender || (childrenColumn && childrenColumn.length > 0 ? true : _isLeaf === false),
expanded: isRowExpanded,
clsPrefix: props.clsPrefix + '-row',
childrenColumnName: childrenColumnName,
columns: leafColumns,
expandIconColumnIndex: expandIconColumnIndex,
onRowClick: onRowClick,
onRowDoubleClick: onRowDoubleClick,
height: height,
isHiddenExpandIcon: isHiddenExpandIcon,
onHover: this.handleRowHover,
key: "table_row_" + key,
hoverKey: key,
ref: rowRef,
store: this.store,
fixed: fixed,
expandedContentHeight: expandedContentHeight,
setRowHeight: props.setRowHeight,
setRowParentIndex: props.setRowParentIndex,
treeType: childrenColumn || this.treeType ? true : false,
fixedIndex: fixedIndex + lazyCurrentIndex,
rootIndex: rootIndex,
syncHover: props.syncHover,
bodyDisplayInRow: props.bodyDisplayInRow,
rowDraggAble: props.rowDraggAble,
useDragHandle: props.useDragHandle,
contentTable: this.contentTable,
tableUid: this.tableUid,
expandedIcon: props.expandedIcon,
collapsedIcon: props.collapsedIcon,
lazyStartIndex: lazyCurrentIndex,
lazyEndIndex: lazyEndIndex,
centerColumnsLength: this.centerColumnsLength,
leftColumnsLength: this.leftColumnsLength,
expandIconCellWidth: expandIconCellWidth,
getCellClassName: props.getCellClassName
}));
}
this.treeRowIndex++;
var subVisible = visible && isRowExpanded;
if (expandedRowContent && isRowExpanded) {
rst.push(this.getExpandedRow(key, expandedRowContent, subVisible, expandedRowClassName(record, i, indent), fixed, record, index));
}
if (childrenColumn) {
this.isTreeType = true; //增加该标志位,为了兼容老版本,不修改以前的 `this.treeType` 的相关逻辑
this.treeType = true; //证明是tree表形式visible = {true}
rst = rst.concat(this.getRowsByData(childrenColumn, subVisible, indent + 1, columns, fixed, paramRootIndex));
}
}
if (props.lazyLoad && props.lazyLoad.sufHeight && indent == 0) {
//console.log("AAA--->lazyLoad---last-->"+props.lazyLoad.sufHeight);
rst.push(_react2["default"].createElement(_TableRow2["default"], { onPaste: onPaste //containerWidth={this.contentDomWidth} isSuf //滚动loading相关的暂时不用
, height: props.lazyLoad.sufHeight, key: 'table_lazyload_row_end', columns: [], className: 'table_lazyload_row_end', store: this.store, visible: true }));
}
if (!this.isTreeType) {
this.treeType = false;
}
return rst;
};
Table.prototype.getRows = function getRows(columns, fixed) {
//统计index,只有含有树表结构才有用,因为树表结构时,固定列的索引取值有问题
this.treeRowIndex = 0;
//每次遍历 data 前,将this.isTreeType置为 false,若遍历完 data,此变量仍为 false,说明是普通表格
this.isTreeType = false;
this.treeType = false;
var rs = this.getRowsByData(this.state.data, true, 0, columns, fixed);
return rs;
};
Table.prototype.getColGroup = function getColGroup(columns, fixed) {
var cols = [];
var self = this;
var _state = this.state,
_state$contentWidthDi = _state.contentWidthDiff,
contentWidthDiff = _state$contentWidthDi === undefined ? 0 : _state$contentWidthDi,
_state$lastShowIndex = _state.lastShowIndex,
lastShowIndex = _state$lastShowIndex === undefined ? -1 : _state$lastShowIndex;
var expandIconAsCell = this.props.expandIconAsCell;
var hasLeftFixed = this.columnManager.isAnyColumnsLeftFixed();
if (expandIconAsCell && hasLeftFixed && fixed == 'left' || expandIconAsCell && !hasLeftFixed && !fixed) {
cols.push(_react2["default"].createElement('col', {
style: { minWidth: expandIconCellWidth, width: expandIconCellWidth },
className: this.props.clsPrefix + '-expand-icon-col',
key: prefix + '-table-expand-icon-col'
}));
}
var leafColumns = void 0;
if (fixed === 'left') {
contentWidthDiff = 0;
leafColumns = this.columnManager.leftLeafColumns();
} else if (fixed === 'right') {
contentWidthDiff = 0;
leafColumns = this.columnManager.rightLeafColumns();
} else {
leafColumns = this.columnManager.centerLeafColumns();
}
cols = cols.concat(leafColumns.map(function (c, i, arr) {
var fixedClass = '';
var width = c.width;
if (typeof width == 'string' && width.indexOf('%') > -1 && self.contentWidth) {
width = Math.floor((self.contentWidth - self.scrollbarWidth) * parseInt(width) / 100); //向下取整,解决宽度2518px时10列每列10%(四舍五入时252px)的情况下,合计2520px导致出现滚动条的问题
} else if (width) {
width = parseInt(width);
}
//中间区域非固定的最后一列自动补充宽度
if (!fixed && lastShowIndex == i && width) {
width = width + (contentWidthDiff < 0 ? 0 : contentWidthDiff);
}
// if (!fixed && c.fixed) {//之前中间区域会渲染固定列dom单不让显示,现在直接不渲染dom了,所以需要了
// fixedClass = ` ${this.props.clsPrefix}-row-fixed-columns-in-body`;
// }
return _react2["default"].createElement('col', { key: c.key || c.dataIndex, style: { width: width, minWidth: c.width }, className: fixedClass || null });
}));
return _react2["default"].createElement(
'colgroup',
{ className: prefix + '-table-colgroup' },
cols
);
};
// renderDragHideTable = () => {
// const { columns,clsPrefix, dragborder, dragborderKey } = this.props;
// if (!dragborder) return null;
// let sum = 0;
// return (<div id={`u-table-drag-hide-table-${dragborderKey}`} className={`${clsPrefix}-hiden-drag`} >
// {
// columns.map((da, i) => {
// sum += da.width ? parseInt(da.width) : 0;
// return (<div className={`${clsPrefix}-hiden-drag-li`} key={da + "_hiden_" + i} style={{ left: sum + "px" }}></div>);
// })
// }
// </div>);
// }
Table.prototype.getLeftFixedTable = function getLeftFixedTable() {
return this.getTable({
columns: this.columnManager.leftColumns(),
fixed: 'left'
});
};
Table.prototype.getRightFixedTable = function getRightFixedTable() {
return this.getTable({
columns: this.columnManager.rightColumns(),
fixed: 'right'
});
};
Table.prototype.getTable = function getTable() {
var _this4 = this;
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var columns = options.columns,
fixed = options.fixed;
var _props6 = this.props,
clsPrefix = _pr