Skip to content

Commit

Permalink
<- table -> fixed columns width on resize
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-long-1988 committed Feb 25, 2019
1 parent 4247a84 commit 32d00db
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fast-table",
"version": "1.4.5",
"version": "1.4.6",
"description": "react table fast",
"main": "./lib/index.js",
"files": [
Expand Down
32 changes: 17 additions & 15 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,20 +140,21 @@ export default class Table extends React.PureComponent<TableParams> {
};

onResize = ({width, height}) => {
this._renderEnable = true;
this._width = width;
this._height = height;
this.cacheManager.reset();
this.sizeManager.update({
_wrapperWidth: width,
_wrapperHeight: height,
_scrollSizeX: measureScrollbar('horizontal'),
_scrollSizeY: measureScrollbar()
});
this.getShowCount();
this.updateColumn();
this.resetShowData();
// this.setState({width, height});
if (this._width !== width || this._height !== height) {
this._renderEnable = true;
this._width = width;
this._height = height;
this.cacheManager.reset();
this.sizeManager.update({
_wrapperWidth: width,
_wrapperHeight: height,
_scrollSizeX: measureScrollbar('horizontal'),
_scrollSizeY: measureScrollbar()
});
this.getShowCount();
this.updateColumn();
this.resetShowData();
}
};

updateColumn = () => {
Expand Down Expand Up @@ -444,10 +445,11 @@ export default class Table extends React.PureComponent<TableParams> {
);
};

renderChild = () => {
renderChild = (params) => {
if (!this._renderEnable) {
return null;
}
this.onResize(params);
const {style, prefixCls} = this.props;
const hasLeftFixed = this.columnManager.isAnyColumnsLeftFixed();
const hasRightFixed = this.columnManager.isAnyColumnsRightFixed();
Expand Down
20 changes: 20 additions & 0 deletions src/managers/ColumnManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,29 @@ export default class ColumnManager {

updateGroupedColumns = (columns) => {
this._cached = {};
this.columns = this._uColumns(columns);
this._cached['groupedColumns'] = columns;
};

_uColumns = (columns) => {
return columns.map((c) => {
let column = {};
for (let key in c) {
if (
typeof key !== 'symbol' &&
Object.prototype.hasOwnProperty.call(c, key)
) {
column[key] = c[key];
}
}
const children = column.children || [];
if (children.length > 0) {
column.children = this._uColumns(children);
}
return column;
});
};

_calcWidth = (width, wrapperWidth) => {
if (typeof width === 'string' && percentReg.test(width)) {
const i = width.replace('%', '');
Expand Down

0 comments on commit 32d00db

Please sign in to comment.