React MUI Datagrid标题的顶部中央对齐

huangapple go评论60阅读模式
英文:

React MUI Datagrid Top Center Alignment for Headers

问题

我想通过sx来设置包裹的表头的对齐方式为顶部居中:

const datagridSx = {
    '& .MuiDataGrid-columnHeaders': {
        height: 'unset !important',
        maxHeight: '168px !important',
    },
    "& .MuiDataGrid-columnHeaderTitle": {
        whiteSpace: "normal",
        lineHeight: "normal",
        fontWeight: "bold",
        verticalAlign: "top"
    },
};

但它不起作用。有人可以帮助我吗?谢谢。

英文:

I would like to set the alignment of the wrapped headers as top-center via sx:

const datagridSx = {
    '& .MuiDataGrid-columnHeaders': {
        height: 'unset !important',
        maxHeight: '168px !important',
    },
    "& .MuiDataGrid-columnHeaderTitle": {
        whiteSpace: "normal",
        lineHeight: "normal",
        fontWeight: "bold",
        verticalAlign: "top"
    },
};

but it doesn't work. Could anyone help me, please? Thank you.

答案1

得分: 1

代替在.MuiDataGrid-columnHeaderTitle上使用verticalAlign: "top",您可以在.MuiDataGrid-columnHeaderTitleContainer上更改alignItems属性。

因此,您的sx看起来可能像这样:

const datagridSx = {
  ".MuiDataGrid-columnHeaderTitleContainer": {
    alignItems: "start",
  },
  "& .MuiDataGrid-columnHeaders": {
    height: "unset !important",
    maxHeight: "168px !important",
  },
  "& .MuiDataGrid-columnHeaderTitle": {
    whiteSpace: "normal",
    lineHeight: "normal",
    fontWeight: "bold",
  },
};
英文:

Instead of using the verticalAlign: "top" on the .MuiDataGrid-columnHeaderTitle you can change the alignItems property on the .MuiDataGrid-columnHeaderTitleContainer.

So your sx would look something like this:

const datagridSx = {
  ".MuiDataGrid-columnHeaderTitleContainer": {
    alignItems: "start",
  },
  "& .MuiDataGrid-columnHeaders": {
    height: "unset !important",
    maxHeight: "168px !important",
  },
  "& .MuiDataGrid-columnHeaderTitle": {
    whiteSpace: "normal",
    lineHeight: "normal",
    fontWeight: "bold",
  },
};

huangapple
  • 本文由 发表于 2023年7月27日 21:18:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/76780158.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定