rc-table
Version:
table ui component for react
1,428 lines (1,222 loc) • 143 kB
JavaScript
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory(require("react"), require("react-dom"));
else if(typeof define === 'function' && define.amd)
define(["react", "react-dom"], factory);
else if(typeof exports === 'object')
exports["rc-table"] = factory(require("react"), require("react-dom"));
else
root["rc-table"] = factory(root["React"], root["ReactDOM"]);
})(this, function(__WEBPACK_EXTERNAL_MODULE_6__, __WEBPACK_EXTERNAL_MODULE_25__) {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ((function(modules) {
// Check all modules for deduplicated modules
for(var i in modules) {
if(Object.prototype.hasOwnProperty.call(modules, i)) {
switch(typeof modules[i]) {
case "function": break;
case "object":
// Module can be created from a template
modules[i] = (function(_m) {
var args = _m.slice(1), fn = modules[_m[0]];
return function (a,b,c) {
fn.apply(this, [a,b,c].concat(args));
};
}(modules[i]));
break;
default:
// Module is a copy of another module
modules[i] = modules[modules[i]];
break;
}
}
}
return modules;
}([
/* 0 */
/***/ function(module, exports, __webpack_require__) {
__webpack_require__(1);
__webpack_require__(2);
__webpack_require__(3);
module.exports = __webpack_require__(4);
/***/ },
/* 1 */
/***/ function(module, exports) {
// removed by extract-text-webpack-plugin
/***/ },
/* 2 */
1,
/* 3 */
1,
/* 4 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
var Table = __webpack_require__(5);
var Column = __webpack_require__(30);
var ColumnGroup = __webpack_require__(31);
Table.Column = Column;
Table.ColumnGroup = ColumnGroup;
module.exports = Table;
/***/ },
/* 5 */
/***/ function(module, exports, __webpack_require__) {
'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 = __webpack_require__(6);
var _react2 = _interopRequireDefault(_react);
var _TableRow = __webpack_require__(7);
var _TableRow2 = _interopRequireDefault(_TableRow);
var _TableHeader = __webpack_require__(16);
var _TableHeader2 = _interopRequireDefault(_TableHeader);
var _utils = __webpack_require__(17);
var _shallowequal = __webpack_require__(11);
var _shallowequal2 = _interopRequireDefault(_shallowequal);
var _addEventListener = __webpack_require__(20);
var _addEventListener2 = _interopRequireDefault(_addEventListener);
var _ColumnManager = __webpack_require__(26);
var _ColumnManager2 = _interopRequireDefault(_ColumnManager);
var _createStore = __webpack_require__(27);
var _createStore2 = _interopRequireDefault(_createStore);
var _componentClasses = __webpack_require__(28);
var _componentClasses2 = _interopRequireDefault(_componentClasses);
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 Table = function (_React$Component) {
_inherits(Table, _React$Component);
function Table(props) {
_classCallCheck(this, Table);
var _this = _possibleConstructorReturn(this, _React$Component.call(this, props));
_this.onExpanded = function (expanded, record, e, index) {
if (e) {
e.preventDefault();
e.stopPropagation();
}
var info = _this.findExpandedRow(record);
if (typeof info !== 'undefined' && !expanded) {
_this.onRowDestroy(record, index);
} else if (!info && expanded) {
var expandedRows = _this.getExpandedRows().concat();
expandedRows.push(_this.getRowKey(record, index));
_this.onExpandedRowsChange(expandedRows);
}
_this.props.onExpand(expanded, record);
};
_this.onRowDestroy = function (record, rowIndex) {
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);
}
_this.onExpandedRowsChange(expandedRows);
};
_this.handleWindowResize = function () {
_this.syncFixedTableRowHeight();
_this.setScrollPositionClassName();
};
_this.syncFixedTableRowHeight = function () {
var tableRect = _this.tableNode.getBoundingClientRect();
// If tableNode's height less than 0, suppose it is hidden and don't recalculate rowHeight.
// see: https://github.com/ant-design/ant-design/issues/4836
if (tableRect.height !== undefined && tableRect.height <= 0) {
return;
}
var prefixCls = _this.props.prefixCls;
var headRows = _this.refs.headTable ? _this.refs.headTable.querySelectorAll('thead') : _this.refs.bodyTable.querySelectorAll('thead');
var bodyRows = _this.refs.bodyTable.querySelectorAll('.' + prefixCls + '-row') || [];
var fixedColumnsHeadRowsHeight = [].map.call(headRows, function (row) {
return row.getBoundingClientRect().height || 'auto';
});
var fixedColumnsBodyRowsHeight = [].map.call(bodyRows, function (row) {
return row.getBoundingClientRect().height || 'auto';
});
if ((0, _shallowequal2.default)(_this.state.fixedColumnsHeadRowsHeight, fixedColumnsHeadRowsHeight) && (0, _shallowequal2.default)(_this.state.fixedColumnsBodyRowsHeight, fixedColumnsBodyRowsHeight)) {
return;
}
_this.setState({
fixedColumnsHeadRowsHeight: fixedColumnsHeadRowsHeight,
fixedColumnsBodyRowsHeight: fixedColumnsBodyRowsHeight
});
};
_this.detectScrollTarget = function (e) {
if (_this.scrollTarget !== e.currentTarget) {
_this.scrollTarget = e.currentTarget;
}
};
_this.handleBodyScroll = function (e) {
// Prevent scrollTop setter trigger onScroll event
// http://stackoverflow.com/q/1386696
if (e.target !== _this.scrollTarget) {
return;
}
var _this$props$scroll = _this.props.scroll,
scroll = _this$props$scroll === undefined ? {} : _this$props$scroll;
var _this$refs = _this.refs,
headTable = _this$refs.headTable,
bodyTable = _this$refs.bodyTable,
fixedColumnsBodyLeft = _this$refs.fixedColumnsBodyLeft,
fixedColumnsBodyRight = _this$refs.fixedColumnsBodyRight;
if (scroll.x && e.target.scrollLeft !== _this.lastScrollLeft) {
if (e.target === bodyTable && headTable) {
headTable.scrollLeft = e.target.scrollLeft;
} else if (e.target === headTable && bodyTable) {
bodyTable.scrollLeft = e.target.scrollLeft;
}
_this.setScrollPositionClassName(e.target);
}
if (scroll.y) {
if (fixedColumnsBodyLeft && e.target !== fixedColumnsBodyLeft) {
fixedColumnsBodyLeft.scrollTop = e.target.scrollTop;
}
if (fixedColumnsBodyRight && e.target !== fixedColumnsBodyRight) {
fixedColumnsBodyRight.scrollTop = e.target.scrollTop;
}
if (bodyTable && e.target !== bodyTable) {
bodyTable.scrollTop = e.target.scrollTop;
}
}
// Remember last scrollLeft for scroll direction detecting.
_this.lastScrollLeft = e.target.scrollLeft;
};
_this.handleRowHover = function (isHover, key) {
_this.store.setState({
currentHoverKey: isHover ? key : null
});
};
var expandedRowKeys = [];
var rows = [].concat(_toConsumableArray(props.data));
_this.columnManager = new _ColumnManager2.default(props.columns, props.children);
_this.store = (0, _createStore2.default)({
currentHoverKey: null,
expandedRowsHeight: {}
});
_this.setScrollPosition('left');
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,
currentHoverKey: null,
fixedColumnsHeadRowsHeight: [],
fixedColumnsBodyRowsHeight: []
};
return _this;
}
Table.prototype.componentDidMount = function componentDidMount() {
if (this.columnManager.isAnyColumnsFixed()) {
this.handleWindowResize();
this.debouncedWindowResize = (0, _utils.debounce)(this.handleWindowResize, 150);
this.resizeEvent = (0, _addEventListener2.default)(window, 'resize', this.debouncedWindowResize);
}
};
Table.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
if ('expandedRowKeys' in nextProps) {
this.setState({
expandedRowKeys: nextProps.expandedRowKeys
});
}
if (nextProps.columns && nextProps.columns !== this.props.columns) {
this.columnManager.reset(nextProps.columns);
} else if (nextProps.children !== this.props.children) {
this.columnManager.reset(null, nextProps.children);
}
};
Table.prototype.componentDidUpdate = function componentDidUpdate(prevProps) {
if (this.columnManager.isAnyColumnsFixed()) {
this.handleWindowResize();
}
// when table changes to empty, reset scrollLeft
if (prevProps.data.length > 0 && this.props.data.length === 0 && this.hasScrollX()) {
this.resetScrollX();
}
};
Table.prototype.componentWillUnmount = function componentWillUnmount() {
if (this.resizeEvent) {
this.resizeEvent.remove();
}
if (this.debouncedWindowResize) {
this.debouncedWindowResize.cancel();
}
};
Table.prototype.onExpandedRowsChange = function onExpandedRowsChange(expandedRowKeys) {
if (!this.props.expandedRowKeys) {
this.setState({ expandedRowKeys: expandedRowKeys });
}
this.props.onExpandedRowsChange(expandedRowKeys);
};
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 === undefined ? index : key;
};
Table.prototype.getExpandedRows = function getExpandedRows() {
return this.props.expandedRowKeys || this.state.expandedRowKeys;
};
Table.prototype.getHeader = function getHeader(columns, fixed) {
var _props = this.props,
showHeader = _props.showHeader,
expandIconAsCell = _props.expandIconAsCell,
prefixCls = _props.prefixCls;
var rows = this.getHeaderRows(columns);
if (expandIconAsCell && fixed !== 'right') {
rows[0].unshift({
key: 'rc-table-expandIconAsCell',
className: prefixCls + '-expand-icon-th',
title: '',
rowSpan: rows.length
});
}
var trStyle = fixed ? this.getHeaderRowStyle(columns, rows) : null;
return showHeader ? _react2.default.createElement(_TableHeader2.default, {
prefixCls: prefixCls,
rows: rows,
rowStyle: trStyle
}) : null;
};
Table.prototype.getHeaderRows = function getHeaderRows(columns) {
var _this2 = this;
var currentRow = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
var rows = arguments[2];
rows = rows || [];
rows[currentRow] = rows[currentRow] || [];
columns.forEach(function (column) {
if (column.rowSpan && rows.length < column.rowSpan) {
while (rows.length < column.rowSpan) {
rows.push([]);
}
}
var cell = {
key: column.key,
className: column.className || '',
children: column.title
};
if (column.children) {
_this2.getHeaderRows(column.children, currentRow + 1, rows);
}
if ('colSpan' in column) {
cell.colSpan = column.colSpan;
}
if ('rowSpan' in column) {
cell.rowSpan = column.rowSpan;
}
if (cell.colSpan !== 0) {
rows[currentRow].push(cell);
}
});
return rows.filter(function (row) {
return row.length > 0;
});
};
Table.prototype.getExpandedRow = function getExpandedRow(key, content, visible, className, fixed) {
var _props2 = this.props,
prefixCls = _props2.prefixCls,
expandIconAsCell = _props2.expandIconAsCell;
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.leafColumns().length;
}
var columns = [{
key: 'extra-row',
render: function render() {
return {
props: {
colSpan: colCount
},
children: fixed !== 'right' ? content : ' '
};
}
}];
if (expandIconAsCell && fixed !== 'right') {
columns.unshift({
key: 'expand-icon-placeholder',
render: function render() {
return null;
}
});
}
return _react2.default.createElement(_TableRow2.default, {
columns: columns,
visible: visible,
className: className,
key: key + '-extra-row',
rowKey: key + '-extra-row',
prefixCls: prefixCls + '-expanded-row',
indent: 1,
expandable: false,
store: this.store,
expandedRow: true,
fixed: !!fixed
});
};
Table.prototype.getRowsByData = function getRowsByData(data, visible, indent, columns, fixed) {
var props = this.props;
var childrenColumnName = props.childrenColumnName;
var expandedRowRender = props.expandedRowRender;
var expandRowByClick = props.expandRowByClick;
var fixedColumnsBodyRowsHeight = this.state.fixedColumnsBodyRowsHeight;
var rst = [];
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;
var expandIconAsCell = fixed !== 'right' ? props.expandIconAsCell : false;
var expandIconColumnIndex = fixed !== 'right' ? props.expandIconColumnIndex : -1;
for (var i = 0; i < data.length; i++) {
var record = data[i];
var key = this.getRowKey(record, i);
var childrenColumn = record[childrenColumnName];
var isRowExpanded = this.isRowExpanded(record, i);
var expandedRowContent = void 0;
if (expandedRowRender && isRowExpanded) {
expandedRowContent = expandedRowRender(record, i, indent);
}
var className = rowClassName(record, i, indent);
var onHoverProps = {};
if (this.columnManager.isAnyColumnsFixed()) {
onHoverProps.onHover = this.handleRowHover;
}
var height = fixed && fixedColumnsBodyRowsHeight[i] ? fixedColumnsBodyRowsHeight[i] : null;
var leafColumns = void 0;
if (fixed === 'left') {
leafColumns = this.columnManager.leftLeafColumns();
} else if (fixed === 'right') {
leafColumns = this.columnManager.rightLeafColumns();
} else {
leafColumns = this.columnManager.leafColumns();
}
rst.push(_react2.default.createElement(_TableRow2.default, _extends({
indent: indent,
indentSize: props.indentSize,
needIndentSpaced: needIndentSpaced,
className: className,
record: record,
expandIconAsCell: expandIconAsCell,
onDestroy: this.onRowDestroy,
index: i,
visible: visible,
expandRowByClick: expandRowByClick,
onExpand: this.onExpanded,
expandable: childrenColumn || expandedRowRender,
expanded: isRowExpanded,
prefixCls: props.prefixCls + '-row',
childrenColumnName: childrenColumnName,
columns: leafColumns,
expandIconColumnIndex: expandIconColumnIndex,
onRowClick: onRowClick,
onRowDoubleClick: onRowDoubleClick,
height: height
}, onHoverProps, {
key: key,
hoverKey: key,
ref: rowRef(record, i, indent),
store: this.store
})));
var subVisible = visible && isRowExpanded;
if (expandedRowContent && isRowExpanded) {
rst.push(this.getExpandedRow(key, expandedRowContent, subVisible, expandedRowClassName(record, i, indent), fixed));
}
if (childrenColumn) {
rst = rst.concat(this.getRowsByData(childrenColumn, subVisible, indent + 1, columns, fixed));
}
}
return rst;
};
Table.prototype.getRows = function getRows(columns, fixed) {
return this.getRowsByData(this.props.data, true, 0, columns, fixed);
};
Table.prototype.getColGroup = function getColGroup(columns, fixed) {
var cols = [];
if (this.props.expandIconAsCell && fixed !== 'right') {
cols.push(_react2.default.createElement('col', {
className: this.props.prefixCls + '-expand-icon-col',
key: 'rc-table-expand-icon-col'
}));
}
var leafColumns = void 0;
if (fixed === 'left') {
leafColumns = this.columnManager.leftLeafColumns();
} else if (fixed === 'right') {
leafColumns = this.columnManager.rightLeafColumns();
} else {
leafColumns = this.columnManager.leafColumns();
}
cols = cols.concat(leafColumns.map(function (c) {
return _react2.default.createElement('col', { key: c.key, style: { width: c.width, minWidth: c.width } });
}));
return _react2.default.createElement(
'colgroup',
null,
cols
);
};
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 _this3 = this;
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var columns = options.columns,
fixed = options.fixed;
var _props3 = this.props,
prefixCls = _props3.prefixCls,
_props3$scroll = _props3.scroll,
scroll = _props3$scroll === undefined ? {} : _props3$scroll,
getBodyWrapper = _props3.getBodyWrapper;
var useFixedHeader = this.props.useFixedHeader;
var bodyStyle = _extends({}, this.props.bodyStyle);
var headStyle = {};
var tableClassName = '';
if (scroll.x || fixed) {
tableClassName = prefixCls + '-fixed';
bodyStyle.overflowX = bodyStyle.overflowX || 'auto';
}
var innerBodyStyle = {};
if (scroll.y) {
// maxHeight will make fixed-Table scrolling not working
// so we only set maxHeight to body-Table here
if (fixed) {
innerBodyStyle.maxHeight = bodyStyle.maxHeight || scroll.y;
innerBodyStyle.overflowY = bodyStyle.overflowY || 'scroll';
} else {
bodyStyle.maxHeight = bodyStyle.maxHeight || scroll.y;
}
bodyStyle.overflowY = bodyStyle.overflowY || 'scroll';
useFixedHeader = true;
// Add negative margin bottom for scroll bar overflow bug
var scrollbarWidth = (0, _utils.measureScrollbar)();
if (scrollbarWidth > 0) {
(fixed ? bodyStyle : headStyle).marginBottom = '-' + scrollbarWidth + 'px';
(fixed ? bodyStyle : headStyle).paddingBottom = '0px';
}
}
var renderTable = function renderTable() {
var hasHead = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
var hasBody = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
var tableStyle = {};
if (!fixed && scroll.x) {
// not set width, then use content fixed width
if (scroll.x === true) {
tableStyle.tableLayout = 'fixed';
} else {
tableStyle.width = scroll.x;
}
}
var tableBody = hasBody ? getBodyWrapper(_react2.default.createElement(
'tbody',
{ className: prefixCls + '-tbody' },
_this3.getRows(columns, fixed)
)) : null;
return _react2.default.createElement(
'table',
{ className: tableClassName, style: tableStyle, key: 'table' },
_this3.getColGroup(columns, fixed),
hasHead ? _this3.getHeader(columns, fixed) : null,
tableBody
);
};
var headTable = void 0;
if (useFixedHeader) {
headTable = _react2.default.createElement(
'div',
{
key: 'headTable',
className: prefixCls + '-header',
ref: fixed ? null : 'headTable',
style: headStyle,
onMouseOver: this.detectScrollTarget,
onTouchStart: this.detectScrollTarget,
onScroll: this.handleBodyScroll
},
renderTable(true, false)
);
}
var bodyTable = _react2.default.createElement(
'div',
{
key: 'bodyTable',
className: prefixCls + '-body',
style: bodyStyle,
ref: 'bodyTable',
onMouseOver: this.detectScrollTarget,
onTouchStart: this.detectScrollTarget,
onScroll: this.handleBodyScroll
},
renderTable(!useFixedHeader)
);
if (fixed && columns.length) {
var refName = void 0;
if (columns[0].fixed === 'left' || columns[0].fixed === true) {
refName = 'fixedColumnsBodyLeft';
} else if (columns[0].fixed === 'right') {
refName = 'fixedColumnsBodyRight';
}
delete bodyStyle.overflowX;
delete bodyStyle.overflowY;
bodyTable = _react2.default.createElement(
'div',
{
key: 'bodyTable',
className: prefixCls + '-body-outer',
style: _extends({}, bodyStyle)
},
_react2.default.createElement(
'div',
{
className: prefixCls + '-body-inner',
style: innerBodyStyle,
ref: refName,
onMouseOver: this.detectScrollTarget,
onTouchStart: this.detectScrollTarget,
onScroll: this.handleBodyScroll
},
renderTable(!useFixedHeader)
)
);
}
return [headTable, bodyTable];
};
Table.prototype.getTitle = function getTitle() {
var _props4 = this.props,
title = _props4.title,
prefixCls = _props4.prefixCls;
return title ? _react2.default.createElement(
'div',
{ className: prefixCls + '-title', key: 'title' },
title(this.props.data)
) : null;
};
Table.prototype.getFooter = function getFooter() {
var _props5 = this.props,
footer = _props5.footer,
prefixCls = _props5.prefixCls;
return footer ? _react2.default.createElement(
'div',
{ className: prefixCls + '-footer', key: 'footer' },
footer(this.props.data)
) : null;
};
Table.prototype.getEmptyText = function getEmptyText() {
var _props6 = this.props,
emptyText = _props6.emptyText,
prefixCls = _props6.prefixCls,
data = _props6.data;
return !data.length ? _react2.default.createElement(
'div',
{ className: prefixCls + '-placeholder', key: 'emptyText' },
emptyText()
) : null;
};
Table.prototype.getHeaderRowStyle = function getHeaderRowStyle(columns, rows) {
var fixedColumnsHeadRowsHeight = this.state.fixedColumnsHeadRowsHeight;
var headerHeight = fixedColumnsHeadRowsHeight[0];
if (headerHeight && columns) {
if (headerHeight === 'auto') {
return { height: 'auto' };
}
return { height: headerHeight / rows.length };
}
return null;
};
Table.prototype.setScrollPosition = function setScrollPosition(position) {
this.scrollPosition = position;
if (this.tableNode) {
var prefixCls = this.props.prefixCls;
if (position === 'both') {
(0, _componentClasses2.default)(this.tableNode).remove(new RegExp('^' + prefixCls + '-scroll-position-.+$')).add(prefixCls + '-scroll-position-left').add(prefixCls + '-scroll-position-right');
} else {
(0, _componentClasses2.default)(this.tableNode).remove(new RegExp('^' + prefixCls + '-scroll-position-.+$')).add(prefixCls + '-scroll-position-' + position);
}
}
};
Table.prototype.setScrollPositionClassName = function setScrollPositionClassName(target) {
var node = target || this.refs.bodyTable;
var scrollToLeft = node.scrollLeft === 0;
var scrollToRight = node.scrollLeft + 1 >= node.children[0].getBoundingClientRect().width - node.getBoundingClientRect().width;
if (scrollToLeft && scrollToRight) {
this.setScrollPosition('both');
} else if (scrollToLeft) {
this.setScrollPosition('left');
} else if (scrollToRight) {
this.setScrollPosition('right');
} else if (this.scrollPosition !== 'middle') {
this.setScrollPosition('middle');
}
};
Table.prototype.resetScrollX = function resetScrollX() {
if (this.refs.headTable) {
this.refs.headTable.scrollLeft = 0;
}
if (this.refs.bodyTable) {
this.refs.bodyTable.scrollLeft = 0;
}
};
Table.prototype.findExpandedRow = function findExpandedRow(record, index) {
var _this4 = this;
var rows = this.getExpandedRows().filter(function (i) {
return i === _this4.getRowKey(record, index);
});
return rows[0];
};
Table.prototype.isRowExpanded = function isRowExpanded(record, index) {
return typeof this.findExpandedRow(record, index) !== 'undefined';
};
Table.prototype.hasScrollX = function hasScrollX() {
var _props$scroll = this.props.scroll,
scroll = _props$scroll === undefined ? {} : _props$scroll;
return 'x' in scroll;
};
Table.prototype.render = function render() {
var _this5 = this;
var props = this.props;
var prefixCls = props.prefixCls;
var className = props.prefixCls;
if (props.className) {
className += ' ' + props.className;
}
if (props.useFixedHeader || props.scroll && props.scroll.y) {
className += ' ' + prefixCls + '-fixed-header';
}
if (this.scrollPosition === 'both') {
className += ' ' + prefixCls + '-scroll-position-left ' + prefixCls + '-scroll-position-right';
} else {
className += ' ' + prefixCls + '-scroll-position-' + this.scrollPosition;
}
var isTableScroll = this.columnManager.isAnyColumnsFixed() || props.scroll.x || props.scroll.y;
var content = [this.getTable({ columns: this.columnManager.groupedColumns() }), this.getEmptyText(), this.getFooter()];
var scrollTable = isTableScroll ? _react2.default.createElement(
'div',
{ className: prefixCls + '-scroll' },
content
) : content;
return _react2.default.createElement(
'div',
{ ref: function ref(node) {
return _this5.tableNode = node;
}, className: className, style: props.style },
this.getTitle(),
_react2.default.createElement(
'div',
{ className: prefixCls + '-content' },
scrollTable,
this.columnManager.isAnyColumnsLeftFixed() && _react2.default.createElement(
'div',
{ className: prefixCls + '-fixed-left' },
this.getLeftFixedTable()
),
this.columnManager.isAnyColumnsRightFixed() && _react2.default.createElement(
'div',
{ className: prefixCls + '-fixed-right' },
this.getRightFixedTable()
)
)
);
};
return Table;
}(_react2.default.Component);
Table.propTypes = {
data: _react.PropTypes.array,
expandIconAsCell: _react.PropTypes.bool,
defaultExpandAllRows: _react.PropTypes.bool,
expandedRowKeys: _react.PropTypes.array,
defaultExpandedRowKeys: _react.PropTypes.array,
useFixedHeader: _react.PropTypes.bool,
columns: _react.PropTypes.array,
prefixCls: _react.PropTypes.string,
bodyStyle: _react.PropTypes.object,
style: _react.PropTypes.object,
rowKey: _react.PropTypes.oneOfType([_react.PropTypes.string, _react.PropTypes.func]),
rowClassName: _react.PropTypes.func,
expandedRowClassName: _react.PropTypes.func,
childrenColumnName: _react.PropTypes.string,
onExpand: _react.PropTypes.func,
onExpandedRowsChange: _react.PropTypes.func,
indentSize: _react.PropTypes.number,
onRowClick: _react.PropTypes.func,
onRowDoubleClick: _react.PropTypes.func,
expandIconColumnIndex: _react.PropTypes.number,
showHeader: _react.PropTypes.bool,
title: _react.PropTypes.func,
footer: _react.PropTypes.func,
emptyText: _react.PropTypes.func,
scroll: _react.PropTypes.object,
rowRef: _react.PropTypes.func,
getBodyWrapper: _react.PropTypes.func,
children: _react.PropTypes.node
};
Table.defaultProps = {
data: [],
useFixedHeader: false,
expandIconAsCell: false,
defaultExpandAllRows: false,
defaultExpandedRowKeys: [],
rowKey: 'key',
rowClassName: function rowClassName() {
return '';
},
expandedRowClassName: function expandedRowClassName() {
return '';
},
onExpand: function onExpand() {},
onExpandedRowsChange: function onExpandedRowsChange() {},
onRowClick: function onRowClick() {},
onRowDoubleClick: function onRowDoubleClick() {},
prefixCls: 'rc-table',
bodyStyle: {},
style: {},
childrenColumnName: 'children',
indentSize: 15,
expandIconColumnIndex: 0,
showHeader: true,
scroll: {},
rowRef: function rowRef() {
return null;
},
getBodyWrapper: function getBodyWrapper(body) {
return body;
},
emptyText: function emptyText() {
return 'No Data';
}
};
exports.default = Table;
module.exports = exports['default'];
/***/ },
/* 6 */
/***/ function(module, exports) {
module.exports = __WEBPACK_EXTERNAL_MODULE_6__;
/***/ },
/* 7 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _react = __webpack_require__(6);
var _react2 = _interopRequireDefault(_react);
var _TableCell = __webpack_require__(8);
var _TableCell2 = _interopRequireDefault(_TableCell);
var _ExpandIcon = __webpack_require__(10);
var _ExpandIcon2 = _interopRequireDefault(_ExpandIcon);
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 TableRow = function (_React$Component) {
_inherits(TableRow, _React$Component);
function TableRow() {
var _temp, _this, _ret;
_classCallCheck(this, TableRow);
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _ret = (_temp = (_this = _possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.state = {
hovered: false,
height: null
}, _this.onRowClick = function (event) {
var _this$props = _this.props,
record = _this$props.record,
index = _this$props.index,
onRowClick = _this$props.onRowClick,
expandable = _this$props.expandable,
expandRowByClick = _this$props.expandRowByClick,
expanded = _this$props.expanded,
onExpand = _this$props.onExpand;
if (expandable && expandRowByClick) {
onExpand(!expanded, record, event, index);
}
onRowClick(record, index, event);
}, _this.onRowDoubleClick = function (event) {
var _this$props2 = _this.props,
record = _this$props2.record,
index = _this$props2.index,
onRowDoubleClick = _this$props2.onRowDoubleClick;
onRowDoubleClick(record, index, event);
}, _this.onMouseEnter = function () {
var _this$props3 = _this.props,
onHover = _this$props3.onHover,
hoverKey = _this$props3.hoverKey;
onHover(true, hoverKey);
}, _this.onMouseLeave = function () {
var _this$props4 = _this.props,
onHover = _this$props4.onHover,
hoverKey = _this$props4.hoverKey;
onHover(false, hoverKey);
}, _temp), _possibleConstructorReturn(_this, _ret);
}
TableRow.prototype.componentDidMount = function componentDidMount() {
var _this2 = this;
var store = this.props.store;
this.pushHeight();
this.pullHeight();
this.unsubscribe = store.subscribe(function () {
_this2.setHover();
_this2.pullHeight();
});
};
TableRow.prototype.componentWillUnmount = function componentWillUnmount() {
var _props = this.props,
record = _props.record,
onDestroy = _props.onDestroy,
index = _props.index;
onDestroy(record, index);
if (this.unsubscribe) {
this.unsubscribe();
}
};
TableRow.prototype.setHover = function setHover() {
var _props2 = this.props,
store = _props2.store,
hoverKey = _props2.hoverKey;
var _store$getState = store.getState(),
currentHoverKey = _store$getState.currentHoverKey;
if (currentHoverKey === hoverKey) {
this.setState({ hovered: true });
} else if (this.state.hovered === true) {
this.setState({ hovered: false });
}
};
TableRow.prototype.pullHeight = function pullHeight() {
var _props3 = this.props,
store = _props3.store,
expandedRow = _props3.expandedRow,
fixed = _props3.fixed,
rowKey = _props3.rowKey;
var _store$getState2 = store.getState(),
expandedRowsHeight = _store$getState2.expandedRowsHeight;
if (expandedRow && fixed && expandedRowsHeight[rowKey]) {
this.setState({ height: expandedRowsHeight[rowKey] });
}
};
TableRow.prototype.pushHeight = function pushHeight() {
var _props4 = this.props,
store = _props4.store,
expandedRow = _props4.expandedRow,
fixed = _props4.fixed,
rowKey = _props4.rowKey;
if (expandedRow && !fixed) {
var _store$getState3 = store.getState(),
expandedRowsHeight = _store$getState3.expandedRowsHeight;
var height = this.trRef.getBoundingClientRect().height;
expandedRowsHeight[rowKey] = height;
store.setState({ expandedRowsHeight: expandedRowsHeight });
}
};
TableRow.prototype.render = function render() {
var _this3 = this;
var _props5 = this.props,
prefixCls = _props5.prefixCls,
columns = _props5.columns,
record = _props5.record,
visible = _props5.visible,
index = _props5.index,
expandIconColumnIndex = _props5.expandIconColumnIndex,
expandIconAsCell = _props5.expandIconAsCell,
expanded = _props5.expanded,
expandRowByClick = _props5.expandRowByClick,
expandable = _props5.expandable,
onExpand = _props5.onExpand,
needIndentSpaced = _props5.needIndentSpaced,
indent = _props5.indent,
indentSize = _props5.indentSize;
var className = this.props.className;
if (this.state.hovered) {
className += ' ' + prefixCls + '-hover';
}
var cells = [];
var expandIcon = _react2.default.createElement(_ExpandIcon2.default, {
expandable: expandable,
prefixCls: prefixCls,
onExpand: onExpand,
needIndentSpaced: needIndentSpaced,
expanded: expanded,
record: record
});
for (var i = 0; i < columns.length; i++) {
if (expandIconAsCell && i === 0) {
cells.push(_react2.default.createElement(
'td',
{
className: prefixCls + '-expand-icon-cell',
key: 'rc-table-expand-icon-cell'
},
expandIcon
));
}
var isColumnHaveExpandIcon = expandIconAsCell || expandRowByClick ? false : i === expandIconColumnIndex;
cells.push(_react2.default.createElement(_TableCell2.default, {
prefixCls: prefixCls,
record: record,
indentSize: indentSize,
indent: indent,
index: index,
column: columns[i],
key: columns[i].key,
expandIcon: isColumnHaveExpandIcon ? expandIcon : null
}));
}
var height = this.props.height || this.state.height;
var style = { height: height };
if (!visible) {
style.display = 'none';
}
return _react2.default.createElement(
'tr',
{
ref: function ref(node) {
return _this3.trRef = node;
},
onClick: this.onRowClick,
onDoubleClick: this.onRowDoubleClick,
onMouseEnter: this.onMouseEnter,
onMouseLeave: this.onMouseLeave,
className: prefixCls + ' ' + className + ' ' + prefixCls + '-level-' + indent,
style: style
},
cells
);
};
return TableRow;
}(_react2.default.Component);
TableRow.propTypes = {
onDestroy: _react.PropTypes.func,
onRowClick: _react.PropTypes.func,
onRowDoubleClick: _react.PropTypes.func,
record: _react.PropTypes.object,
prefixCls: _react.PropTypes.string,
expandIconColumnIndex: _react.PropTypes.number,
onHover: _react.PropTypes.func,
columns: _react.PropTypes.array,
height: _react.PropTypes.oneOfType([_react.PropTypes.string, _react.PropTypes.number]),
visible: _react.PropTypes.bool,
index: _react.PropTypes.number,
hoverKey: _react.PropTypes.any,
expanded: _react.PropTypes.bool,
expandable: _react.PropTypes.any,
onExpand: _react.PropTypes.func,
needIndentSpaced: _react.PropTypes.bool,
className: _react.PropTypes.string,
indent: _react.PropTypes.number,
indentSize: _react.PropTypes.number,
expandIconAsCell: _react.PropTypes.bool,
expandRowByClick: _react.PropTypes.bool,
store: _react.PropTypes.object.isRequired,
expandedRow: _react.PropTypes.bool,
fixed: _react.PropTypes.bool,
rowKey: _react.PropTypes.string
};
TableRow.defaultProps = {
onRowClick: function onRowClick() {},
onRowDoubleClick: function onRowDoubleClick() {},
onDestroy: function onDestroy() {},
expandIconColumnIndex: 0,
expandRowByClick: false,
onHover: function onHover() {}
};
exports.default = TableRow;
module.exports = exports['default'];
/***/ },
/* 8 */
/***/ function(module, exports, __webpack_require__) {
'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 = __webpack_require__(6);
var _react2 = _interopRequireDefault(_react);
var _lodash = __webpack_require__(9);
var _lodash2 = _interopRequireDefault(_lodash);
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 TableCell = function (_React$Component) {
_inherits(TableCell, _React$Component);
function TableCell() {
var _temp, _this, _ret;
_classCallCheck(this, TableCell);
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _ret = (_temp = (_this = _possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.handleClick = function (e) {
var _this$props = _this.props,
record = _this$props.record,
onCellClick = _this$props.column.onCellClick;
if (onCellClick) {
onCellClick(record, e);
}
}, _temp), _possibleConstructorReturn(_this, _ret);
}
TableCell.prototype.isInvalidRenderCellText = function isInvalidRenderCellText(text) {
return text && !_react2.default.isValidElement(text) && Object.prototype.toString.call(text) === '[object Object]';
};
TableCell.prototype.render = function render() {
var _props = this.props,
record = _props.record,
indentSize = _props.indentSize,
prefixCls = _props.prefixCls,
indent = _props.indent,
index = _props.index,
expandIcon = _props.expandIcon,
column = _props.column;
var dataIndex = column.dataIndex,
render = column.render,
_column$className = column.className,
className = _column$className === undefined ? '' : _column$className;
// We should return undefined if no dataIndex is specified, but in order to
// be compatible with object-path's behavior, we return the record object instead.
var text = void 0;
if (typeof dataIndex === 'number') {
text = (0, _lodash2.default)(record, dataIndex);
} else if (!dataIndex || dataIndex.length === 0) {
text = record;
} else {
text = (0, _lodash2.default)(record, dataIndex);
}
var tdProps = void 0;
var colSpan = void 0;
var rowSpan = void 0;
if (render) {
text = render(text, record, index);
if (this.isInvalidRenderCellText(text)) {
tdProps = text.props || {};
colSpan = tdProps.colSpan;
rowSpan = tdProps.rowSpan;
text = text.children;
}
}
// Fix https://github.com/ant-design/ant-design/issues/1202
if (this.isInvalidRenderCellText(text)) {
text = null;
}
var indentText = expandIcon ? _react2.default.createElement('span', {
style: { paddingLeft: indentSize * indent + 'px' },
className: prefixCls + '-indent indent-level-' + indent
}) : null;
if (rowSpan === 0 || colSpan === 0) {
return null;
}
return _react2.default.createElement(
'td',
_extends({
className: className
}, tdProps, {
onClick: this.handleClick
}),
indentText,
expandIcon,
text
);
};
return TableCell;
}(_react2.default.Component);
TableCell.propTypes = {
record: _react.PropTypes.object,
prefixCls: _react.PropTypes.string,
index: _react.PropTypes.number,
indent: _react.PropTypes.number,
indentSize: _react.PropTypes.number,
column: _react.PropTypes.object,
expandIcon: _react.PropTypes.node
};
exports.default = TableCell;
module.exports = exports['default'];
/***/ },
/* 9 */
/***/ function(module, exports) {
/* WEBPACK VAR INJECTION */(function(global) {/**
* lodash (Custom Build) <https://lodash.com/>
* Build: `lodash modularize exports="npm" -o ./`
* Copyright jQuery Foundation and other contributors <https://jquery.org/>
* Released under MIT license <https://lodash.com/license>
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
*/
/** Used as the `TypeError` message for "Functions" methods. */
var FUNC_ERROR_TEXT = 'Expected a function';
/** Used to stand-in for `undefined` hash values. */
var HASH_UNDEFINED = '__lodash_hash_undefined__';
/** Used as references for various `Number` constants. */
var INFINITY = 1 / 0;
/** `Object#toString` result references. */
var funcTag = '[object Function]',
genTag = '[object Gen