DataGrid 分页在具有 dir=”rtl” 的容器中无法右对齐。

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

DataGrid pagination not aligning to the right in container with dir="rtl"

问题

试图在具有 dir="rtl" 的容器中使用 Material-UI 创建带有分页的 DataGrid。我已自定义分页组件以对齐容器的右侧,但效果不如预期。

这里有一个 codeSandBox 示例

我已经定义了 Box dir="rtl"。当我运行代码时,分页组件对齐到容器的左侧。

如何使分页组件出现在容器的右侧,同时仍然使用 dir="rtl"?

英文:

I'm trying to create a DataGrid with pagination using Material-UI in a container with dir="rtl". I've customized the pagination component to be aligned to the right side of the container, but it's not working as expected.

Here's a example In codeSandBox

I've defined Box dir="rtl". when I run the code, the pagination component is aligned to the left side of the container.

How can I make the pagination component appear on the right side of the container, while still using dir="rtl"?

答案1

得分: 2

你需要修改你的 CustomPagination 组件,将其对齐到右侧。

在你的 CodeSandbox 中,我只是在 <div> 中添加了 style={{ display: "flex", width: "100%" }}>,并在 <Pagination> 中添加了 sx={{ ml: "auto" }} 以使其生效。

function CustomPagination() {
 const apiRef = useGridApiContext();
 const page = useGridSelector(apiRef, gridPageSelector);
 const pageCount = useGridSelector(apiRef, gridPageCountSelector);

   return (
       <div dir="ltr" style={{ display: "flex", width: "100%" }}>
          <Pagination
            color="primary"
            count={pageCount}
            page={page + 1}
            onChange={(event, value) => apiRef.current.setPage(value - 1)}
            sx={{ ml: "auto" }}
          />
       </div>
    );
}
英文:

You need to modify your CustomPagination component to align it to the right side.

In your codesandbox, I just added style={{ display: "flex", width: "100%" }}> in the <div> and sx={{ ml: "auto" }} in the <Pagination> to make it work.

 function CustomPagination() {
 const apiRef = useGridApiContext();
 const page = useGridSelector(apiRef, gridPageSelector);
 const pageCount = useGridSelector(apiRef, gridPageCountSelector);

   return (
       <div dir="ltr" style={{ display: "flex", width: "100%" }}>
          <Pagination
            color="primary"
            count={pageCount}
            page={page + 1}
            onChange={(event, value) => apiRef.current.setPage(value - 1)}
            sx={{ ml: "auto" }}
          />
       </div>
    );
}

huangapple
  • 本文由 发表于 2023年2月23日 23:28:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/75546915.html
匿名

发表评论

匿名网友

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

确定