简体   繁体   English

如何在所有行中隐藏 REACT 材料表上的列,并在我正在编辑的特定行的编辑上显示它,并在新行添加时添加操作?

[英]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?

I am working with React Material Table.我正在使用 React Material Table。 Please assist I need to hide a Password column Heading and fields by default in all rows and show it on Edit for a particular row and have it also for Adding new row.请协助我需要在所有行中默认隐藏密码列标题和字段,并将其显示在特定行的编辑中,并将其用于添加新行。 I used the property hidden: true but I am unable to show it for a particular row I am editing only, maybe I could also display it with just stars like: -我使用了属性hidden: true但我无法为我正在编辑的特定行显示它,也许我也可以只用星号显示它:-

Password
********

But I am unable to do so.但我无法这样做。 Here's my code below so far:-到目前为止,这是我的代码:-

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" },
    },

I would like to show it only for specific row I am editing and also on new row being added.我只想为我正在编辑的特定行以及正在添加的新行显示它。

You could define editComponent and render props on the password column definition, likes this:您可以在密码列定义上定义editComponentrender道具,如下所示:

  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 />
    )
  }
];

This way the field won't be hidden but the passwords will only be shown during update or creation.这样该字段不会被隐藏,但密码只会在更新或创建期间显示。 Link to working sandbox here . 在此处链接到工作沙箱。

编辑密码字段

You can use a state and pass it to hidden.您可以使用 state 并将其传递给隐藏。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM