如何将Antd表格头部中的排序和搜索按钮移动到右侧?

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

How to move the sort and search buttons to the right in Antd Table header?

问题

在Antd表格中,我想将排序和搜索按钮移动到表格头部的右侧。默认情况下,这些按钮出现在表头的左侧。我已经尝试在Antd文档中找到解决方案,但未找到相关信息。

如何将Antd表格头部中的排序和搜索按钮位置移到右侧?是否有内置选项可以实现这一点,还是需要覆盖默认的CSS样式?任何帮助或指导将不胜感激。

我可以通过类名和样式更新边框半径和边框,但由于某些原因,无法在我的代码库中进行更新,更改不会反映出来。ant-table类无法通过内联CSS或类名来覆盖。因此,我希望通过ConfigProvider来进行更改。如何实现这一点?

<Table
  columns={employeeColumns}
  dataSource={dataSource}
  loading={isLoading}
  rowKey={key}
  {...params}
/>
英文:

I am using Antd Table in my React application and I would like to move the sort and search buttons to the right side of the Table header. By default, these buttons appear on the left side of the header. I have tried to find a solution in the Antd documentation but couldn't find anything relevant.

How can I change the position of the sort and search buttons in the Antd Table header to the right side? Is there a built-in option to do this or do I need to override the default CSS styles? Any help or guidance would be greatly appreciated.

I can update border radius and border with className and style but due to some reasons I can't update it in my codebase, the changes doesn't reflect. The ant-table class can't be overwritten neither with inline CSS nor with className. So I am looking forward to change it through ConfigProvider. How do I make it happen?

&lt;Table
  columns={employeeColumns}
  dataSource={dataSource}
  loading={isLoading}
  rowKey={key}
  {...params}
/&gt;

答案1

得分: 1

你可以简单地使用 antdSpace 组件,或者甚至一个简单的 <div> 来包裹你的按钮,然后使用 flex 并设置 justifyContent: "end"

<div>
  <Space
    style={{
      marginBottom: 16,
      display: "flex",
      justifyContent: "end",
    }}
  >
    <div>
      <Button onClick={setAgeSort}>Sort age</Button>
      <Button onClick={clearFilters}>Clear filters</Button>
      <Button onClick={clearAll}>Clear filters and sorters</Button>
    </div>
  </Space>
  <Table columns={columns} dataSource={data} onChange={handleChange} />
</div>;
英文:

you can simply use the Space component of antd or even a simple &lt;div&gt; to wrapp your buttons within it, then use flex and make justifyContent: &quot;end&quot; :

&lt;div&gt;
  &lt;Space
    style={{
      marginBottom: 16,
      display: &quot;flex&quot;,
      justifyContent: &quot;end&quot;,
    }}
  &gt;
    &lt;div&gt;
      &lt;Button onClick={setAgeSort}&gt;Sort age&lt;/Button&gt;
      &lt;Button onClick={clearFilters}&gt;Clear filters&lt;/Button&gt;
      &lt;Button onClick={clearAll}&gt;Clear filters and sorters&lt;/Button&gt;
    &lt;/div&gt;
  &lt;/Space&gt;
  &lt;Table columns={columns} dataSource={data} onChange={handleChange} /&gt;
&lt;/div&gt;;

huangapple
  • 本文由 发表于 2023年3月12日 10:42:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/75710794.html
匿名

发表评论

匿名网友

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

确定