We have requirement where we need to show 'Hide/Show' columns feature on the header of table and also we want to provide different color to the header of table in ant design. Can anyone help me how can we do this? I did not find any control to do it as header rendering is completely internal to component.
You can use the <Table.Column title={<...any react node...>}>
attribute in combination with ordinary CSS.
What I tried to resolve the background colour issue of header is overwrite the ant style class as below
thead[class*="ant-table-thead"] th{
background-color: yellow !important;
}
I am not sure if this is the correct way of doing or not. antd should provide the property on Table to configure the header style.
Is there any other better way to do it?
className="xxx"
if you don't want to override antd's classes. –
Suggestibility You can use the <Table.Column title={<...any react node...>}>
attribute in combination with ordinary CSS.
The solution offered by kalpana did not work for me. What did work (Ant V4.10.x) was this:
thead > tr > th {
background-color: yellow;
}
Note that the !important
setting is not required to make this work.
Similarly, if you want to target the cells of the table, you can use:
tbody > tr > td {
background-color: yellow;
}
Late answer, but hopefully it helps someone.
If the styling you want to apply via className are one of headerBg, headerColor, headerBorderRadius, headerFilterHoverBg, headerSortActiveBg, headerSortHoverBg, headerSplitColor then you can use the Design token, either on your table alone, or globally so the style is applied across all table headers in your app.
import { ConfigProvider, Table } from 'antd'
<ConfigProvider
theme={{
components: {
Table: {
headerBg: '#fff' /* example, changes header background color to white */,
/* other properties: https://ant.design/components/table#design-token */
},
},
}}
>
<Table />
{/* or any other component that contains one or more Tables to apply styling to all tables within */}
</ConfigProvider>
Refer to https://ant.design/components/table#design-token for more details about the token, its description, type and default value.
Furthermore, there is showHeader
prop on the Table, that hides or shows the header row
If you wish to remove or add a column or update the title of the column (header), update the columns
array provided to the Table component accordingly.
© 2022 - 2025 — McMap. All rights reserved.