Commit 9988d5e9 authored by zhangwenshuai's avatar zhangwenshuai

修改列伸缩为dom操作

parent be4f22ef
...@@ -30,6 +30,8 @@ export default class AirTable extends Component<TableProps, TableState> { ...@@ -30,6 +30,8 @@ export default class AirTable extends Component<TableProps, TableState> {
grid6: any; grid6: any;
tableContainer: any; tableContainer: any;
widthHandleWrapper: any;
widthHandle: any;
memoizeData: Function; memoizeData: Function;
...@@ -68,8 +70,6 @@ export default class AirTable extends Component<TableProps, TableState> { ...@@ -68,8 +70,6 @@ export default class AirTable extends Component<TableProps, TableState> {
tableWidth: width, tableWidth: width,
tableHeight: height, tableHeight: height,
selectedCell: null, selectedCell: null,
showWidthHandle: false,
widthHandleLeft: 0,
}; };
this.config = { this.config = {
overscanColumnCount: 5, overscanColumnCount: 5,
...@@ -220,31 +220,19 @@ export default class AirTable extends Component<TableProps, TableState> { ...@@ -220,31 +220,19 @@ export default class AirTable extends Component<TableProps, TableState> {
}; };
// 列伸缩回调 // 列伸缩回调
onResizeWidth = (columnName: string, e, { size }) => { onResizeWidth = (e) => {
let originLeft = const originLeft = (this.tableContainer && this.tableContainer.getBoundingClientRect().x) || 0;
this.tableContainer && this.tableContainer.offsetParent.offsetParent.offsetParent.style.paddingLeft; if (this.widthHandle) {
if (originLeft) { this.widthHandle.style.left = `${e.x - originLeft}px`;
originLeft = originLeft.replace(/[a-zA-Z]/gi, '');
} else {
originLeft = 0;
} }
this.setState({
widthHandleLeft: e.x - originLeft,
});
}; };
// 列伸缩开始 // 列伸缩开始
onResizeWidthStart = (columnName: string, e, { size }) => { onResizeWidthStart = (e) => {
let originLeft = const originLeft = (this.tableContainer && this.tableContainer.getBoundingClientRect().x) || 0;
this.tableContainer && this.tableContainer.offsetParent.offsetParent.offsetParent.style.paddingLeft; if (this.widthHandleWrapper && this.widthHandle) {
if (originLeft) { this.widthHandleWrapper.style.display = 'block';
originLeft = originLeft.replace(/[a-zA-Z]/gi, ''); this.widthHandle.style.left = `${e.x - originLeft}px`;
} else {
originLeft = 0;
} }
this.setState({
showWidthHandle: true,
widthHandleLeft: e.x - originLeft,
});
}; };
// 列伸缩结束 // 列伸缩结束
onResizeWidthStop = (columnName: string, e, { size }) => { onResizeWidthStop = (columnName: string, e, { size }) => {
...@@ -256,10 +244,12 @@ export default class AirTable extends Component<TableProps, TableState> { ...@@ -256,10 +244,12 @@ export default class AirTable extends Component<TableProps, TableState> {
} }
newColumns.push(item); newColumns.push(item);
}); });
if (this.widthHandleWrapper) {
this.widthHandleWrapper.style.display = 'none';
}
this.setState( this.setState(
{ {
columns: newColumns, columns: newColumns,
showWidthHandle: false,
}, },
() => { () => {
this.grid1 && this.grid1.recomputeGridSize(); this.grid1 && this.grid1.recomputeGridSize();
...@@ -301,8 +291,8 @@ export default class AirTable extends Component<TableProps, TableState> { ...@@ -301,8 +291,8 @@ export default class AirTable extends Component<TableProps, TableState> {
}} }}
/> />
} }
// onResize={this.onResizeWidth.bind(this, columnName)} onResize={this.onResizeWidth}
// onResizeStart={this.onResizeWidthStart.bind(this, columnName)} onResizeStart={this.onResizeWidthStart}
onResizeStop={this.onResizeWidthStop.bind(this, columnName)} onResizeStop={this.onResizeWidthStop.bind(this, columnName)}
draggableOpts={{ enableUserSelectHack: false }} draggableOpts={{ enableUserSelectHack: false }}
> >
...@@ -418,7 +408,7 @@ export default class AirTable extends Component<TableProps, TableState> { ...@@ -418,7 +408,7 @@ export default class AirTable extends Component<TableProps, TableState> {
render() { render() {
const { loading, noDataPlaceholder, loadComp } = this.props; const { loading, noDataPlaceholder, loadComp } = this.props;
const { columns, dataSource, tableWidth = 0, tableHeight = 0, showWidthHandle, widthHandleLeft } = this.state; const { columns, dataSource, tableWidth = 0, tableHeight = 0 } = this.state;
const { overscanColumnCount, overscanRowCount, rowHeight, headerHeight } = this.config; const { overscanColumnCount, overscanRowCount, rowHeight, headerHeight } = this.config;
const scrollbarWidth = scrollbarSize() || 0; const scrollbarWidth = scrollbarSize() || 0;
const showColumns = this.memoizeColumns(columns); const showColumns = this.memoizeColumns(columns);
...@@ -716,9 +706,16 @@ export default class AirTable extends Component<TableProps, TableState> { ...@@ -716,9 +706,16 @@ export default class AirTable extends Component<TableProps, TableState> {
</div> </div>
<div <div
className={styles.widthHandleWrapper} className={styles.widthHandleWrapper}
style={{ display: showWidthHandle ? 'block' : 'none' }} ref={(dom) => {
this.widthHandleWrapper = dom;
}}
> >
<div className={styles.widthHandle} style={{ left: widthHandleLeft }} /> <div
className={styles.widthHandle}
ref={(dom) => {
this.widthHandle = dom;
}}
/>
</div> </div>
</div> </div>
); );
......
...@@ -80,8 +80,6 @@ export interface TableState { ...@@ -80,8 +80,6 @@ export interface TableState {
tableHeight?: number; tableHeight?: number;
tableWidth?: number; tableWidth?: number;
selectedCell?: any; selectedCell?: any;
showWidthHandle: boolean;
widthHandleLeft: number;
} }
export interface CommonProps extends TableProps { export interface CommonProps extends TableProps {
operateConfig?: OperateConfigProps; operateConfig?: OperateConfigProps;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment