[英]React Bootstrap Accordion on table
嗨,有人知道如何在反應桌上實現手風琴嗎? 我試圖在單擊標題(標簽)時隱藏我的整個表格。 謝謝你
<div class="Asalertpf1 block" >
<FormLabel className="btn-success d-flex justify-content-center m-0">
<h6 >PF1 AS Alert</h6>
</FormLabel>
<div >
<Table striped hover responsive >
<thead className="theadAS text-white thAS" >
<tr className="text-center" >
<th>Time</th>
<th>Job Name</th>
<th>Result</th>
<th>Alarm Switch</th>
</tr>
</thead>
</Table>
</div>
<div>
<p class="text-center font-weight-bold ">
Latest Update Time:
{new Date().toDateString()}
{new Date().toLocaleTimeString()}
</p>
</div>
</div>
基本上,您維護一個 state 說open
並在標題上有一個 onClick 並切換 state open
該示例使用沒有 styles 的簡單 div,但您明白了。
示例片段:
class App extends React.Component {
constructor() {
super();
this.state = {
data: makeData(),
open: true
};
}
toggleAccordian = () => {
this.setState(prev => ({ ...prev, open: !prev.open }));
};
render() {
const { data } = this.state;
return (
<div>
<div
style={{ background: "red", cursor: "pointer" }}
onClick={this.toggleAccordian}
>
toggle table
</div>
<div
style={{
margin: "20px",
display: this.state.open ? "block" : "none"
}}
>
<ReactTable
data={data}
columns={[
{
Header: "First Name",
accessor: "firstName",
className: "sticky",
headerClassName: "sticky"
},
......
同樣如評論中所述,如果您使用任何庫,則可以使用現成的手風琴
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.