Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(table): add support for configurable column size #45

Merged
merged 2 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/apsara-ui/src/TableV2/Table.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ const columns = [
title: "Age",
dataIndex: "age",
key: "age",
size: 20,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
size: 20,
width: 20,

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed

},
{
title: "Address",
Expand Down
20 changes: 17 additions & 3 deletions packages/apsara-ui/src/TableV2/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ function Table({
columnHelper.accessor(item.key, {
cell: item.render ? item.render : (info) => info.getValue(),
header: item.title ?? item.dataIndex,
size: item.size,
}),
);
});
Expand Down Expand Up @@ -145,14 +146,21 @@ function Table({
};

return (
<StyledTable className={`${alternate ? "alternate" : ""} ${alternateHover ? "alternate-hover" : ""}`} height={height}>
<StyledTable
className={`${alternate ? "alternate" : ""} ${alternateHover ? "alternate-hover" : ""}`}
height={height}
>
<TableWrapper className="apsara-table-content">
<table>
<thead>
{table.getHeaderGroups().map((headerGroup) => (
<tr key={headerGroup.id}>
{headerGroup.headers.map((header) => (
<th key={header.id} className="table-cell">
<th
key={header.id}
className="table-cell"
style={{ width: header.getSize() !== 150 ? header.getSize() : undefined }}
>
{header.isPlaceholder ? null : (
<div
style={{
Expand Down Expand Up @@ -201,7 +209,13 @@ function Table({
{table.getRowModel().rows.map((row) => (
<tr key={row.id} onClick={() => (rowClick ? rowClick(row) : "")}>
{row.getVisibleCells().map((cell) => (
<td key={cell.id}>
<td
key={cell.id}
style={{
width:
cell.column.getSize() !== 150 ? cell.column.getSize() : undefined,
}}
>
{flexRender(cell.column.columnDef.cell, cell.getContext())}
</td>
))}
Expand Down
18 changes: 16 additions & 2 deletions packages/apsara-ui/src/TableV2/VirtualisedTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ function VirtualisedTable({
columnHelper.accessor(item.key, {
cell: item.render ? item.render : (info) => info.getValue(),
header: item.title ?? item.dataIndex,
size: item.size,
}),
);
});
Expand Down Expand Up @@ -117,7 +118,11 @@ function VirtualisedTable({
{table.getHeaderGroups().map((headerGroup) => (
<tr key={headerGroup.id}>
{headerGroup.headers.map((header) => (
<th key={header.id} className="table-cell">
<th
key={header.id}
className="table-cell"
style={{ width: header.getSize() !== 150 ? header.getSize() : undefined }}
>
{header.isPlaceholder ? null : (
<div
style={{
Expand Down Expand Up @@ -178,7 +183,16 @@ function VirtualisedTable({
<tr key={row.id} onClick={() => (rowClick ? rowClick(row) : "")}>
{row.getVisibleCells().map((cell) => {
return (
<td key={cell.id} className="virtual-table-cell">
<td
key={cell.id}
className="virtual-table-cell"
style={{
width:
cell.column.getSize() !== 150
? cell.column.getSize()
: undefined,
}}
>
{flexRender(cell.column.columnDef.cell, cell.getContext())}
</td>
);
Expand Down