Skip to content
Closed
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
7 changes: 3 additions & 4 deletions frontend/src/components/data-table/data-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ interface DataTableProps<TData> extends Partial<ExportActionProps> {
wrapperClassName?: string;
className?: string;
maxHeight?: number;
width?: "auto" | "full";
columns: ColumnDef<TData>[];
data: TData[];
rawData?: TData[]; // raw data for filtering/copying (present only if format_mapping is provided)
Expand Down Expand Up @@ -135,6 +136,7 @@ const DataTableInternal = <TData,>({
wrapperClassName,
className,
maxHeight,
width = "full",
columns,
data,
rawData,
Expand Down Expand Up @@ -384,10 +386,7 @@ const DataTableInternal = <TData,>({
</Banner>
)}
<Table
className={cn(
"relative",
columns.length <= AUTO_WIDTH_MAX_COLUMNS ? "w-auto" : "w-full",
)}
className={cn("relative", width === "auto" ? "w-auto" : "w-full")}
ref={tableRef}
>
{showLoadingBar && (
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/plugins/impl/DataTablePlugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ interface Data<T> {
pagination: boolean;
pageSize: number;
maxHeight?: number;
width?: "auto" | "full";
selection: DataTableSelection;
showDownload: boolean;
showFilters: boolean;
Expand Down Expand Up @@ -280,6 +281,7 @@ export const DataTablePlugin = createPlugin<S>("marimo-table")
maxColumns: z.union([z.number(), z.literal("all")]).default("all"),
hasStableRowId: z.boolean().default(false),
maxHeight: z.number().optional(),
width: z.enum(["auto", "full"]).default("full"),
cellStyles: z
.record(z.string(), z.record(z.string(), z.object({}).passthrough()))
.optional(),
Expand Down Expand Up @@ -861,6 +863,7 @@ const DataTableComponent = ({
getRow,
cellId,
maxHeight,
width,
}: DataTableProps<unknown> &
DataTableSearchProps & {
data: unknown[];
Expand Down Expand Up @@ -1120,6 +1123,7 @@ const DataTableComponent = ({
columns={columns}
className={className}
maxHeight={maxHeight}
width={width}
sorting={sorting}
totalRows={totalRows}
sizeBytes={sizeBytes}
Expand Down
5 changes: 5 additions & 0 deletions marimo/_plugins/ui/_impl/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,9 @@ def hover_cell(rowId, columnName, value):
max_height (int, optional): Maximum height of the table body in pixels. When set,
the table becomes vertically scrollable and the header will be made sticky
in the UI to remain visible while scrolling. Defaults to None.
width (Literal["auto", "full"], optional): Width behavior of the table.
"auto" uses minimum width needed for columns (good for few columns with short data).
"full" fills the available width (default, good for most cases).
label (str, optional): A descriptive name for the table. Defaults to "".
"""

Expand Down Expand Up @@ -581,6 +584,7 @@ def __init__(
style_cell: Callable[[str, str, Any], dict[str, Any]] | None = None,
hover_template: str | Callable[[str, str, Any], str] | None = None,
max_height: int | None = None,
width: Literal["auto", "full"] = "full",
# The _internal_* arguments are for overriding and unit tests
# table should take the value unconditionally
_internal_column_charts_row_limit: int | None = None,
Expand Down Expand Up @@ -859,6 +863,7 @@ def __init__(
"max-height": int(max_height)
if max_height is not None
else None,
"width": width,
},
on_change=on_change,
functions=(
Expand Down
Loading