简体   繁体   English

Ant设计 - 如何通过拖动调整表格列宽?

[英]Ant design - How to adjust table column width by dragging?

Is there any way to let users to adjust column width of Ant Design Table by drag and drop? 有没有办法让用户通过拖放调整Ant设计表的列宽?

I found some examples that about is for column sorting, but not for column resizing. 我发现了一些关于列排序的例子,但没有关于列大小调整的例子。

Please help, thanks! 请帮忙,谢谢!


UPDATED @ 2018-11-13 更新@ 2018-11-13

There is an official example of resizing table column now: 现在有一个调整表格列的官方示例:

https://ant.design/components/table/#components-table-demo-resizable-column https://ant.design/components/table/#components-table-demo-resizable-column

I have made a working sample - its far from perfect and needs a lot of optimization. 我做了一个工作样本 - 它远非完美,需要大量优化。 Basically you need to use the onHeaderCell and capture onMouseDown , onMouseUp and onMouseMove . 基本上你需要使用onHeaderCell和捕捉onMouseDownonMouseUponMouseMove

onMouseMove we call setState and basically trigger a re-render with the new column width. onMouseMove我们调用setState并基本上使用新的列宽度触发重新渲染。

https://codesandbox.io/s/j2zw9nn5w9 https://codesandbox.io/s/j2zw9nn5w9 Antd通过拖动调整表格列宽

onHeaderCell: column => {
  let colw = this.state.columnWidth;
  return {
    onMouseDown: e => {
      this.mouseDownX = e.clientX;
      this.beginDrag = true;
    },
    onMouseUp: () => {
      this.beginDrag = false;
    },
    onMouseMove: e => {
      if(this.beginDrag === true) {
        this.updateColumnWidth(colw + 
        Math.round((e.clientX - this.mouseDownX)*.05));
      }
    }
  };
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM