[英]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.