[英]Open a dialog on row selection [material-table]
Is there a way to open a details dialog when clicking on a specific row of the table.单击表格的特定行时,是否可以打开详细信息对话框。 The issue is regarding material-table ( https://material-table.com/ ).
问题是关于材料表( https://material-table.com/ )。 Thanks in advance!
提前致谢! :)
:)
There isn't a native solution to display a popup like you want with material-table.没有本地解决方案可以像您想要的那样使用材料表显示弹出窗口。 But you can achieve this.
但是你可以做到这一点。
You have a props in MaterialTable called onRowClick.您在 MaterialTable 中有一个名为 onRowClick 的道具。
<MaterialTable onRowClick={(evt, selectedRow) => yourFunction(selectedRow)} />
Using this props you can define your own function to open a popper ( https://material-ui.com/components/popper/ ) or whatever popup type component you want on row click and display the informations of the selected Table row in it.使用这个道具,你可以定义你自己的函数来打开一个弹出窗口( https://material-ui.com/components/popper/ )或任何你想要的弹出类型组件,点击行并在其中显示所选表格行的信息.
That way you can even make a request to get more details info with the id you get to display even more details info !这样,您甚至可以使用显示更多详细信息的 id 请求获取更多详细信息!
Exemple:例子:
const alertMyRow = (selectedRow) => (
// here i can request something on my api with selectedRow.id to get additional
// datas which weren't displayed in the table
alert(`name: ${selectedRow.name}, surname: ${selectedRow.surname}`);
);
return(){
render(
<MaterialTable
columns={[
{ title: 'ID', field:'id' },
{ title: 'Name', field: 'name' },
{ title: 'Surname', field: 'surname' },
{ title: 'Phone Number', field: 'phone' },
]}
datas={[...]}
onRowClick={(evt, selectedRow) => alertMyRow(selectedRow)}
/>
)
);
Don't hesitate if i wasn't clear enough ;)如果我不够清楚,请不要犹豫;)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.