[英]How to hide a column on REACT Material table in all rows and show it on Edit for the Particular Row I am editing and Add Operations on new row adding?
我正在使用 React Material Table。 請協助我需要在所有行中默認隱藏密碼列標題和字段,並將其顯示在特定行的編輯中,並將其用於添加新行。 我使用了屬性hidden: true但我無法為我正在編輯的特定行顯示它,也許我也可以只用星號顯示它:-
Password
********
但我無法這樣做。 到目前為止,這是我的代碼:-
const [columns, setColumns] = useState<any>([
{
title: "Username",
field: "username",
draggable: false,
cellStyle: { textAlign: "left" },
},
{
title: "Password",
field: "password",
hidden: true,
draggable: false,
cellStyle: { textAlign: "left" },
},
我只想為我正在編輯的特定行以及正在添加的新行顯示它。
您可以在密碼列定義上定義editComponent
和render
道具,如下所示:
const tableColumns = [
// ..other columns
{
title: "Password",
field: "password",
editComponent: ({ value, onChange }) => (
<input
type="text"
value={value || ""}
onChange={(e) => onChange(e.target.value)}
/>
),
render: (rowData) => (
<input
type="password"
value={rowData.password}
readOnly />
)
}
];
這樣該字段不會被隱藏,但密碼只會在更新或創建期間顯示。 在此處鏈接到工作沙箱。
您可以使用 state 並將其傳遞給隱藏。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.