Dee*_*eep 5 reactjs material-ui
我正在使用 MaterialTable 并想要屏蔽列值,但我无法这样做。
你能帮忙吗?
我正在使用 MaterialTable 向用户展示应用程序。
import MaterialTable from "material-table";
function UserProfile() {
const [state, setState] = React.useState({
columns: [
{ title: "Logging Name", field: "name" },
{
title: "password",
field: "password",
}
],
data: [
{
name: "Dan",
password: "TopseCrets@1"
}]
return (
<div style={{ maxWidth: "100%" }}>
<MaterialTable
title="User List"
columns={state.columns}
data={state.data}
.
.
.
);
I want to see ***** instead of password for the corresponding field, password string should be displayed only when I try to edit the row.
Run Code Online (Sandbox Code Playgroud)
小智 1
目前,material-table 不支持自定义密码字段。
我能够在https://gitter.im/material-table/Lobby?at=5ebbf9c82cf0da0ad9fda27c(material-table 的聊天大厅)上抢救解决方案
简而言之,您的密码列,您想要添加其他属性(render 和 editComponent):
{
title: 'Password', field: 'password',
render: rowData => <p>{rowData.password.split('').map(() => '*')}</p>,
editComponent: props => (
<TextField
type="password"
value={props.value}
onChange={e => props.onChange(e.target.value)}
/>)
},
Run Code Online (Sandbox Code Playgroud)
render 属性将在显示字段时替换字符。
editComponent 将使用您自己的 TextField 组件,并输入“password”以在编辑行时隐藏该值。
| 归档时间: |
|
| 查看次数: |
1564 次 |
| 最近记录: |