[英]How can I use a material-ui Popover with the actions of material-table in react?
I'm new on React
and this is my first page that I created, I'm using material-table
and material-ui
to help me.我是
React
新手,这是我创建的第一个页面,我使用material-table
和material-ui
来帮助我。
This is my code:这是我的代码:
import React, { useState, useEffect } from 'react';
import { Fade } from "@material-ui/core";
import MaterialTable from 'material-table';
import { makeStyles } from '@material-ui/core/styles';
import api from '../../services/api.js';
const useStyles = makeStyles(theme => ({
root: {
flexGrow: 1,
width: '70%',
margin: 'auto',
marginTop: 20,
boxShadow: '0px 0px 8px 0px rgba(0,0,0,0.4)'
}
}));
function User(props) {
const classes = useStyles();
const [checked, setChecked] = useState(false);
const [tableData, setTableData] = useState([]);
let config = {
columns: [
{ title: 'Name', field: 'name' },
{ title: 'Sector', field: 'sector' },
{ title: 'E-mail', field: 'email'},
{ title: 'Tel', field: 'tel'}
],
actions: [
{ icon: 'create', tooltip: 'Edit', onClick: (event, rowData) => alert('Edit')},
{ icon: 'lock', tooltip: 'Block', onClick: (event, rowData) => alert('Block')},
{ icon: 'delete', tooltip: 'Delete', onClick: (event, rowData) => alert('Delete') },
{ icon: 'visibility', tooltip: 'Last Access', onClick: (event, rowData) => alert('Last') },
{ icon: "add_box", tooltip: "Add", position: "toolbar", onClick: () => { alert('Add') } }
],
options: {
headerStyle: { color: 'rgba(0, 0, 0, 0.54)' },
actionsColumnIndex: -1,
exportButton: true,
paging: true,
pageSize: 10,
pageSizeOptions: [],
paginationType: 'normal'
},
localization: {
body: {
emptyDataSourceMessage: 'No data'
},
toolbar: {
searchTooltip: 'Search',
searchPlaceholder: 'Search',
exportTitle: 'Export'
},
pagination: {
labelRowsSelect: 'Lines',
labelDisplayedRows: '{from} to {to} {count} itens',
firstTooltip: 'First',
previousTooltip: 'Previous',
nextTooltip: 'Next',
lastTooltip: 'Last'
},
header: {
actions: 'Actions'
}
}
}
useEffect(() => {
setChecked(prev => !prev);
async function loadUsers() {
const response = await api.get('/users');
setTableData(response.data);
}
loadUsers();
}, [])
return (
<>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap" />
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons" />
<Fade in={checked} style={{ transitionDelay: checked ? '300ms' : '0ms' }}>
<div className={classes.root}>
<MaterialTable editable={config.editable} options={config.options} localization={config.localization} title="Usuários" columns={config.columns} data={tableData} actions={config.actions}></MaterialTable>
</div>
</Fade>
</>
);
}
export default User;
This code works, and list the users that I have on my database.此代码有效,并列出我的数据库中的用户。 My next step is create a
Popover
on actions Block
and Delete
to show to user a question to confirm if he really wanna delete or block the user on the line.我的下一步是在操作
Block
和Delete
上创建一个Popover
以向用户显示一个问题,以确认他是否真的想删除或阻止在线用户。 I have searched in documentation of material-ui
( https://material-ui.com/components/popover/ ) how can I use the Popover with my table, but I cannot do this.我在
material-ui
( https://material-ui.com/components/popover/ ) 的文档中搜索了如何在我的桌子上使用 Popover,但我不能这样做。 I think I cannot use this prop aria-describedby={id}
, but I don't know.我想我不能使用这个道具
aria-describedby={id}
,但我不知道。
Someone can help me to achieve this or help to find a way?有人可以帮助我实现这一目标或帮助找到方法吗?
I think you are not looking for a popover which is more like a small tooltip, but for a dialog, which needs attention from the user and blocks him from doing anything else.我认为您不是在寻找更像是小工具提示的弹出窗口,而是在寻找需要用户注意并阻止他做任何其他事情的对话框。
Material-UI has a dialog component. Material-UI 有一个对话框组件。 You place it somewhere in the code.
你把它放在代码中的某个地方。 If the property "open" is true it blocks the user from doing anything else but confirming/canceling the deletion.
如果属性“open”为真,它会阻止用户执行除确认/取消删除之外的任何其他操作。 If it set to false the dialog is not visible.
如果它设置为 false,则对话框不可见。
https://material-ui.com/components/dialogs/ https://material-ui.com/components/dialogs/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.