|
104 | 104 |
|
105 | 105 | var _this = _possibleConstructorReturn(this, (StickyTable.__proto__ || Object.getPrototypeOf(StickyTable)).call(this, props));
|
106 | 106 |
|
107 |
| - _this.id = Math.floor(Math.random() * 1000000000) + ''; |
108 |
| - |
109 | 107 | _this.rowCount = 0;
|
110 | 108 | _this.columnCount = 0;
|
111 | 109 | _this.xScrollSize = 0;
|
112 | 110 | _this.yScrollSize = 0;
|
113 | 111 |
|
| 112 | + _this.dom = {}; |
| 113 | + |
114 | 114 | _this.stickyHeaderCount = props.stickyHeaderCount === 0 ? 0 : _this.stickyHeaderCount || 1;
|
115 | 115 |
|
116 | 116 | _this.isFirefox = navigator && navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
|
|
131 | 131 | value: function componentDidMount() {
|
132 | 132 | var _this2 = this;
|
133 | 133 |
|
134 |
| - this.dom = {}; |
135 |
| - |
136 |
| - if (document.getElementById('sticky-table-' + this.id)) { |
137 |
| - this.dom.wrapper = document.getElementById('sticky-table-' + this.id); |
| 134 | + if (this.dom.wrapper) { |
138 | 135 | this.dom.bodyTable = this.dom.wrapper.querySelector('.sticky-table-x-wrapper .sticky-table-table');
|
139 | 136 | this.dom.xScrollbar = this.dom.wrapper.querySelector('.x-scrollbar');
|
140 | 137 | this.dom.yScrollbar = this.dom.wrapper.querySelector('.y-scrollbar');
|
|
266 | 263 | _ref$forceWrapperResi = _ref.forceWrapperResize,
|
267 | 264 | forceWrapperResize = _ref$forceWrapperResi === undefined ? false : _ref$forceWrapperResi;
|
268 | 265 |
|
269 |
| - var wrapperSize = { width: this.dom.wrapper.offsetWidth, height: this.dom.wrapper.offsetWidth }; |
| 266 | + var wrapperSize = { |
| 267 | + width: this.dom.wrapper.offsetWidth, |
| 268 | + height: this.dom.wrapper.offsetWidth |
| 269 | + }; |
| 270 | + |
270 | 271 | var tableCellSizes = {
|
271 | 272 | corner: { width: this.dom.stickyCornerTable.offsetWidth, height: this.dom.stickyCornerTable.offsetHeight },
|
272 | 273 | header: { width: this.dom.stickyHeaderTable.offsetWidth, height: this.dom.stickyHeaderTable.offsetHeight },
|
273 | 274 | column: { width: this.dom.stickyColumnTable.offsetWidth, height: this.dom.stickyColumnTable.offsetHeight },
|
274 | 275 | body: { width: this.dom.bodyTable.offsetWidth, height: this.dom.bodyTable.offsetHeight }
|
275 | 276 | };
|
276 | 277 |
|
277 |
| - if (forceCellTableResize || !this.oldTableCellSizes || JSON.stringify(tableCellSizes) !== JSON.stringify(this.oldTableCellSizes)) { |
| 278 | + var tableCellSizesChanged = JSON.stringify(tableCellSizes) !== JSON.stringify(this.oldTableCellSizes); |
| 279 | + var wrapperSizeChanged = JSON.stringify(wrapperSize) !== JSON.stringify(this.oldWrapperSize); |
| 280 | + |
| 281 | + if (forceCellTableResize || !this.oldTableCellSizes || tableCellSizesChanged) { |
278 | 282 | this.setRowHeights();
|
279 | 283 | this.setColumnWidths();
|
280 | 284 |
|
281 | 285 | this.oldTableCellSizes = tableCellSizes;
|
282 | 286 | }
|
283 | 287 |
|
284 |
| - if (forceWrapperResize || !this.oldWrapperSize || JSON.stringify(wrapperSize) !== JSON.stringify(this.oldWrapperSize)) { |
| 288 | + if (forceWrapperResize || !this.oldWrapperSize || wrapperSizeChanged || tableCellSizesChanged) { |
285 | 289 | this.setScrollBarDims();
|
286 | 290 | this.setScrollBarWrapperDims();
|
287 | 291 | this.setScrollData();
|
|
496 | 500 | }, {
|
497 | 501 | key: 'render',
|
498 | 502 | value: function render() {
|
| 503 | + var _this9 = this; |
| 504 | + |
499 | 505 | //This is probably sub-optimal because render only needs
|
500 | 506 | //to be called for react components that are sub-classed
|
501 | 507 | //and don't have props.children that are <Cell>s
|
|
511 | 517 | this.rowCount = rows.length;
|
512 | 518 | this.columnCount = rows[0] && _react2.default.Children.toArray(rows[0].props.children).length || 0;
|
513 | 519 |
|
| 520 | + var setWrapperElement = function setWrapperElement(element) { |
| 521 | + if (element) _this9.dom.wrapper = element; |
| 522 | + }; |
| 523 | + |
514 | 524 | return _react2.default.createElement(
|
515 | 525 | 'div',
|
516 |
| - { className: 'sticky-table ' + (this.props.className || ''), id: 'sticky-table-' + this.id }, |
| 526 | + { className: 'sticky-table ' + (this.props.className || ''), ref: setWrapperElement }, |
517 | 527 | _react2.default.createElement(
|
518 | 528 | 'div',
|
519 | 529 | { className: 'x-scrollbar' },
|
|
0 commit comments