亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何隱藏 REACT 材料表中所有行中的列,并在我正在編輯的特定行的編輯和添加新行時顯示它?

如何隱藏 REACT 材料表中所有行中的列,并在我正在編輯的特定行的編輯和添加新行時顯示它?

瀟湘沐 2023-09-21 10:50:03
我正在使用 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" },    },我只想為我正在編輯的特定行以及添加的新行顯示它。
查看完整描述

1 回答

?
慕斯709654

TA貢獻1840條經驗 獲得超5個贊

您可以在密碼列定義上定義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 />

? ? )

? }

];

這樣,該字段不會被隱藏,但密碼只會在更新或創建期間顯示。


查看完整回答
反對 回復 2023-09-21
  • 1 回答
  • 0 關注
  • 136 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號