reactjs中如何让材质数据网格宽度填充父组件

Vik*_*rya 1 datagrid reactjs material-ui

我正在尝试显示所有列的数据网格应该采用相等的宽度以适合父组件。但是最后有一个空白空间,我无法删除它,也无法使列采用自动宽度以适应页面宽度。

任何人都可以帮我解决这个问题吗

https://codesandbox.io/s/musing-montalcini-tn04y

在此处输入图片说明

小智 34

就我而言,我包括了 flex 和 minWidth 属性,这有助于表在SM(小型)(XS)超小型设备中显示完整数据。

const columns = [
    {field: "id", hide: true},
    {field: "transaction", headerName: "Transactions", minWidth: 330, flex: 1},
    {field: "date", headerName: "Date", minWidth: 100, flex: 1},
    {field: "type", headerName: "Type", minWidth: 100, flex: 1},
    {field: "price", headerName: "Price", minWidth: 110, flex: 1},
    {field: "gas", headerName: "Gas", minWidth: 110, flex: 1},
    {field: "total", headerName: "Total", minWidth: 110, flex: 1} ]
Run Code Online (Sandbox Code Playgroud)


Sar*_* UK 5

包括每个列级别的弹性值,如下所示,

const columns = [
  { field: "id", headerName: "ID", flex: 1 },
  { field: "firstName", headerName: "First name", flex: 1 },
  { field: "lastName", headerName: "Last name", flex: 1 },
  {
    field: "age",
    headerName: "Age",
    type: "number",
    flex: 1
  },
  {
    field: "fullName",
    headerName: "Full name",
    description: "This column has a value getter and is not sortable.",
    sortable: false,
    flex: 1,
    valueGetter: (params) =>
      `${params.getValue(params.id, "firstName") || ""} ${
        params.getValue(params.id, "lastName") || ""
      }`
  }
];
Run Code Online (Sandbox Code Playgroud)

代码和盒子 - https://codesandbox.io/s/dry-https-7pp93?file=/src/App.js:266-850

  • 你能补充一下这是什么意思吗?flex:1 做什么?弹性是做什么的?只是从你的回答中还不清楚。谢谢 (2认同)