Giter VIP home page Giter VIP logo

virtualized-table-for-antd's Introduction

The virtualized table component for AntD4,fast, restorable and smallest size for gzip!

npm dm license

NPM

  • Install

    npm i --save virtualizedtableforantd4
  • the opts of useVT(examples)

    interface VtOpts {
      id?: number | string;
      /**
       * @default 5
       */
      overscanRowCount?: number;
    
      /**
       * this only needs the scroll.y
       */
      scroll: {
          y: number | string;
      };
    
      /**
       * wheel event(only works on native events).
       */
      onScroll?: ({ left, top, isEnd, }:
        { top: number; left: number; isEnd: boolean }) => void;
    
      initTop?: number;
    
      /**
       * Offset of the table when isEnd becomes true.
       * @default 0
       */
      offset?: number;
    
      /**
       * @default false
       */
      debug?: boolean;
    
    
      // pass -1 means scroll to the bottom of the table
      ref?: React.MutableRefObject<{
        scrollTo: (y: number) => void;
        scrollToIndex: (idx: number) => void;
      }>
    }
  • Quick start

    You need to change your style like following if your Table.size is not default.

    // size={'small'}
    ant-table [vt] > table > .ant-table-tbody > tr > td {
        padding: 8px;
    }
    import React from 'react';
    import { Table } from 'antd';
    import { useVT } from 'virtualizedtableforantd4';
    
    const [ vt, set_components ] = useVT(() => ({ scroll: { y: 600 } }), []);
    
    <Table
      scroll={{ y: 600 }} // It's important for using VT!!! DO NOT FORGET!!!
      components={vt}
      columns={/*your columns*/}
      dataSource={/*your data*/}
    />
  • Scroll to

  • Restoring last state

  • Editable Table

  • Drag soring

  • expanded rows & tree-structure has been well supported!

License

MIT

virtualized-table-for-antd's People

Contributors

frozzy6 avatar kestutis avatar nokecy avatar s-yadav avatar vincz avatar wubostc avatar zomixi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

virtualized-table-for-antd's Issues

Uncaught TypeError: Cannot read property 'style' of null

:19006/static/js/bundle.js:248771 Uncaught TypeError: Cannot read property 'style' of null
at update_wrap_style (:19006/static/js/bundle.js:248771)
at VTRow.collect_h_tr (:19006/static/js/bundle.js:248873)
at VTRow.componentDidUpdate (:19006/static/js/bundle.js:248834)

不知為何, 當我transfer column的時候, 這問題就發生了, 原來的 antd table 是沒這問題的

image

Invalid hook call. Hooks can only be called inside of the body of a function component.

I've tried to use useVT like

import React, {useRef, useEffect} from 'react'
import {useVT} from 'virtualizedtableforantd'

const MyTable = () => {
    const ctx = useRef({})
    const [VT, setComponents, VTScroll] = useVT({onScroll: {}})

    useEffect(()=> {
        return () => {
            const loc = VTScroll(id.current)
           ctx.current.top = loc.top
        }
    },[])
    
    return <Table components={VT} {...rest} />
}

当数据条数初始为0 到 数十条数据的时候, 会渲染不出来一条数据

直接上codesandbox. 链接: https://codesandbox.io/s/epic-fast-l79vt.

只要我将_repainting里面的代码调整一下位置即可正常运行.
原:
`

if (PAINT_FREE.size) {
  for (let idx of PAINT_FREE) {
    free_h_tr(ctx, idx);
  }
  console.assert(!isNaN(ctx.computed_h) && ctx.computed_h >= 0);
}

if (PAINT_SFREE.size) {
  for (let idx of PAINT_SFREE) {
    free_h_tr(ctx, idx);
  }
  console.assert(!isNaN(ctx.computed_h) && ctx.computed_h >= 0);
}

if (PAINT_ADD.size) {
  for (let [idx, el] of PAINT_ADD) {
    apply_h(ctx, idx, el.offsetHeight);
  }
  console.assert(!isNaN(ctx.computed_h) && ctx.computed_h >= 0);
}

`

改成:
`

    if (PAINT_FREE.size) {
        for (let idx of PAINT_FREE) {
            free_h_tr(ctx, idx)
        }
        console.assert(!isNaN(ctx.computed_h) && ctx.computed_h >= 0);
    }

    if (PAINT_ADD.size) {
        for (let [idx, el] of PAINT_ADD) {
            apply_h(ctx, idx, el.offsetHeight)
        }
        console.assert(!isNaN(ctx.computed_h) && ctx.computed_h >= 0);
    }

    if (PAINT_SFREE.size) {
        for (let idx of PAINT_SFREE) {
            free_h_tr(ctx, idx)
        }
        console.assert(!isNaN(ctx.computed_h) && ctx.computed_h >= 0);
    }

`
就可以正常运行了. 初始为0的时候 两次free会报错, 所以我将add放在sfree前面就能正常运行了.
_repainting这部分代码感觉是有些重复的操作, 如果代码写的更规范一些, 不那么杂乱, 说不定会有更多的人来帮你一起维护.

最新版本不支持ie浏览器么?

我使用之前的0.4.0版本出现了个bug,当数据量很大时候,第一次加载只会加载20多条,下面都是空白的。所以我就把版本升级到最新的0.6.1版本,在这个版本上没有上面那个bug了,可是在ie11下就报错了

Fixed row height

Hello, I need a possibility to set this.inst.current.offsetHeight by hands. There are exist cases when offsetHeight equals to zero and table didn't show any content.
It looks like
image
I sometimes got this issue with dynamic components.

Can you do props param for fixed row height smth like
this.collect_h_tr(this.props.children[0]!.props!.index, this.props.rowHeight || this.inst.current.offsetHeight);
in didmount and didupdate methods?

Table becomes blank when it re-renders

issue
We have a table component that fetches new data on page change or on sorting etc. It goes blank sometimes and the issue is difficult to reproduce. Similar to issue #15. Can you help me in resolving this issue

ctx._React_ptr.forceUpdate is not a function.

I'm using React-router-dom and when I change to other screen with te same Table component but with differenrent data, appears whits error, however the Table works

Uncaught TypeError: ctx._React_ptr.forceUpdate is not a function vt.js:249

How to use custom row component?

Hey :)

I don't quite get how to use my custom row component with your library.

Before I just used:

<Table
	columns={columns}
	dataSource={songs}
	pagination={false}
	scroll={{ y: height - 210 }}
	components={{ body: { row: MyCustomRowComponent } }}
/>

Now I tried

const componentsConfig = getVTComponents(1000);
componentsConfig.row = MyCustomRowComponent

<Table
	columns={columns}
	dataSource={songs}
	pagination={false}
	scroll={{ y: height - 210 }}
	components={
		VTComponents({
			id: 1000,
		})
	}
/>

but I get a Assertion failed: console.assert on the console without any further explanation what's wrong.

Table渲染问题

组件首次加载是正常的,但是刷新组件后,表格数据就渲染不出来了。如下图:

Snipaste_2019-10-29_10-53-24
GIF

我找不到问题在哪,用的是最简单的用法,不确定是不是由于render多次导致的,但是后面几次render数据是传进来了的。
请帮忙分析一下可能是哪里出问题了,感谢。

关于antd4支持情况调查

目前初步实现,还有些bug:
1.表格头部被隐藏了
2.横向拖动的时候表格头部动不了

还没想好怎么解决(主要是懒得看antd的源码 ( 0x0 ) )
估计得很久很久

------2020/5/30-------
有种不好的预感,restorable感觉要被砍了 (╥╯^╰╥)

仅仅跑了源码下 test文件下的文件,报一下错误(接不进自己的项目,请问是什么原因???)

"react": "16.12.0",
"antd": "^4.0.3",
"virtualizedtableforantd": "^0.7.6"
使用的是 : useVT
然后将你Test中CustomRows Hooks取出来放到我项目中测试,结果报错
[
Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:

  1. You might have mismatching versions of React and the renderer (such as React DOM)
  2. You might be breaking the Rules of Hooks
  3. You might have more than one copy of React in the same app
    ]

使用 components={VTComponents({ id: 1, debug: true })}
报错
[
vt.js文件 TypeError: Cannot read property 'props' of undefined;
The above error occurred in the component:
in VTable (created by Table)
in div (created by Table)
in div (created by Table)
in Unknown
]

Table scrolls more than necessary and headers are not scrolled

We were using v0.7.1 and when updated to v0.7.5, table scroller try to scroll more than the table width. Not only scroll but also header is not scrolling as it supposed to be.
When we dig deeper we found that the table body width is changed to 100000.

  1. width
    Screen Shot 2020-01-01 at 4 17 16 PM

  2. scroller error
    Screen Shot 2020-01-01 at 4 08 58 PM
    Screen Shot 2020-01-01 at 4 09 21 PM

The table will not render while the data in redux have not change

My table is data is from redux soldiers as below

const INITIAL_STATE = {
  soldiers: [],
  isLoading: false,
  currentPage: 0,
  keyword: '',
  sortProperty: '',
  sortDirection: '',
  isDetail: false,
  skip: 'false'
};

Somtimes I will jump to another component with router. After back to the table, if the data in redux not change, the table will not render and just display the header.

WX20200113-182138@2x

WX20200113-182201@2x

Actually I have data in redux
WX20200113-182222@2x

It seems that if the data in the redux, not updates, the table will not render.

Uncaught TypeError: Cannot redefine property: __DIAGNOSIS__

Uncaught TypeError: Cannot redefine property: DIAGNOSIS
at Function.defineProperty ()
at DIAGNOSIS (:3000/static/js/bundle.js:332964)
at new VTable (:3000/static/js/bundle.js:333416)
at constructClassInstance (:3000/static/js/bundle.js:302917)
at updateClassComponent (:3000/static/js/bundle.js:307126)
image

Horizontal scroll issue

I'm using this library to render table inside a resizable container. The horizontal scroll appears when the total column width is more than the width of the container. But the column headers do not move along with the horizontal scroll. Can you please help us with this issue?
Thanks in advance.

Style Error

因为在Table上套了一层Div 导致原AntTable 有些样式不生效了。比如size fixed=“right” 等等

Ajax for progressive load

Hello,

Are you plan to create an example to work with ajax content progressive loading ?

Thank you.

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.