简体   繁体   English

如何控制 react-bootstrap-table-next 中的 boolean 字段

[英]How to Control boolean field in react-bootstrap-table-next

Suppose in an API I have a boolean value eg.假设在 API 我有一个 boolean 值,例如。 mission_status: true, or mission_status: false.任务状态:真,或任务状态:假。 And I use react-bootstrap-table2 to create table.我使用 react-bootstrap-table2 创建表。 Since it copies whatever data is there in the array of object into a table row.因为它将 object 数组中的任何数据复制到表行中。
I want to display "Success" in the Table if the mission_status is true and "Failure" if mission_status is false.如果mission_status 为真,我想在表中显示“成功”,如果mission_status 为假,则显示“失败”。 Right now it only displays true and false.现在它只显示真假。

const columns = [
    { dataField:"flight_number", text:"No." };
    { dataField:"mission_name", text:"Mission" },
    { dataField:"mission_status", text:"Mission Status" },
    { dataField:"rocket.rocket_name", text:"Rocket" }
]

And this is the jsx part:这是 jsx 部分:

<BootstrapTable 
            keyField="flight_number"
            data={launch}
            columns={columns}
            pagination={paginationFactory()}

        />

I want mission Status as "Success" if it is true in the table and vice-versa.如果表中为真,我希望任务状态为“成功”,反之亦然。
How to achieve it Please help??如何实现它请帮助?

You can use formatter to achieve that您可以使用formatter来实现这一点

// Add formatter properties to the cell
const columns = [
    ...,
    { 
        dataField:"mission_status", 
        text:"Mission Status", 
        formatter: statusFormatter 
    },
    ...
]

// Process the returned data in the formatter
function statusFormatter(cell, row, rowIndex, formatExtraData) {
    return cell ? 'Success' : 'Failure'
}

formatter will have 4 arguments available. formatter将有 4 个 arguments 可用。 cell is the data passed to the formatter, and row is the whole data object for that row. cell是传递给格式化程序的数据, row是该行的整个数据 object。

You can read more about it on the docs: https://react-bootstrap-table.github.io/react-bootstrap-table2/docs/column-props.html#columnformatter-function您可以在文档中了解更多信息: https://react-bootstrap-table.github.io/react-bootstrap-table2/docs/column-props.html#columnformatter-function

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

相关问题 React-Bootstrap-Table-Next 对动态表上的字母数字字符串进行排序 - React-Bootstrap-Table-Next Sort Alphanumeric Strings on Dynamic Table 如何在 react-bootstrap-table-next 表的列中显示倒计时? - How do I display countdowns in a column of a react-bootstrap-table-next table? 使用 react-bootstrap-table-next 时如何删除表的 header - how to remove the header of the table when using react-bootstrap-table-next 从 react-bootstrap-table-next 路由到新组件? - Routing to a new component from react-bootstrap-table-next? React-Bootstrap-Table-Next Search Bar onSearch 不是一个函数 - React-Bootstrap-Table-Next Search Bar onSearch is not a function 复选框在 react-bootstrap-table-next 中不起作用 - check boxes are not functioning in react-bootstrap-table-next 带有 mobx 商店的 react-bootstrap-table-next 不呈现更改 - react-bootstrap-table-next with mobx store doesn't render changes 如何将React JS中的普通表转换为使用React Bootstrap表 - How to convert normal table in react js to using react bootstrap table next 如何在引导程序中的输入字段旁边放置图标 - How to place icon next to input field in bootstrap 下一页和上一页在 react-bootstrap-table2-paginator 中不起作用 - next page and previous page not working in react-bootstrap-table2-paginator
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM