Skip to content

Commit 3df9be8

Browse files
Index column height works.
1 parent 64af679 commit 3df9be8

File tree

5 files changed

+37
-19
lines changed

5 files changed

+37
-19
lines changed

src/components/Grid/Cell.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export const Cell = memo(
2020
rowHeight,
2121
rowStart,
2222
rowAutoHeight,
23+
getRowHeight
2324
} = data;
2425

2526
const currentRowIndex = rowIndex + rowStart;
@@ -57,9 +58,8 @@ export const Cell = memo(
5758

5859
const cellRef = useRef<HTMLDivElement>(null);
5960

60-
// useEffect(() => {
61-
// console.log("Current ref form cell: ", cellRef.current?.getBoundingClientRect().height)
62-
// })
61+
const currentHeight = getRowHeight(rowIndex);
62+
console.log(`Which is bigger, rowHeight ${rowHeight} or current height? ${currentHeight}`)
6363

6464
useEffect(() => {
6565
console.log("Current ref form cell: ", cellRef.current?.getBoundingClientRect().height)
@@ -69,11 +69,12 @@ export const Cell = memo(
6969
}
7070
}, [cellRef, data.updateRowHeight, rowIndex]);
7171

72+
console.log("Row height is: ", rowHeight)
7273
return (
7374
<div
7475
style={{
7576
...style,
76-
height: "max-content"
77+
height: "max-content",
7778
}}
7879
data-row={currentRowIndex}
7980
data-column={columnIndex}

src/components/Grid/Grid.tsx

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -213,15 +213,30 @@ export const Grid = forwardRef<HTMLDivElement, GridProps>(
213213
onCopyCallback,
214214
]);
215215

216+
216217
const rowHeightsRef = useRef(new Map());
217-
218+
219+
const getRowHeight = useCallback((index: number) => {
220+
// console.log(`GetRowHeight: from ref: ${rowHeightsRef.current.get(index)}`)
221+
if (rowHeightsRef.current.get(index)) {
222+
// console.log(`Returning ref: ${rowHeightsRef.current.get(index)}`)
223+
return rowHeightsRef.current.get(index) + 33;
224+
}
225+
// console.log("Returning rowHeight")
226+
return rowHeight;
227+
}, [rowHeight]);
218228

219229
const updateRowHeight = useCallback((rowIndex: number, height: number) => {
220230
console.log("Updating row height!");
221231
const prevHeight = rowHeightsRef.current.get(rowIndex) || 0;
232+
console.log("Previous row height", prevHeight);
222233
if (height > prevHeight) {
223234
rowHeightsRef.current.set(rowIndex, height);
224-
gridRef.current?.resetAfterRowIndex(rowIndex);
235+
console.log("Current height > prevheight", rowHeightsRef);
236+
if (gridRef.current) {
237+
gridRef.current.resetAfterRowIndex(rowIndex);
238+
console.log("Reset the grid");
239+
}
225240
}
226241
}, []);
227242

@@ -420,7 +435,8 @@ export const Grid = forwardRef<HTMLDivElement, GridProps>(
420435
rowNumberWidth,
421436
rowStart,
422437
rowAutoHeight,
423-
updateRowHeight
438+
updateRowHeight,
439+
getRowHeight
424440
};
425441

426442
const InnerElementType = forwardRef<HTMLDivElement, InnerElementTypeTypes>(
@@ -806,27 +822,24 @@ export const Grid = forwardRef<HTMLDivElement, GridProps>(
806822
// to fit content if there is only one row.
807823
useEffect(() => {
808824
if (gridRef.current) {
809-
gridRef.current.resetAfterRowIndex(0);
810-
console.log("Inner: ", innerCellRef.current?.scrollHeight)
811-
console.log("Bounding: ", innerCellRef.current?.scrollHeight)
825+
gridRef.current.resetAfterRowIndex(1);
826+
// console.log("Inner: ", innerCellRef.current?.scrollHeight)
827+
// console.log("Bounding: ", innerCellRef.current?.scrollHeight)
812828
}
813829
}, [rowCount]);
814830

815831

816832
const innerCellRef = useRef<HTMLDivElement>(null);
817833

818834
useEffect(() => {
819-
console.log("Inner: ", innerCellRef.current?.getBoundingClientRect().height)
835+
// console.log("Inner: ", innerCellRef.current?.getBoundingClientRect().height)
820836
if (innerCellRef.current) {
821837
// gridRef.current.resetAfterRowIndex(0);
822-
console.log("Is current")
838+
// console.log("Is current")
823839
}
824840
}, [onItemsRendered]);
825841

826-
const getRowHeight = useCallback((index: number) => {
827-
console.log(`GetRowHeight: from ref: ${rowHeightsRef.current.get(index)}`)
828-
return rowHeightsRef.current.get(index) || rowHeight;
829-
}, [rowHeight]);
842+
830843

831844

832845
// console.log("Inner ref? ", innerCellRef.current?.scrollHeight)

src/components/Grid/RowNumberColumn.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,17 @@ const RowNumberColumnContainer = styled.div<{
2323
const RowNumberCell = styled.div<{
2424
$height: number;
2525
$rowNumber: number;
26+
$rowAutoHeight?: boolean;
2627
}>`
2728
position: absolute;
2829
left: 0;
2930
overflow: hidden;
3031
text-overflow: ellipsis;
3132
white-space: nowrap;
3233
width: 100%;
33-
${({ $height, $rowNumber }) => `
34+
${({ $height, $rowNumber, $rowAutoHeight }) => `
3435
top: ${$height * $rowNumber}px;
35-
height: ${$height}px;
36+
height: ${$rowAutoHeight ? "100%" : `${$height}px`};
3637
`}
3738
`;
3839
interface RowNumberColumnProps {
@@ -87,6 +88,7 @@ const RowNumber = ({
8788
<RowNumberCell
8889
$rowNumber={rowIndex}
8990
$height={rowHeight}
91+
$rowAutoHeight={rowAutoHeight}
9092
>
9193
<StyledCell
9294
$height={rowHeight}

src/components/Grid/StyledCell.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ export const StyledCell = styled.div<{
3737
$showBorder,
3838
$rowAutoHeight,
3939
}) => `
40-
height: ${$rowAutoHeight ? "auto" : `${$height}px`};
40+
height: ${$rowAutoHeight ? "100%" : `${$height}px`};
41+
min-height: ${$rowAutoHeight ? "auto" : ""};
4142
overflow-y: ${$rowAutoHeight ? "auto" : "hidden"};
4243
background: ${theme.click.grid[$type].cell.color.background[$selectionType]};
4344
color: ${

src/components/Grid/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ export interface ItemDataType {
159159
rowStart: number;
160160
rowAutoHeight?: boolean;
161161
updateRowHeight: (rowIndex: number, height: number) => void;
162+
getRowHeight: (index: number) => number;
162163
}
163164

164165
export interface GridContextMenuItemProps extends Omit<ContextMenuItemProps, "children"> {

0 commit comments

Comments
 (0)