Git Product home page Git Product logo

virtuallist-antd's Introduction

virtuallist-antd

NPM JavaScript Style Guide

仓库(github): https://github.com/crawler-django/virtuallist-antd

版本更新记录(update detail): https://github.com/crawler-django/virtuallist-antd/blob/master/update.md

virtualList for antd-table, 实现 antd-table 的虚拟列表, antd-table 无限滚动, infinite scrolling for antd-table. 支持 antd 树形表格, antd 版本要在 4.17.0 及以上, virtuallist-antd 要再 0.6.3 及以上. (support tree data, after antd v4.17.0, after virtuallist-antd v0.6.3)

  • 支持antd4, antd5.(4.x / 5.x ---- v0.3.0 后, 3.x ---- v0.2.8. antd3对应的版本不再更新)

    (support antdv4, antdv5 --- ^v0.3.0, 3.x --- v0.2.8. 3.x not updated)

  • 你可以像平常一样在 columns 里使用 fixed

    (u can use fixed as usual)

  • 支持进行条件搜索 变更数据.

    (support search data as usual)

  • 目前用了节流 - 60ms 在滚动的时候刷新窗口

    (use throttle, 60ms)

  • 支持分页, calc().

    (support pagination, support scrolly for calc())

  • 只支持纵向虚拟列表.

    (only support vertical virtuallist)

  • 此组件会计算第一行的高度, 并且以第一行的高度为准来固定每行的高度. 组件有自带的 css, �� 会使每行的 td 不会换行.

    (this component will calculate first line's height and amend following each line's height based on it. It has its own css, which prevents each line's TD from wrapping (td do not wrap))

example

complex example

Install

npm install --save virtuallist-antd

Usage

import React, { useMemo } from 'react'
import ReactDom from 'react-dom'

import { VList } from 'virtuallist-antd'
import { Table } from 'antd'

function Example(): JSX.Element {
	const dataSource = [...]
	const columns = [...]
	const rowkey = 'xxx'

	const vComponents = useMemo(() => {
		// 使用VList 即可有虚拟列表的效果
		return VList({
			height: 1000 // 此值和scrollY值相同. 必传. (required).  same value for scrolly
		})
	}, [])

	return (
		<Table
			dataSource={dataSource}
			columns={columns}
			rowKey={rowKey}
			scroll={{
				y: 1000 // 滚动的高度, 可以是受控属性。 (number | string) be controlled.
			}}
			components={vComponents}
		/>
	)
}

ReactDom.render(<Example />, dom)

VList

	VList({
		height: number | string,  // (必填) 对应scrollY.
		onReachEnd: () => void, // ��(可选) 滚动条滚到底部触发api. (scrollbar to the end)
		onScroll: () => void, // (可选) 滚动时触发的api. (triggered by scrolling)
		vid: string, // (可选, 如果同一页面存在多个虚拟表格时必填.) 唯一标识. (unique vid, required when exist more vitual table on a page)
		resetTopWhenDataChange: boolean, // 默认为true. 是否数据变更后重置滚动条 (default true, Whether to reset scrollTop when data changes)
	})

	VList returns: {
		table: VTable,
		body: {
			wrapper: VWrapper,
			row: VRow,
			cell: VCell,
		}
	}

api

import { scrollTo } from 'virtuallist-antd'

// scrollTo
scrollTo({
    row: number, // 行数. (row number)
    y: number, // y偏移量. (offset Y)
    vid: string, // 对应VList的vid. (same as VList vid)
})

License

MIT © crawler-django

virtuallist-antd's People

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

virtuallist-antd's Issues

Table下半页空白

我的列表开始是空的,展示antd的默认空白页面,等我改变搜索条件再次去拉取列表的时候,返回了8条数据,但是表格只展示了4条,等我触发滚动或者页面的resize的时候,突然8条记录又渲染出来了。
antd版本是4.0.3。

滚动条处罚底部请求API函数,在Electron环境中没有执行?

滚动条处罚底部请求API函数 onReachEnd ,在Electron中没有执行而 onScroll 在Electron环境中可以执行,在浏览器中没有问题,请问 onReachEnd 是采用什么方式返回的呢?请问是什么问题导致的呢?使用 react-infinite-scroller 在Electron中执行没有问题。

Summary content

Hello! Thanks for the awesome library!

Any idea on how to make it work with Summary rows?
On my case, if I use summary rows, they render at the last row of the table, not with the default behaviour of rendering after the table default data, as the bellow images shows.

Should be like this:

image

Actual behaviour:

1- Summary is last row of the table, pay attention to the scrollbar
image

2- Summary not visible

image

Reproduce based on one of the docs examples:
https://codesandbox.io/s/affectionate-nova-pshc3

Thanks!

改变搜索条件重新拉取列表数据,接口返回了5条数据,但是表格只展示了4条,需要等待一段时间或者触发滚动,才会将没渲染的数据渲染上。

改变搜索条件重新拉取列表数据,接口返回了5条数据,但是表格只展示了4条,需要等待一段时间或者触发滚动,才会将没渲染的数据渲染上。
antd版本是4.17.1, virtuallist-antd版本是0.6.4-beta.0

如图1所示,本应渲染5条数据,但只渲染4条,等待一会之后才会显示图2这样渲染完成的样子
图1
image

图2
image

能否实现自动跳转到指定行

打开弹窗(Modal)的时候,给Table传一个指定行的参数,Table滚动条自动跳转到该行,不需要Button点击
尝试过把scrollTo放在函数里,或者把Button 放在Table的columns.render里,没有成功,报错:TypeError: Cannot set properties of undefined (setting 'scrollTop')

能否向外部支持一个 onScroll 的回调函数

<Table
    rowSelection={rowSelection}
    columns={columns}
    dataSource={dataSource}
    pagination={false}
    scroll={{y: '85vh'}}
    rowKey={"company_name"}
    components={VList({
        height: '85vh',
        onScroll: handleTableScroll
    })}
/>

由于 ant-d 的一些原因,需要在列表滚动时操作一些其他组件的 props,因此需要如题的onScroll这样一个属性。

项目继续维护, 支持antd.v4.v5

项目特性:
1. fixed, 分页, 查询数据, sorter, string类的高度值. 支持树形结构的数据, 要求antd版本v4.17.0及以上. (antd.v4表格的基本功能大部分都能使用.)

项目缺陷:
1. 组件有自带的css样式文件, 会使每行的td不会换行. (如今只能做到固定每行高度的虚拟滚动)
2. 不支持横向虚拟滚动.
3. 滚动的性能不如react-window.

(keep updating.)

(如果你有好的想法, 欢迎PR. 有好的建议也可以提出来, 一起进步^.^)

Table宽度变化的时候,columns的render函数会全部重新执行,页面卡顿

页面第一次加载


收起侧边栏


代码

getColumn = () => {
        const {renamingId} = this.props;
        return [
            ... ...
            {
                title:'文件名',
                key:'name',
                width:'60%',
                ellipsis:true,
                render:(text,record,index) => {
                    console.log('title')
                    return <WtFileWriteTableNameCell
                        record={record}
                        isRename={renamingId === record.id}
                        onFileOperation={this.props.onFileOperation}
                        onFolderOperation={this.props.onFolderOperation}
                        onFileClick={this.props.onFileClick}
                    />;
                },
            },
            ... ...
        ];
};

页面加载的时候,render执行的应该是展示出来的row个数,但是在table宽度变化的时候,需要将所有row都重新render。
会不会就是因为这个引起的页面卡顿。

列宽无法限制

请问在ant table里设置了列宽,为什么会失效,不受控

当columns列过多会出现滚动卡顿且有空白现象

这几天使用virtuallist-antd虽然加载速度问题解决了,但是发现下拉滚动时会特别不流畅且很卡。不知道作者有没有遇到类似的问题或者已经有了解决的方式,又或者是我使用virtuallist-antd方式错误?。期待作者的回复..
image

项目是否有更新计划

我试了一下,升级到antd4不能用,原因是VTable传入的props.children数组第三个元素是null,而我们这里用到了这个元素,这应该是4.0的一个改变。antd4的table并没有直接支持虚拟滚动,而是文档里写了一个例子,看起来支持的功能很少,和您写的这个不能相提并论,本组件还是有很大用途的。冒昧问一下,还准备更新这个项目吗?或者ant4后虚拟滚动有没有其他更好的解法?

合并单元格滚动导致卡死

    {
      width: 100,
      title: '车数',
      isMerge: true,
      key: 'sameCar',
      dataIndex: 'sameCar',
      search: false,
      fixedSearch: false,
      render: (value, row, index) => {
        const obj = {
          children: value,
          props: {},
        };
        obj.props.rowSpan = row.num
        obj.children = '1车'
        return obj;
      }
    },

image

合并单元格,会导致无法滚动的情况,请问怎么回事?

Table stop rendering rows while in tabs if you use 'calc'

Hello everybody!

If you use a Table inside Tabs component, and use 'calc' to determinate the height of the 'y' scroll, when you change Tabs, the tables that have height with calc will not render the rows.

Any idea why? If you use normal numeric values it works as expected.

To reproduce go to the link bellow and change between Tab 2 and 3 after scrolling the table a bit.

Reproduction link

Edit on CodeSandbox

不知能否加入当数据不超过一屏时不显示滚动条的功能

在配置使用VList之后,当我的数据量不多的时候,页面右侧也会显示滚动条,想问问大佬能否加入判断不超过一屏时不显示滚动条的功能(类似antd官方给的虚拟化列表的示例)?或者是有没有什么思路可以提供一下 感谢
image

如何兼容自定义的Table components?

我项目中自定义了components来实现表格的右键菜单:

const wrapperRender = (props: any) => <Dropdown overlay={contextMenu} trigger={['contextMenu']}><tbody {...props} /></Dropdown>;
const components = {
  body: {
    wrapper: wrapperRender,
  },
}

Table参数 components = {merge(VList({ height: tableHeight }), components)} // lodash/merge

这样的话虚拟列表会出bug,往下滚动的时候永远只显示开头的十几条数据,但是内容高度却在无限增长,滚不到底。

在codesandbox下使用下面这段代码,scrollTo有问题。

import React, { useState, useEffect } from "react";
import { render } from "react-dom";
import { Table, Input, Button } from "antd";
import { VList, scrollTo } from "virtuallist-antd";

import "./styles.css";
import "antd/dist/antd.css";

function App() {
const [dataSource, setDataSource] = useState([]);

useEffect(() => {
let tempDataSource = [];
for (let i = 0; i < 1000; i++) {
tempDataSource.push({
company_name: aaa${i} 富士山下的你好美 你知道吗,
company_name1: aaa${i} index index index index,
company_name2: aaa${i} company index index index,

    company_name3: `aaa${i} company company index index`,
    company_name4: `aaa${i} company company company index`,
    company_name5: `aaa${i} company company company company`,
    company_name6: `aaa${i} company index index company`
  });
}

setTimeout(() => {
  setDataSource(tempDataSource);
}, 2000);

}, []);

const columns = [
{
title: "序号",
key: "id",
fixed: "left",
render(text, record, index) {
return index + 1;
},
width: 100
},
{
title: "公司",
dataIndex: "company_name",
render(text, record, index) {
return
},
width: 200
},
{
title: "公司1",
dataIndex: "company_name1",
render(text, record, index) {
return
},
width: 200
},
{
title: "公司2",
dataIndex: "company_name2",
render(text, record, index) {
return
},
width: 200
}
];

return (
<>
<Button style={{ marginRight: 10 }} onClick={() => {
const tmpdataSource = [...dataSource];
tmpdataSource.push({company_name6: aaa${tmpdataSource.length + 1} company index index company});
setDataSource(tmpdataSource);
scrollTo({ row: tmpdataSource.length })
}
}>
scrollTo row: 30

<Button onClick={() => scrollTo({ y: 1000 })}>scrollTo y: 1000
<Table
columns={columns}
dataSource={dataSource}
pagination={false}
scroll={{ y: 500 }}
rowKey={"company_name"}
components={VList({
height: 500
})}
/>
</>
);
}

const rootElement = document.getElementById("root");
render(, rootElement);

使用 Ant-D 的<Dropdown>不会跟随滚动条上下移动

参考 ant-design 上的解决方法

  1. Dropdown 会跟随滚动条上下移动?
  2. <Select> API
    getPopupContainer
  3. getPopupContainer 示例

参考仓库中的示例,修改进行的尝试

... ...
const menu = (
    <Menu>
        <Menu.Item>
            <a target="_blank" rel="noopener noreferrer" href="https://www.antgroup.com">
                1st menu item
            </a>
        </Menu.Item>
        <Menu.Item disabled>
            <a target="_blank" rel="noopener noreferrer" href="https://www.aliyun.com">
                2nd menu item
            </a>
        </Menu.Item>
        <Menu.Item disabled>
            <a target="_blank" rel="noopener noreferrer" href="https://www.luohanacademy.com">
                3rd menu item
            </a>
        </Menu.Item>
        <Menu.Item danger>a danger item</Menu.Item>
    </Menu>
);

const columns: ColumnsType<RecordType> = [
    {
        title: "序号",
        key: "id",
        fixed: "left",
        render(text, record, index) {
            return index + 1;
        },
        width: 100
    },
    {
        title: "公司",
        dataIndex: "company_name",
        width: 200
    },
    {
        title: "公司1",
        dataIndex: "company_name1",
        width: 200
    },
    {
        title: "公司2",
        dataIndex: "company_name2",
        width: 200,
        render(text, record) {
            return <Dropdown
                overlay={menu}
                trigger={['click']}
                // @ts-ignore
                getPopupContainer={() => document.getElementById('wrap_tableRef')}
            >
                <a>{text}</a>
            </Dropdown>
        }
    }
];
...

其中document.getElementById('wrap_tableRef')id,是我自己在function VTable中的ref={wrap_tableRef}那边加上的。希望能提供相似的实现或者更好的解决方式,来支持getPopupContainer

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.