Code Monkey home page Code Monkey logo

varown / react-antd-column-resize Goto Github PK

View Code? Open in Web Editor NEW
43.0 1.0 14.0 7.29 MB

react-antd-column-resize 是一个基于 react hooks 开发的 antd 表格(table)列宽拖动组件(antd 表格拖动、拖拽、调整表头宽度), 支持 antd4、antd5 和 ant-design/pro-components 以及所有基于 antd 开发的 table 组件。 其核心 hooks useAntdColumnResize,可以自定义拖动的最小宽度、最大宽度和默认宽度方便快捷。

Home Page: https://varown.github.io/react-antd-column-resize/components/use-antd-column-resize

License: MIT License

TypeScript 94.95% JavaScript 1.25% Shell 0.41% CSS 3.38%
antd react table

react-antd-column-resize's Introduction

欢迎使用 react-antd-column-resize

中文文档 | English NPM version NPM downloads

简介

react-antd-column-resize 是一个基于 react hooks 开发的 antd 表格(table)列宽拖动组件, 支持 antd4、antd5 和 ant-design/pro-components 以及所有基于 antd 开发的 table 组件。 其核心 hooksuseAntdColumnResize,可以自定义拖动的最小宽度、最大宽度和默认宽度方便快捷。 已经使用 antd4、antd5 官网中的 table 示例例进行测试,可以正常使用。

安装

npm install --save react-antd-column-resize

# or use yarn

yarn add react-antd-column-resize

使用

import { Button, Divider, Table } from 'antd';
import React from 'react';
import { useAntdColumnResize } from 'react-antd-column-resize';

const App = () => {
  const columns = [
    {
      title: 'Name',
      dataIndex: 'name',
      key: 'name',
      width: 200,
      align: 'center',
    },
    {
      title: 'Age',
      dataIndex: 'age',
      key: 'age',
      width: 100,
    },
    {
      title: 'Address',
      dataIndex: 'address',
      key: 'address',
      width: 300,
    },
    {
      title: 'phone',
      dataIndex: 'phone',
      key: 'phone',
      fixed: 'right',
      //width:"必须有一项不设置宽度,不然会造成拖动异常"
      //width:"必须有一项不设置宽度,不然会造成拖动异常"
      //width:"必须有一项不设置宽度,不然会造成拖动异常"
    },
  ];

  const data = [
    {
      key: '1',
      name: 'John Doe',
      age: 32,
      address: '123 Street, City',
      phone: '1588553336',
    },
    {
      key: '2',
      name: 'Jane Smith',
      age: 28,
      address: '456 Road, Town',
      phone: '1588553336',
    },
  ];
  const { resizableColumns, components, tableWidth, resetColumns } =
    useAntdColumnResize(() => {
      return { columns, minWidth: 100 };
    }, []);

  return (
    <div className="app">
      <Button onClick={resetColumns}>重置Columns</Button>
      <Divider />
      <Table
        columns={resizableColumns}
        dataSource={data}
        components={components}
        bordered
        scroll={{ x: tableWidth }}
      />
    </div>
  );
};

export default App;

useAntdColumnResize API

useAntdColumnResize(setup: () => resizeDataType, dependencies: any[])

参数 说明 类型 默认值
setup 获取列配置函数 () => resizeDataType<Column> -
dependencies 更新依赖项 any[] -

resizeDataType setup 返回数据类型

参数 说明 类型 默认值
columns 列配置 object[] antd table columns -
minWidth 最小宽度 number 120
maxWidth 最大宽度 number 2000

useAntdColumnResize 返回数据

参数 说明 类型 默认值
resizableColumns 可拖动列配置 object[] antd table columns -
components antd table 组件 object -
tableWidth 表格宽度 number -
resetColumns 重置列 function -

注意事项(请一定阅读,请一定阅读,请一定阅读,尤其是第二项)

  1. columns 设置每项 width 时,默认该项是可拖动项,并且请确保含有唯一标识(dataIndex或者key)。
  2. columns 至少需要一项不设置 width,否则会拖动异常,minWidth 默认是未设置项宽度的最小宽度。 原因:当 columns 每项设置的宽度之和小于表格宽度时,会造成拖动异常,所以需要至少一项不设置宽度,让其自适应。
  3. minWidthmaxWidth 代表可拖动的距离,建议 minWidth等于 columns 设置的最小宽度项,最大宽度同理应大于columns 设置的最大宽度项。
  4. 请不要欺骗useAntdColumnResizedependencies 依赖项请按需添加,否则会造成无限循环。

贡献

如果对您有帮助希望动动您发财的小手,给个 star 吧!

欢迎贡献代码、提出问题或者改进建议。请查阅贡献指南了解更多详情。

Stargazers over time

Stargazers over time

react-antd-column-resize's People

Contributors

varown avatar

Stargazers

 avatar  avatar  avatar 高级CV魔改师(恩师鱿鱼须) avatar hxj avatar bqxu avatar  avatar BarrySong avatar fine avatar  avatar longmo avatar Bing Li avatar  avatar hank avatar 你的明明呐丶 avatar yang-wei-jie avatar  avatar Deshun avatar zhan yeye avatar Lion Li avatar Brad.Z avatar xiaoyunxiao avatar  avatar Beall  avatar TONY.W avatar towavephone avatar  avatar Matthew Wang avatar 莉莉安 avatar 大马猴 avatar  avatar Funny avatar Simon avatar  avatar ziyi avatar NeilChoi avatar  avatar  avatar oxxd avatar  avatar  avatar  avatar 庆丰年 avatar

Watchers

 avatar

react-antd-column-resize's Issues

Hook生效应当在文档中还加一个前提条件

添加文档注释:要使得列宽可以被拖动,除了要声明width属性外,必须声明key或dataIndex属性,否则拖动不生效。
因为有时候表格中的操作列不声明key或dataIndex也是可以的。
image

自定义handle

您好,可以把把react-resizable部分参数放开透传吗? 比如handle等

该库使用了 sass,但是依赖并未声明导致运行失败

Hi,

首先感谢您的开源项目。
但是在使用时发现该库使用了 sass 作为样式预处理器,并且没有将其声明到 package.json 中。
由于使用 father build 的 bundleless 模式,并未将 scss 后缀文件处理,所以在没有 sass 的项目中使用该库将会报错。

建议是否能将 sass 移除,或在 publish 前先用 sass 将 scss 文件转化为 css,又或者使用 jss 编写样式并将 jss 加入 dependencies。

再次感谢

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.