[英]Fixed Column in React-Table
I'm using an excellent data table library for React:我正在为 React 使用一个出色的数据表库:
https://react-table.js.org/ https://react-table.js.org/
My only issue is that I need to "freeze" the first (left most) column so that it's always in "view" when a user is scrolling sideways to view the other columns.我唯一的问题是我需要“冻结”第一列(最左侧),以便在用户侧向滚动以查看其他列时它始终处于“视图”状态。 I've poured over the documentation and didn't find any references, so I don't think there is a way to do this without hacking up the source code.
我翻遍了文档并没有找到任何参考资料,所以我认为没有办法在不破解源代码的情况下做到这一点。
This issue has been temporarily resolved with an external library:此问题已通过外部库暂时解决:
https://guillaumejasmin.github.io/react-table-hoc-fixed-columns/ https://guillaumejasmin.github.io/react-table-hoc-fixed-columns/
Example:示例:
import createTable from 'react-table-hoc-fixed-columns';
const ReactTableFixedColumns = createTable(ReactTable);
class MyComponent extends React.Component {
...
...
...
render(){
<ReactTableFixedColumns
data={this.state.data}
// Fixed Column(s)
columns = {[
{
Header: "Name",
id: "name_id",
fixed: true,
accessor: d => d.name,
},
// Scrollable Column(s)
{columns: [
{
Header: "Address",
id: "address_id",
accessor: d => d.address,
},
.
.
.
]}
]}
without using react-table or any npm dependencies fixed column can be achieved only via css tricks with in react app. 不使用react-table或任何npm依赖项固定列只能通过react app中的css技巧来实现。
Find the full code Here 在这里找到完整的代码
Step 1 : divide the dataset of fixed and scrollable columns 步骤1:划分固定列和滚动列的数据集
Step 2 : place two tables side by side in such a way that it looks as single table 第2步:以看起来像单个表的方式并排放置两个表
Step 3 : Wrap both with a single div and use a fixed width, give fixed width or responsive width for second one and make overflow-x: scroll; 第3步:将两个div都包裹起来,并使用固定宽度,为第二个宽度赋予固定宽度或响应宽度,然后使之溢出-x:滚动; so that it keeps scrolling horizontally,while first tables columns will not be scrollable
因此它会保持水平滚动,而第一个表格列将无法滚动
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.