[英]Onclick with Button in Material-Table
Hi!你好! Could you help me how to click Button => it will change to other component (Checkdetail) When i click button xet duyet.
您能帮我如何单击按钮 => 当我单击按钮 xet duyet 时,它将更改为其他组件(Checkdetail)。 But it
但它
not display the content of Checkdetail.不显示 Checkdetail 的内容。 Please give me solution for
请给我解决方案
this problem!这个问题! Thank you so much!
太感谢了!
I have added some code and modified several parts of it, but the post cannot be submitted.我已经添加了一些代码并修改了其中的几个部分,但是无法提交帖子。 Checkdetail
检查详情
//CheckDoc.js //CheckDoc.js
import React from 'react';
import MaterialTable , { MTableAction } from 'material-table';
import {Button} from '@material-ui/core/';
import { useHistory } from "react-router-dom";
import Checkdetail from './Checkdetail.js';
export default function CheckDoc() {
const [state, setState] = React.useState({
columns: [
{ title: "Ngày nộp đơn", field: "date" },
{ title: "Tên Văn bản", field: "namedoc" },
{ title: "Người nộp", field: "nameapplier" }
],
data: [
{ date: "20/2/02/2020", namedoc: "Báo Cáo", nameapplier: "Trinh Huynh" },
{ date: "20/2/02/2020", namedoc: "Báo Cáo", nameapplier: "Hua Thu" },
{ date: "20/2/02/2020", namedoc: "Báo Cáo", nameapplier: "Nhat Huynh" },
{ date: "20/2/02/2020", namedoc: "Báo Cáo", nameapplier: "Thanh Tran" },
{ date: "20/2/02/2020", namedoc: "Báo Cáo", nameapplier: "Van Kiet" },
{ date: "20/2/02/2020", namedoc: "Báo Cáo", nameapplier: "Phuc Hau" }
]
});
const history = useHistory();
const routeChange = () => {
let path = "Checkdetail";
history.push(path);
};
const { useState } = React;
const [selectedRow, setSelectedRow] = useState(null);
return (
<MaterialTable
// format some options
options={{
search: true,
rowStyle: rowData => ({
backgroundColor:
selectedRow === rowData.tableData.id ? "#C2D6EE" : "#FFF"
}),
headerStyle: {
backgroundColor: "default ",
color: "#111"
},
actionsColumnIndex: -1
}}
localization={{
header: {
actions: "Trạng Thái"
},
toolbar: {
searchTooltip: "Search",
searchPlaceholder: "Tìm kiếm..."
}
}}
// Button checked
actions={[
{
icon: "save",
tooltip: "Save User"
}
]}
components={{
Action: props => (
<Button
color="secondary"
variant="contained"
style={{ maxWidth: "75px", maxHeight: "50px" }}
size="small"
onClick={routeChange}
>
Xét duyệt
</Button>
)
}}
title="Xét duyệt"
columns={state.columns}
data={state.data}
/>
);
}
//Checkdetail.js //检查detail.js
export default function Checkdetail() {
return (
<div className="row">
<div className="col col-lg-7">
<form>
<img
id="img_resize"
src="assets/img/bao-cao-tong-ket-cong-tac-nam-1.png"
/>
<button className="btn btn-primary" id="btn_checked" type="button">
Duyệt
</button>
<button className="btn btn-primary" id="btn_cancel" type="button">
Huy
</button>
</form>
</div>
<div
className="col col-lg-5"
src="assets/img/bao-cao-tong-ket-cong-tac-nam-1.png"
>
<form>
<div className="form-group">
<label>
Tên văn bản:
<input
className="form-control"
type="text"
id="input_note"
placeholder="Báo cáo tổng kết cuối năm"
/>
</label>
</div>
<div className="form-group">
<label>
Ngày nộp:
<input
className="form-control"
type="text"
id="input_note"
placeholder="23/05/2020"
/>
</label>
</div>
<div className="form-group">
<label>Ghi chú </label>
<textarea className="form-control" defaultValue={""} />
</div>
<button className="btn btn-primary" id="btn_checked" type="button">
Luu
</button>
</form>
</div>
</div>
);
}
Assuming you have a Router
correctly setup in your app somewhere, and a Route
with, I'll assume, a path="/checkdetail"
, then you need to push to that same path.假设您在某处的应用程序中正确设置了
Router
,并且我假设Route
带有path="/checkdetail"
,那么您需要推送到相同的路径。
So, given some route所以,给定一些路线
<Route path="/checkdetail" component={Checkdetail} />
Then you can push a new route to "/checkdetail"然后你可以将新路由推送到“/checkdetail”
const routeChange = () => history.push("/checkdetail");
How you attached the callback to the button is ok.您如何将回调附加到按钮是可以的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.