Skip to content

Commit db955f0

Browse files
committed
support variable row height in UITable
1 parent 09b6581 commit db955f0

3 files changed

Lines changed: 36 additions & 10 deletions

File tree

public/themes/basti.css

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
--radiobutton-size:20px;
6565
--tab-padding:0rem 1rem;
6666
--table-header-padding: 0.6rem 0.75rem;
67-
--table-cell-padding-top-bottom: 0.2rem;
67+
--table-cell-padding-top-bottom: 0.25rem;
6868
--table-cell-padding-left-right: 0.75rem;
6969
--table-data-height:27px;
7070
--label-padding:calc(var(--input-padding-tb) + var(--input-border-width));
@@ -308,6 +308,11 @@ body {
308308
padding: var(--table-cell-padding-top-bottom) var(--table-cell-padding-left-right) var(--table-cell-padding-top-bottom) var(--table-cell-padding-left-right);
309309
height: calc(8px + var(--table-data-height));
310310
}
311+
.basti .rc-table.variable-row-height .p-datatable-tbody > tr > td {
312+
min-height: calc(8px + var(--table-data-min-height));
313+
max-height: calc(8px + var(--table-data-max-height));
314+
height: auto;
315+
}
311316
.basti .rc-label > span {
312317
padding: var(--label-padding) 0px;
313318
}

src/main/components/table/UITable.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,11 @@
253253
&.cancel-padding {
254254
padding: var(--table-cell-padding-top-bottom, .2rem) var(--table-cell-padding-left-right, .4rem);
255255
}
256+
257+
@at-root .variable-row-height#{&} {
258+
min-height: var(--table-data-min-height);
259+
max-height: var(--table-data-max-height);
260+
}
256261
}
257262

258263
&.ChoiceCellEditor, &.CheckBoxCellEditor {

src/main/components/table/UITable.tsx

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -236,15 +236,28 @@ const UITable: FC<TableProps & IExtendableTable & IComponentConstants> = (props)
236236
const updateRowHeight = useCallback(() => {
237237
clearTimeout(updateRowHeightTimeout.current);
238238
updateRowHeightTimeout.current = window.setTimeout(() => {
239-
let max = 0;
240-
for(let v of cellHeights.current.values()) {
241-
max = Math.max(max, v);
239+
if (props.sameRowHeight === false && !props.rowHeight) {
240+
let sum = 0;
241+
for(let v of cellHeights.current.values()) {
242+
sum += v;
243+
}
244+
const mean = Math.ceil(sum / cellHeights.current.size);
245+
setRowHeight(negotiateRowHeight(
246+
props.minRowHeight,
247+
mean,
248+
props.maxRowHeight
249+
));
250+
} else {
251+
let max = 0;
252+
for(let v of cellHeights.current.values()) {
253+
max = Math.max(max, v);
254+
}
255+
setRowHeight(negotiateRowHeight(
256+
props.minRowHeight,
257+
max,
258+
props.maxRowHeight
259+
));
242260
}
243-
setRowHeight(negotiateRowHeight(
244-
props.minRowHeight,
245-
max,
246-
props.maxRowHeight
247-
));
248261
}, 1);
249262
}, [props.maxRowHeight])
250263

@@ -1030,7 +1043,7 @@ const UITable: FC<TableProps & IExtendableTable & IComponentConstants> = (props)
10301043
const isEditable = getCellIsEditable(rowData);
10311044
const elementRef = useRef<any>(null);
10321045
useEffect(() => {
1033-
if (tableInfo.rowIndex < 100 && props.sameRowHeight && !props.rowHeight) {
1046+
if (tableInfo.rowIndex < 100 && (props.sameRowHeight === true || props.sameRowHeight === false) && !props.rowHeight) {
10341047
const h = (elementRef.current?.querySelector('.cell-data-content').scrollHeight ?? 0) + 8;
10351048
const k = `${colName}-${tableInfo.rowIndex}`;
10361049
cellHeights.current.set(k, h);
@@ -1546,9 +1559,12 @@ const UITable: FC<TableProps & IExtendableTable & IComponentConstants> = (props)
15461559
ref={tableRef}
15471560
style={{
15481561
"--table-data-height": `${rowHeight - 8}px`,
1562+
...(props.minRowHeight ? {"--table-data-min-height": `${props.minRowHeight - 8}px`} : {}),
1563+
...(props.maxRowHeight ? {"--table-data-max-height": `${props.maxRowHeight - 8}px`} : {}),
15491564
} as React.CSSProperties}
15501565
className={concatClassnames(
15511566
"rc-table",
1567+
props.sameRowHeight === false && !props.rowHeight ? "variable-row-height" : '',
15521568
props.autoResize === false ? "no-auto-resize" : "",
15531569
getNavTableClassName(props.parent),
15541570
props.styleClassNames

0 commit comments

Comments
 (0)