Skip to content

Commit 6bc5d17

Browse files
committed
fix table column size and horizontal scroll
Signed-off-by: Ricardo M G da Silva <[email protected]>
1 parent c31d82f commit 6bc5d17

File tree

2 files changed

+33
-42
lines changed

2 files changed

+33
-42
lines changed

src/components/TDViewer/base/BasePagination.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,11 @@ const BasePagination = <T,>({
6464
}, [filteredItems, totalPages, currentPage]);
6565

6666
return (
67-
<div>
68-
{/* Render the current items using the children function */}
69-
{children({ items: currentItems })}
67+
<div className="flex flex-col">
68+
<div className="overflow-x-auto">
69+
{/* Render the current items using the children function */}
70+
{children({ items: currentItems })}
71+
</div>
7072

7173
{/* Pagination controls */}
7274
{filteredItems.length > itemsPerPage && (

src/components/TDViewer/base/BaseTable.tsx

Lines changed: 28 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -76,20 +76,6 @@ const BaseTable = <T extends TableItem>({
7676
renderItem,
7777
placeholder,
7878
}: BaseTableProps<T>): JSX.Element => {
79-
const colWidth = useMemo(() => {
80-
const width = Math.floor(100 / headers.length);
81-
switch (width) {
82-
case 25:
83-
return "w-1/4";
84-
case 33:
85-
return "w-1/3";
86-
case 50:
87-
return "w-1/2";
88-
default:
89-
return "grow";
90-
}
91-
}, [headers.length]);
92-
9379
const filteredItems = useMemo(() => {
9480
const defaultFilterMethod = (filterValue: string) => (item: T) =>
9581
!filterValue?.trim() ||
@@ -241,6 +227,9 @@ const BaseTable = <T extends TableItem>({
241227
}
242228

243229
case "propName":
230+
let description = !item.description
231+
? "No description available"
232+
: item.description;
244233
return (
245234
<div
246235
className="flex h-full w-full items-center justify-center px-1"
@@ -255,7 +244,7 @@ const BaseTable = <T extends TableItem>({
255244
<div className="items-center justify-center px-1">
256245
<Icon
257246
id="info"
258-
html={`Property description: ${item.description}`}
247+
html={`Property description: ${description}`}
259248
IconComponent={Info}
260249
/>
261250
</div>
@@ -388,30 +377,30 @@ const BaseTable = <T extends TableItem>({
388377
return (
389378
<BasePagination items={orderedItems} itemsPerPage={itemsPerPage}>
390379
{({ items: paginatedItems }) => (
391-
<div className={`w-full ${className}`}>
392-
{/* Headers */}
393-
<div className="flex">
394-
{headers.map((header, index) => (
395-
<div
396-
key={`header-${header.key}`}
397-
className={`text-elevation-0-1 my-2.5 flex h-auto items-center text-center text-sm font-bold text-white ${
398-
index === 0
399-
? "justify-start pl-5"
400-
: index === headers.length - 1
401-
? "justify-end pr-5"
402-
: "justify-center"
403-
} `}
404-
style={{
405-
width: `${100 / headers.length}%`,
406-
wordWrap: "break-word",
407-
wordBreak: "break-word",
408-
whiteSpace: "normal",
409-
}}
410-
>
411-
<div>{header.text}</div>
412-
</div>
413-
))}
414-
</div>
380+
<div className="relative overflow-x-auto">
381+
<div className={`inline-block min-w-full ${className}`}>
382+
{/* Table Container */}
383+
<div
384+
className="grid"
385+
style={{
386+
gridTemplateColumns: `repeat(${headers.length}, minmax(150px, 1fr))`,
387+
}}
388+
>
389+
{/* Headers */}
390+
{headers.map((header, index) => (
391+
<div
392+
key={`header-${header.key}`}
393+
className={`text-elevation-0-1 my-2.5 flex items-center justify-center text-sm font-bold text-white ${
394+
index === 0
395+
? "pl-5"
396+
: index === headers.length - 1
397+
? "pr-5"
398+
: "px-5"
399+
}`}
400+
>
401+
{header.text}
402+
</div>
403+
))}
415404

416405
{/* Rows */}
417406
{paginatedItems.length > 0 ? (

0 commit comments

Comments
 (0)