【问题标题】:How to add columns filter using react-bootstrap/table?如何使用 react-bootstrap/table 添加列过滤器?
【发布时间】:2021-06-16 09:06:13
【问题描述】:

我想添加对表格列进行排序/过滤的功能。在网上我找不到任何关于如何使用 react-bootstrap/table 来做到这一点的示例。

这是我的代码:

import React from 'react';
import 'bootstrap/dist/css/bootstrap.min.css';
import Table from 'react-bootstrap/Table';

export default class Success extends React.Component {
render() {
        return (
            <div className="container">         
                </div>
                <div className="row">
                    <Table striped bordered hover>
                      <thead>
                        <tr>
                          <th>#</th>
                          <th>Label</th>
                          <th>Text</th>
                          <th>Prediction</th>                                                                     
                          <th>Validation</th>
                        </tr>
                      </thead>
                      <tbody>
                        {Object.keys(this.state.jsondata.label).map(k =>
                            <tr>
                                <td>{k}</td>
                                <td>{this.state.jsondata.label[k]}</td>
                                                        
                                <td>{this.state.jsondata.prediction[k]}</td>
                                <td>
                                 <Button variant="danger" size="sm" onClick={() => { this.removeData(k) }}>Cancel<XOctagonFill/></Button>
                                </td>                                
                            </tr>
                        )}                  
                      </tbody>
                    </Table>
                </div>
            </div>
        )
    }
}

我找不到任何关于如何在不使用 react-bootstrap-table2 的情况下向列添加过滤器的资源,但是我需要修改我的整个项目

【问题讨论】:

标签: reactjs react-bootstrap react-bootstrap-table tablefilter


【解决方案1】:

我创建了一个关于如何根据列值过滤数组的非常小的示例。

您在th 中创建一个输入文本,然后将此值用作属性过滤器。 然后,您可以选择是否要基于相等或startsWithincludes 等进行字符串比较

请查看this sandbox

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-06
    相关资源
    最近更新 更多