Skip to content

Commit

Permalink
feat(table): add support for configurable column size (#45)
Browse files Browse the repository at this point in the history
* feat(table): add support for configurable column size

* chore: resolve comments
  • Loading branch information
abhishekv24 authored Jun 4, 2024
1 parent 790afc4 commit 2da148d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
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",
width: 20,
},
{
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.width,
}),
);
});
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

0 comments on commit 2da148d

Please sign in to comment.