简体   繁体   English

在反应虚拟化中的表数据之后添加自定义行

[英]Add custom rows after table data in react-virtualized

Im using react-virtualized table with Columns.我使用带有列的反应虚拟化表。 Its an existing table that I'm converting.它是我正在转换的现有表。 The table displays 100 rows at a time.该表一次显示 100 行。 At the bottom of the table is a button to load the next 100 rows.表格底部有一个按钮,用于加载接下来的 100 行。 I'm having trouble getting my button in the table.我在桌子上找不到按钮。 Its in an extra row with a conditional.它在带有条件的额外行中。 Cant figure out how to do that with the Column approach无法弄清楚如何使用 Column 方法做到这一点

I've tried displaying the table with Columns then adding an extra row at the bottom but that doesn't work.我试过用列显示表格,然后在底部添加一个额外的行,但这不起作用。

        <Table
          width={width}
          height={height}
        >
          <Column label="Name" dataKey="name" width={200} />
          <Column width={300} label="Description" dataKey="description" 
       />
          //extra custom row here with button to get more data
        </Table>

I know I can use the infinite loader but this table has existing functionality that I'm trying to reproduce我知道我可以使用无限加载器,但该表具有我正在尝试重现的现有功能

Recently I have faced a similar problem, after digging dipper in their documentation and experimenting a little bit I have found the solution, as you can see in code I have imported defaultTableRowRenderer from react-virtualized, this component is responsible for rendering your row based on row data.最近我遇到了类似的问题,在他们的文档中挖掘了 dipper 并进行了一些试验后,我找到了解决方案,正如您在代码中看到的,我从 react-virtualized 导入了defaultTableRowRenderer ,该组件负责基于行数据。

First I have provided the row count 1 more than the actual row count needs to render and首先,我提供的row count 1 more than the actual row count需要渲染的row count 1 more than the actual row count

then handled 2 more props然后再处理2个道具

  1. rowGetter : here for this extra row I am returning previous row data, you can return any data here, then I have handled the rowGetter : 对于这个额外的行,我返回前一行数据,你可以在这里返回任何数据,然后我已经处理了
  2. rowRenderer render props from Table and returning defaultTableRowRenderer for all index except this extra row where I am returning my custom UI with load more text rowRenderer从 Table 渲染道具并为所有索引返回defaultTableRowRenderer ,除了这个额外的行,我返回我的自定义 UI 并加载更多文本

import { Column, Table, defaultTableRowRenderer as DefaultRowRenderer } from "react-virtualized"; import { Column, Table, defaultTableRowRenderer as DefaultRowRenderer } from "react-virtualized";

const yourRowCount = 10; const yourRowCount = 10; //some value from props; //来自道具的一些值; const yourRowsData = []; const yourRowsData = []; //from props //来自道具

<Table
 width={width}
 height={height}
 rowCount={yourRowCount + 1}
 rowGetter={({ index }) => {
      if (index === yourRowCount.length) {
        index=index-1
      }
     return rows[index]
    }}
 rowRenderer={(props) => {
      if (props.index === yourRowCount.length) {
        return <div onClick={this.handleLoadMore}>Load More<div/>
      }
     return <DefaultRowRenderer {...props}></DefaultRowRenderer>;
    }}
>
   <Column label="Name" dataKey="name" width={200} />
   <Column width={300} label="Description" dataKey="description"/>
</Table>

Soon, I will create a Codepen/Codesnippet to see it working live很快,我将创建一个 Codepen/Codesnippet 来查看它的实时运行情况

References: https://github.com/bvaughn/react-virtualized/blob/master/docs/Table.md#rowrenderer参考资料: https : //github.com/bvaughn/react-virtualized/blob/master/docs/Table.md#rowrenderer

https://github.com/bvaughn/react-virtualized/blob/master/source/Table/defaultRowRenderer.js https://github.com/bvaughn/react-virtualized/blob/master/source/Table/defaultRowRenderer.js

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

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