bee-table7/build/TableHeader.js

651 lines
25 KiB
JavaScript
Raw Normal View History

"use strict";
2017-01-12 08:53:51 +08:00
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");
2017-01-12 08:53:51 +08:00
var _react2 = _interopRequireDefault(_react);
2018-12-02 16:53:06 +08:00
var _reactDom = require("react-dom");
var _reactDom2 = _interopRequireDefault(_reactDom);
var _propTypes = require("prop-types");
var _propTypes2 = _interopRequireDefault(_propTypes);
var _shallowequal = require("shallowequal");
2017-01-12 08:53:51 +08:00
var _shallowequal2 = _interopRequireDefault(_shallowequal);
var _throttleDebounce = require("throttle-debounce");
var _utils = require("./utils");
2018-05-11 11:30:56 +08:00
var _FilterType = require("./FilterType");
var _FilterType2 = _interopRequireDefault(_FilterType);
2017-01-12 08:53:51 +08:00
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 _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 propTypes = {
clsPrefix: _propTypes2["default"].string,
rowStyle: _propTypes2["default"].object,
rows: _propTypes2["default"].array
2017-01-12 08:53:51 +08:00
};
var TableHeader = function (_Component) {
_inherits(TableHeader, _Component);
function TableHeader(props) {
_classCallCheck(this, TableHeader);
2018-05-11 09:29:43 +08:00
var _this = _possibleConstructorReturn(this, _Component.call(this, props));
2018-12-02 16:53:06 +08:00
_this.onLineMouseMove = function (e) {
var _this$props = _this.props,
clsPrefix = _this$props.clsPrefix,
dragborder = _this$props.dragborder,
contentDomWidth = _this$props.contentDomWidth,
scrollbarWidth = _this$props.scrollbarWidth,
contentTable = _this$props.contentTable,
headerScroll = _this$props.headerScroll;
_utils.Event.stopPropagation(e);
var event = _utils.Event.getEvent(e);
if (!_this.props.dragborder) return;
if (_this.drag.option != "border") {
return false;
}
//移动改变宽度
var currentCols = _this.table.cols[_this.drag.currIndex];
var diff = event.x - _this.drag.oldLeft;
var newWidth = _this.drag.oldWidth + diff;
2018-12-03 11:17:39 +08:00
// if(newWidth > this.drag.minWidth){
if (newWidth > _this.minWidth) {
2018-12-02 16:53:06 +08:00
currentCols.style.width = newWidth + 'px';
//hao 支持固定表头拖拽 修改表体的width
if (_this.fixedTable.cols) {
_this.fixedTable.cols[_this.drag.currIndex].style.width = newWidth + "px";
}
2018-05-11 11:30:56 +08:00
2018-12-02 16:53:06 +08:00
//表头滚动条处理
if (headerScroll) {
var oldTableWidth = parseInt(_this.table.table.style.width ? _this.table.table.style.width : _this.table.table.scrollWidth);
var newTableWidth = oldTableWidth + diff;
_this.table.table.style.width = newTableWidth; //改变table的width
var showScroll = contentDomWidth - newTableWidth - scrollbarWidth;
// if(bordered){
// showScroll = showScroll -1;
// }
var fixedLeftHeaderTable = contentTable.querySelector('.u-table-fixed-left .u-table-header');
var fixedRighHeadertTable = contentTable.querySelector('.u-table-fixed-right .u-table-header');
var contentTableHeader = contentTable.querySelector('.u-table-scroll .u-table-header');
if (showScroll < 0) {
//找到固定列表格设置表头的marginBottom值为scrollbarWidth;
contentTableHeader.style.overflowX = 'scroll';
fixedLeftHeaderTable && (fixedLeftHeaderTable.style.marginBottom = scrollbarWidth + "px");
fixedRighHeadertTable && (fixedRighHeadertTable.style.marginBottom = scrollbarWidth + "px");
} else {
contentTableHeader.style.overflowX = 'hidden';
fixedLeftHeaderTable && (fixedLeftHeaderTable.style.marginBottom = '0px');
fixedRighHeadertTable && (fixedRighHeadertTable.style.marginBottom = '0px');
}
}
2018-11-26 20:42:18 +08:00
}
2018-05-11 11:30:56 +08:00
};
2018-12-02 16:53:06 +08:00
_this.onLineMouseDown = function (e) {
_utils.Event.stopPropagation(e);
var event = _utils.Event.getEvent(e);
var _this$props2 = _this.props,
clsPrefix = _this$props2.clsPrefix,
contentTable = _this$props2.contentTable;
if (!_this.props.dragborder) return;
var currentIndex = parseInt(_utils.Event.getTarget(event).getAttribute("data-line-index"));
var defaultWidth = _utils.Event.getTarget(event).getAttribute("data-th-width");
var currentObj = _this.table.cols[currentIndex];
_this.drag.option = "border"; //拖拽操作
_this.drag.currIndex = currentIndex;
_this.drag.oldLeft = event.x;
_this.drag.oldWidth = parseInt(currentObj.style.width);
_this.drag.minWidth = currentObj.style.minWidth != "" ? parseInt(currentObj.style.minWidth) : defaultWidth;
};
2018-12-02 16:53:06 +08:00
_this.onLineMouseUp = function (event) {
2018-12-02 16:53:06 +08:00
_this.clearDragBorder(event);
};
2018-12-02 16:53:06 +08:00
_this.bodyonLineMouseMove = function (event) {
_this.clearDragBorder(event);
2018-05-11 11:30:56 +08:00
};
2018-12-02 16:53:06 +08:00
_this.dragAbleMouseDown = function (e) {
2018-12-05 13:17:11 +08:00
// Event.stopPropagation(e);
2018-12-02 16:53:06 +08:00
var event = _utils.Event.getEvent(e);
if (!_this.props.draggable) return;
2018-12-05 13:17:11 +08:00
var th = _this.getThDome(event.target);
if (!th) return;
2018-12-02 16:53:06 +08:00
event.target.setAttribute('draggable', true); //添加交换列效果
_this.drag.option = 'dragAble';
2018-12-04 16:25:22 +08:00
_this.currentDome = event.target;
_this.thEventListen([{ key: 'mouseup', fun: _this.dragAbleMouseUp }], '', true); //th
2018-12-02 16:53:06 +08:00
_this.removeDragBorderEvent(); //清理掉拖拽列宽的事件
_this.addDragAbleEvent(); //添加拖拽交换列的事件
2018-05-11 11:30:56 +08:00
};
2018-12-04 16:25:22 +08:00
_this.dragAbleMouseUp = function (e) {
_this.currentDome.setAttribute('draggable', false); //添加交换列效果
_this.removeDragAbleEvent();
_this.thEventListen([{ key: 'mouseup', fun: _this.dragAbleMouseUp }], 'remove', true); //th
//拖拽交换列事件
_this.thEventListen([{ key: 'mousedown', fun: _this.dragAbleMouseDown }], 'remove', true); //表示把事件添加到th元素上
_this.initEvent();
};
2018-12-02 16:53:06 +08:00
_this.onDragStart = function (e) {
var event = _utils.Event.getEvent(e);
if (!_this.props.draggable) return;
if (_this.drag.option === 'border') {
return;
2018-11-26 20:42:18 +08:00
}
2018-12-03 16:03:32 +08:00
var th = _this.getThDome(event.target);
if (!th) return;
var currentIndex = parseInt(th.getAttribute("data-line-index"));
2018-05-11 11:30:56 +08:00
2018-12-02 16:53:06 +08:00
var currentKey = event.target.getAttribute('data-line-key');
event.dataTransfer.effectAllowed = "move";
event.dataTransfer.setData("Text", currentKey);
_this.currentObj = _this.props.rows[0][currentIndex];
event.dataTransfer.setDragImage(event.target, 0, 0);
2018-05-14 10:01:06 +08:00
};
2018-12-02 16:53:06 +08:00
_this.onDragOver = function (e) {
event.preventDefault();
2018-05-14 10:01:06 +08:00
};
2018-12-02 16:53:06 +08:00
_this.onDrop = function (e) {
if (!_this.props.draggable) return;
if (_this.drag.option === 'border') {
return;
}
2018-12-04 16:25:22 +08:00
_this.currentDome.setAttribute('draggable', false); //添加交换列效果
2018-12-02 16:53:06 +08:00
var data = _this.getCurrentEventData(e);
2018-12-03 11:17:39 +08:00
if (!data) return;
2018-12-02 16:53:06 +08:00
if (!_this.currentObj || _this.currentObj.key == data.key) return;
if (!_this.props.onDrop) return;
_this.props.onDrop(event, { dragSource: _this.currentObj, dragTarg: data });
};
_this.handlerFilterChange = function (key, value, condition) {
var onFilterChange = _this.props.onFilterChange;
if (onFilterChange) {
onFilterChange(key, value, condition);
}
};
_this.handlerFilterClear = function (field) {
var onFilterClear = _this.props.onFilterClear;
if (onFilterClear) {
onFilterClear(field);
}
};
_this.filterRenderType = function (type, dataIndex, index) {
2018-12-02 16:53:06 +08:00
var _this$props3 = _this.props,
clsPrefix = _this$props3.clsPrefix,
rows = _this$props3.rows,
filterDelay = _this$props3.filterDelay,
locale = _this$props3.locale;
switch (type) {
//文本输入
case "text":
return _react2["default"].createElement(_FilterType2["default"], {
locale: locale //多语
, rendertype: type //渲染类型
, clsPrefix: clsPrefix //css前缀
, className: clsPrefix + " filter-text",
dataIndex: dataIndex //字段
, onFilterChange: _this.handlerFilterChange //输入框回调
, onFilterClear: _this.handlerFilterClear //清除回调
, filterDropdown: rows[1][index]["filterdropdown"] //是否显示下拉条件
, filterDropdownType: rows[1][index]["filterdropdowntype"] //下拉的条件类型为string,number
2018-11-26 20:42:18 +08:00
});
//数值输入
case "number":
return _react2["default"].createElement(_FilterType2["default"], {
locale: locale,
rendertype: type,
clsPrefix: clsPrefix,
className: clsPrefix + " filter-text",
dataIndex: dataIndex //字段
, onFilterChange: (0, _throttleDebounce.debounce)(filterDelay || 300, _this.handlerFilterChange) //输入框回调并且函数防抖动
, onFilterClear: _this.handlerFilterClear //清除回调
, filterDropdown: rows[1][index]["filterdropdown"],
2018-11-26 20:42:18 +08:00
filterDropdownType: rows[1][index]["filterdropdowntype"] //下拉的条件类型为string,number
});
//下拉框选择
case "dropdown":
var selectDataSource = [];
//处理没有输入数据源的时候,系统自动查找自带的数据筛选后注入
if (rows.length > 0 && (rows[1][index]["filterdropdownauto"] || "auto") == "auto") {
var hash = {};
//处理下拉重复对象组装dropdown
selectDataSource = Array.from(rows[1][0].datasource, function (x) {
return {
key: x[dataIndex],
value: x[dataIndex]
};
});
selectDataSource = selectDataSource.reduceRight(function (item, next) {
hash[next.key] ? "" : hash[next.key] = true && item.push(next);
return item;
}, []);
2018-10-11 22:53:27 +08:00
} else {
//从外部数据源加载系统数据
selectDataSource = rows[1][index]["filterdropdowndata"];
}
return _react2["default"].createElement(_FilterType2["default"], {
2018-11-01 14:35:46 +08:00
locale: locale,
rendertype: type,
className: clsPrefix + " filter-dropdown",
data: selectDataSource,
dataIndex: dataIndex //字段
, onFilterChange: _this.handlerFilterChange //输入框回调
, onFilterClear: _this.handlerFilterClear //清除回调
, filterDropdown: rows[1][index]["filterdropdown"],
2018-11-26 20:42:18 +08:00
onFocus: rows[1][index]["filterdropdownfocus"],
filterDropdownType: rows[1][index]["filterdropdowntype"] //下拉的条件类型为string,number
});
//日期
case "date":
return _react2["default"].createElement(_FilterType2["default"], {
2018-11-01 14:35:46 +08:00
locale: locale,
rendertype: type,
className: "filter-date",
onClick: function onClick() {},
format: rows[1][index]["format"] || "YYYY-MM-DD",
dataIndex: dataIndex //字段
, onFilterChange: _this.handlerFilterChange //输入框回调
, onFilterClear: _this.handlerFilterClear //清除回调
, filterDropdown: rows[1][index]["filterdropdown"],
2018-11-26 20:42:18 +08:00
filterDropdownType: rows[1][index]["filterdropdowntype"] //下拉的条件类型为string,number
});
2018-11-26 21:12:48 +08:00
//日期范围
case "daterange":
return _react2["default"].createElement(_FilterType2["default"], {
locale: locale,
rendertype: type,
className: "filter-date",
onClick: function onClick() {},
format: rows[1][index]["format"] || "YYYY-MM-DD",
dataIndex: dataIndex //字段
, onFilterChange: _this.handlerFilterChange //输入框回调
, onFilterClear: _this.handlerFilterClear //清除回调
, filterDropdown: rows[1][index]["filterdropdown"],
2018-11-26 21:12:48 +08:00
filterDropdownType: rows[1][index]["filterdropdowntype"] //下拉的条件类型为string,number
});
default:
//不匹配类型默认文本输入
return _react2["default"].createElement("div", null);
}
2018-05-11 11:30:56 +08:00
};
2018-05-11 09:29:43 +08:00
_this.currentObj = null;
2018-05-14 10:01:06 +08:00
_this.theadKey = new Date().getTime();
2018-05-11 11:30:56 +08:00
_this.drag = {
2018-12-02 16:53:06 +08:00
option: ''
};
2018-12-03 11:17:39 +08:00
_this.minWidth = 80; //确定最小宽度就是80
2018-12-02 16:53:06 +08:00
_this.table = null;
2018-05-11 09:29:43 +08:00
return _this;
2017-01-12 08:53:51 +08:00
}
2018-12-02 16:53:06 +08:00
/**
* 动态绑定th line 事件
* type 为false 为增加事件
* eventSource 为false th 内部的div增加事件
*/
TableHeader.prototype.thEventListen = function thEventListen(events, type, eventSource) {
var _table = this.table,
ths = _table.ths,
cols = _table.cols;
for (var index = 0; index < ths.length; index++) {
var element = ths[index]; //.getAttribute('data-type');
if (!element.getAttribute('data-th-fixed')) {
2018-12-03 16:03:32 +08:00
var colLine = null;
if (element.children.length === 0) {
colLine = element;
} else if (element.children.length > 0) {
colLine = element.lastElementChild;
} else if (element.children.length === 1) {
colLine = element.children[0];
}
// const colLine = element.children.length > 1?element.lastElementChild:element.children[0];
2018-12-02 16:53:06 +08:00
for (var i = 0; i < events.length; i++) {
var _event = events[i];
var _dataSource = eventSource ? element : colLine;
if (type === "remove") {
2018-12-04 16:25:22 +08:00
_utils.EventUtil.removeHandler(_dataSource, _event.key, _event.fun);
2018-12-02 16:53:06 +08:00
} else {
2018-12-04 16:25:22 +08:00
_utils.EventUtil.addHandler(_dataSource, _event.key, _event.fun);
2018-12-02 16:53:06 +08:00
}
}
}
}
};
TableHeader.prototype.bodyEventListen = function bodyEventListen(events, type) {
for (var i = 0; i < events.length; i++) {
var _event = events[i];
if (type == "remove") {
2018-12-04 16:25:22 +08:00
_utils.EventUtil.removeHandler(document.body, _event.key, _event.fun);
2018-12-02 16:53:06 +08:00
} else {
2018-12-04 16:25:22 +08:00
_utils.EventUtil.addHandler(document.body, _event.key, _event.fun);
2018-12-02 16:53:06 +08:00
}
}
2018-12-02 16:53:06 +08:00
};
TableHeader.prototype.componentDidUpdate = function componentDidUpdate() {
this.initTable();
this.initEvent();
};
2018-12-02 16:53:06 +08:00
TableHeader.prototype.componentDidMount = function componentDidMount() {
this.initTable();
this.initEvent();
};
/**
* 拖拽列宽的事件处理
*/
2018-12-02 16:53:06 +08:00
TableHeader.prototype.initEvent = function initEvent() {
var events = [{ key: 'mouseup', fun: this.onLineMouseUp }, { key: 'mousemove', fun: this.onLineMouseMove }];
if (this.props.dragborder) {
this.thEventListen(events, '', true); //表示把事件添加到th元素上
this.thEventListen([{ key: 'mousedown', fun: this.onLineMouseDown }]); //表示把事件添加到竖线
this.bodyEventListen([{ key: 'mouseup', fun: this.bodyonLineMouseMove }]);
}
2018-12-02 16:53:06 +08:00
if (!this.props.draggable) return;
//拖拽交换列事件
2018-12-04 16:25:22 +08:00
this.thEventListen([{ key: 'mousedown', fun: this.dragAbleMouseDown }], '', true); //表示把事件添加到th元素上
2017-01-12 08:53:51 +08:00
};
2018-12-02 16:53:06 +08:00
/**
* 移除拖拽宽度的事件
*/
TableHeader.prototype.removeDragBorderEvent = function removeDragBorderEvent() {
var events = [{ key: 'mouseup', fun: this.onLineMouseUp }, { key: 'mousemove', fun: this.onLineMouseMove }];
this.thEventListen(events, 'remove', true); //表示把事件添加到th元素上
this.thEventListen([{ key: 'mousedown', fun: this.onLineMouseDown }], 'remove'); //表示把事件添加到竖线
this.bodyEventListen([{ key: 'mouseup', fun: this.bodyonLineMouseMove }], 'remove');
};
2018-12-02 16:53:06 +08:00
/**
* 获取table的属性存放在this.table (公用方法)
*/
TableHeader.prototype.initTable = function initTable() {
if (!this.props.dragborder && !this.props.draggable) return;
var el = _reactDom2["default"].findDOMNode(this);
var tableDome = el.parentNode;
var table = {};
if (tableDome && tableDome.nodeName && tableDome.nodeName.toUpperCase() == "TABLE") {
table.table = tableDome;
table.cols = tableDome.getElementsByTagName("col");
table.ths = tableDome.getElementsByTagName("th");
}
this.table = table;
if (!this.props.dragborder) return;
if (document.getElementById("u-table-drag-thead-" + this.theadKey)) {
//hao 固定列table
this.fixedTable = {};
var _fixedParentContext = document.getElementById("u-table-drag-thead-" + this.theadKey).parentNode;
var siblingDom = _fixedParentContext.parentNode.nextElementSibling;
if (siblingDom) {
var fixedTable = siblingDom.querySelector("table");
this.fixedTable.table = fixedTable;
this.fixedTable.cols = fixedTable.getElementsByTagName("col");
// this.fixedTable.ths = fixedTable.tableDome.getElementsByTagName("th");
}
}
};
//---拖拽列宽代码逻辑----start-----
TableHeader.prototype.clearDragBorder = function clearDragBorder() {
// if (!this.props.dragborder || !this.props.draggable) return;
2018-12-05 12:39:29 +08:00
if (!this.drag || !this.drag.option) return;
var rows = this.props.rows;
var data = { rows: rows[0], cols: this.table.cols, currIndex: this.drag.currIndex };
this.props.afterDragColWidth && this.props.afterDragColWidth(data);
2018-12-02 16:53:06 +08:00
this.drag = {
option: ""
};
2018-12-04 16:25:22 +08:00
if (this.props.draggable) {
this.removeDragAbleEvent();
}
2018-12-02 16:53:06 +08:00
};
//---拖拽列宽代码逻辑----start-----
/**
* 拖拽交换列的事件处理
*/
TableHeader.prototype.addDragAbleEvent = function addDragAbleEvent() {
var events = [{ key: 'dragstart', fun: this.onDragStart }, //用户开始拖动元素时触发
{ key: 'dragover', fun: this.onDragOver }, //当某被拖动的对象在另一对象容器范围内拖动时触发此事件
{ key: 'drop', fun: this.onDrop }];
2018-12-02 16:53:06 +08:00
this.thEventListen(events, '', true);
// this.bodyEventListen([{key:'mouseup',fun:this.bodyonDragMouseMove}]);
};
TableHeader.prototype.removeDragAbleEvent = function removeDragAbleEvent() {
var events = [{ key: 'dragstart', fun: this.onDragStart }, { key: 'dragover', fun: this.onDragOver }, { key: 'drop', fun: this.onDrop }, { key: 'dragenter', fun: this.onDragEnter }];
this.thEventListen(events, 'remove', true);
};
/**
* 当被鼠标拖动的对象进入其容器范围内时触发此事件目标事件
* @memberof TableHeader
*/
// onDragEnter = (e) => {
// if (!this.props.draggable) return;
// if(this.drag.option === 'border'){return;}
// let data = this.getCurrentEventData(e);
// if (!this.currentObj || this.currentObj.key == data.key) return;
2018-12-03 16:55:10 +08:00
// };
2018-12-02 16:53:06 +08:00
/**
* 在一个拖动过程中释放鼠标键时触发此事件目标事件
* @memberof TableHeader
*/
TableHeader.prototype.getCurrentEventData = function getCurrentEventData(e) {
var event = _utils.Event.getEvent(e);
2018-12-03 16:03:32 +08:00
var th = this.getThDome(event.target);
if (!th) {
console.log(" event target is not th ! ");
return null;
}
var key = th.getAttribute('data-line-key');
2018-12-02 16:53:06 +08:00
var data = this.props.rows[0].find(function (da) {
return da.key == key;
});
if (data) {
return data;
} else {
console.log(" getCurrentEventData data is null ");
return null;
}
};
2018-12-03 16:03:32 +08:00
/**
*根据拖拽获取当前的Th属性
* @param {*} element
* @returns
* @memberof TableHeader
*/
TableHeader.prototype.getThDome = function getThDome(element) {
var _tagName = element.tagName.toLowerCase();
2018-12-05 13:17:11 +08:00
if (element.getAttribute('data-filter-type') === 'filterContext') return null;
2018-12-03 16:03:32 +08:00
if (_tagName === 'i') return null;
if (_tagName != 'th') {
return this.getThDome(element.parentElement);
} else {
return element;
}
};
2018-12-02 16:53:06 +08:00
//---拖拽列交换----end-----
2018-12-03 16:03:32 +08:00
/**
* 过滤输入后或下拉条件的回调函数
*/
/**
* 过滤行清除回调
*/
/**
* 过滤渲染的组件类型
*/
2017-01-12 08:53:51 +08:00
TableHeader.prototype.render = function render() {
2018-11-21 22:38:32 +08:00
var _this2 = this;
2018-05-11 09:29:43 +08:00
2017-01-12 08:53:51 +08:00
var _props = this.props,
clsPrefix = _props.clsPrefix,
rowStyle = _props.rowStyle,
2018-05-11 09:29:43 +08:00
onDragStart = _props.onDragStart,
onDragOver = _props.onDragOver,
onDrop = _props.onDrop,
draggable = _props.draggable,
dragborder = _props.dragborder,
2018-05-11 09:29:43 +08:00
rows = _props.rows,
filterable = _props.filterable,
onFilterRowsChange = _props.onFilterRowsChange,
2018-05-11 09:29:43 +08:00
onMouseDown = _props.onMouseDown,
onMouseMove = _props.onMouseMove,
onMouseUp = _props.onMouseUp,
onMouseOut = _props.onMouseOut,
contentWidthDiff = _props.contentWidthDiff,
2018-09-13 10:28:28 +08:00
fixed = _props.fixed,
2018-11-21 22:38:32 +08:00
lastShowIndex = _props.lastShowIndex,
contentTable = _props.contentTable;
2017-01-12 08:53:51 +08:00
var attr = dragborder ? { id: "u-table-drag-thead-" + this.theadKey } : {};
2017-01-12 08:53:51 +08:00
return _react2["default"].createElement(
"thead",
2018-12-02 16:53:06 +08:00
_extends({ className: clsPrefix + "-thead" }, attr, { "data-theader-fixed": "scroll" }),
2017-01-12 08:53:51 +08:00
rows.map(function (row, index) {
return _react2["default"].createElement(
"tr",
{ key: index, style: rowStyle, className: filterable && index == rows.length - 1 ? 'filterable' : '' },
2018-12-02 16:53:06 +08:00
row.map(function (da, columIndex, arr) {
var thHover = da.drgHover ? " " + clsPrefix + "-thead th-drag-hover" : "";
delete da.drgHover;
var fixedStyle = "";
var canDotDrag = "";
2018-12-06 21:03:05 +08:00
//主表格下、固定列或者是过滤行中含有固定列时添加该属性
if (!fixed && (da.fixed || filterable && index == rows.length - 1 && rows[0][columIndex].fixed)) {
fixedStyle = clsPrefix + "-row-fixed-columns-in-body";
}
2018-11-27 15:23:03 +08:00
2018-12-02 16:53:06 +08:00
if (lastShowIndex == columIndex) {
canDotDrag = "th-can-not-drag";
}
2018-10-11 14:12:19 +08:00
if (filterable && index == rows.length - 1) {
2018-12-02 16:53:06 +08:00
da.children = _this2.filterRenderType(da["filtertype"], da.dataindex, columIndex);
delete da.filterdropdownfocus;
2018-10-11 14:12:19 +08:00
}
2018-12-02 16:53:06 +08:00
var thDefaultObj = {};
var thClassName = "" + da.className ? "" + da.className : '';
2018-12-02 16:53:06 +08:00
if (draggable) {
thClassName += clsPrefix + "-thead th-drag " + thHover + " ";
}
if (dragborder) {
thClassName += clsPrefix + "-thead-th " + canDotDrag;
}
thClassName += " " + fixedStyle;
2018-12-02 16:53:06 +08:00
if (!da.fixed) {
return _react2["default"].createElement(
"th",
2018-12-06 21:03:05 +08:00
_extends({}, da, { key: 'table-header-th-' + da.dataindex, className: thClassName, "data-th-fixed": da.fixed,
"data-line-key": da.key, "data-line-index": columIndex, "data-th-width": da.width }),
da.children,
2018-12-02 16:53:06 +08:00
dragborder ? _react2["default"].createElement(
2018-11-26 20:42:18 +08:00
"div",
2018-12-02 16:53:06 +08:00
{ ref: function ref(el) {
2018-11-26 20:42:18 +08:00
return _this2.gap = el;
2018-12-02 16:53:06 +08:00
}, "data-line-key": da.key,
"data-line-index": columIndex, "data-th-width": da.width,
"data-type": "online", className: clsPrefix + "-thead-th-drag-gap" },
_react2["default"].createElement("div", { id: "th-online", className: "online", "data-line-key": da.key, "data-line-index": columIndex, "data-th-width": da.width })
) : ""
2018-05-11 11:30:56 +08:00
);
2018-05-11 09:29:43 +08:00
} else {
thDefaultObj = _extends({}, da, {
className: da.className + " " + fixedStyle,
2018-12-02 16:53:06 +08:00
key: columIndex
});
da.onClick ? thDefaultObj.onClick = function (e) {
da.onClick(da, e);
} : "";
2018-12-02 16:53:06 +08:00
return _react2["default"].createElement("th", _extends({}, thDefaultObj, { "data-th-fixed": da.fixed }));
2018-05-11 09:29:43 +08:00
}
2017-01-12 08:53:51 +08:00
})
);
})
);
};
return TableHeader;
}(_react.Component);
TableHeader.defaultProps = {
contentWidthDiff: 0
};
2017-01-12 08:53:51 +08:00
TableHeader.propTypes = propTypes;
exports["default"] = TableHeader;
module.exports = exports["default"];