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

line breaks in table cells #2525

Merged
merged 2 commits into from
Apr 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 7 additions & 2 deletions frontend/taipy-gui/packaging/taipy-gui.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ export interface ColumnDesc {
width?: number | string;
/** If true, the column cannot be edited. */
notEditable?: boolean;
/** The name of the column that holds the CSS classname to
/** The name of the column that holds the CSS className to
* apply to the cells. */
className?: string;
/** The name of the column that holds the tooltip to
Expand All @@ -383,13 +383,18 @@ export interface ColumnDesc {
apply?: string;
/** The flag that allows the user to aggregate the column. */
groupBy?: boolean;
widthHint?: number;
/** The list of values that can be used on edit. */
lov?: string[];
/** If true the user can enter any value besides the lov values. */
freeLov?: boolean;
/** If false, the column cannot be sorted */
sortable?: boolean;
/** The column headers if more than one. */
headers?: string[];
/** The index of the multi index if exists. */
multi?: number;
/** If true or not set, line breaks are transformed into <BR>. */
lineBreak?: boolean;
}
/**
* A cell value type.
Expand Down
32 changes: 27 additions & 5 deletions frontend/taipy-gui/src/components/Taipy/tableUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import React, {
MouseEvent,
ChangeEvent,
SyntheticEvent,
ReactNode,
} from "react";
import { FilterOptionsState } from "@mui/material";
import Autocomplete, { createFilterOptions } from "@mui/material/Autocomplete";
Expand Down Expand Up @@ -108,6 +109,8 @@ export interface ColumnDesc {
headers?: string[];
/** The index of the multi index if exists. */
multi?: number;
/** If true or not set, line breaks are transformed into <BR>. */
lineBreak?: boolean;
}

export const DEFAULT_SIZE = "small";
Expand Down Expand Up @@ -245,7 +248,13 @@ export const getSortByIndex = (cols: Record<string, ColumnDesc>) => (key1: strin
? 1
: cols[key1].index - cols[key2].index;

const formatValue = (val: RowValue, col: ColumnDesc, formatConf: FormatConfig, nanValue?: string): string => {
const formatValue = (
val: RowValue,
col: ColumnDesc,
formatConf: FormatConfig,
nanValue: string | undefined,
lineBreak: boolean = true
): ReactNode => {
if (val === undefined) {
return "";
}
Expand All @@ -262,7 +271,20 @@ const formatValue = (val: RowValue, col: ColumnDesc, formatConf: FormatConfig, n
}
return getNumberString(val as number, col.format, formatConf);
default:
return val ? (val as string) : "";
return val
? lineBreak && (col.lineBreak === undefined || col.lineBreak)
? (val as string).split("\n").map((p, i) =>
i == 0 ? (
p
) : (
<>
<br />
{p}
</>
)
)
: val
: "";
}
};

Expand All @@ -277,11 +299,11 @@ const defaultCursorIcon = { ...iconInRowSx, "& .MuiSwitch-input": defaultCursor
const getCellProps = (col: ColumnDesc, base: Partial<TableCellProps> = {}): Partial<TableCellProps> => {
switch (col.type) {
case "bool":
base = {...base, align: "center"};
base = { ...base, align: "center" };
break;
}
if (col.width) {
base = {...base, width: col.width};
base = { ...base, width: col.width };
}
return base;
};
Expand Down Expand Up @@ -577,7 +599,7 @@ export const EditableCell = (props: EditableCellProps) => {
title={
tooltip || comp
? `${tooltip ? tooltip : ""}${
comp ? " " + formatValue(comp as RowValue, colDesc, formatConfig, nanValue) : ""
comp ? " " + formatValue(comp as RowValue, colDesc, formatConfig, nanValue, false) : ""
}`
: undefined
}
Expand Down
Loading