Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
24 changes: 17 additions & 7 deletions js/dataframe/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ interface ShinyDataGridProps<TIndex> {
const ShinyDataGrid: FC<ShinyDataGridProps<unknown>> = (props) => {
const { id, data, bgcolor } = props;
const { columns, type_hints, data: rowData } = data;
const { width, height, filters: withFilters } = data.options;
const { width, height, fill, filters: withFilters } = data.options;

const containerRef = useRef<HTMLDivElement>(null);
const theadRef = useRef<HTMLTableSectionElement>(null);
Expand Down Expand Up @@ -213,10 +213,13 @@ const ShinyDataGrid: FC<ShinyDataGridProps<unknown>> = (props) => {

const headerRowCount = table.getHeaderGroups().length;

const scrollingClass =
containerRef.current?.scrollHeight > containerRef.current?.clientHeight
? "scrolling"
: "";
// Assume we're scrolling until proven otherwise
let scrollingClass = "scrolling";
const scrollHeight = containerRef.current?.scrollHeight;
const clientHeight = containerRef.current?.clientHeight;
if (scrollHeight && clientHeight && scrollHeight <= clientHeight) {
scrollingClass = "";
}

const makeHeaderKeyDown =
(column: Column<unknown[], unknown>) => (event: React.KeyboardEvent) => {
Expand All @@ -227,12 +230,17 @@ const ShinyDataGrid: FC<ShinyDataGridProps<unknown>> = (props) => {

const measureEl = useVirtualizerMeasureWorkaround(rowVirtualizer);

let className = `shiny-data-grid ${containerClass} ${scrollingClass}`;
if (fill) {
className += " html-fill-item";
}

return (
<>
<div
className={`shiny-data-grid ${containerClass} ${scrollingClass}`}
className={className}
ref={containerRef}
style={{ width, maxHeight: height, overflow: "auto" }}
style={{ width, height, overflow: "auto" }}
>
<table
className={tableClass + (withFilters ? " filtering" : "")}
Expand Down Expand Up @@ -476,6 +484,8 @@ export class ShinyDataFrameOutput extends HTMLElement {

const myDiv = document.createElement("div");
myDiv.classList.add("html-fill-container", "html-fill-item");
myDiv.style.marginLeft = "auto";
myDiv.style.marginRight = "auto";
target.appendChild(myDiv);

this.reactRoot = createRoot(myDiv);
Expand Down
5 changes: 5 additions & 0 deletions js/dataframe/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@

.shiny-data-grid {
max-width: 100%;
height: 500px;
&:not(.scrolling) {
height: auto;
flex-basis: 500px;
}

> table {
border-collapse: separate;
Expand Down
1 change: 1 addition & 0 deletions js/dataframe/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface DataGridOptions {
filters?: boolean;
width?: string;
height?: string;
fill?: boolean;
}

export interface PandasData<TIndex> {
Expand Down
3 changes: 2 additions & 1 deletion shiny/render/_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def __init__(
data: object,
*,
width: str | float | None = "fit-content",
height: Union[str, float, None] = "500px",
height: Union[str, float, None] = None,
summary: Union[bool, str] = True,
filters: bool = False,
row_selection_mode: Literal["none", "single", "multiple"] = "none",
Expand Down Expand Up @@ -103,6 +103,7 @@ def to_payload(self) -> Jsonifiable:
filters=self.filters,
row_selection_mode=self.row_selection_mode,
style="grid",
fill=self.height is None,
)
return res

Expand Down
13 changes: 9 additions & 4 deletions shiny/www/shared/py-shiny/dataframe/dataframe.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions shiny/www/shared/py-shiny/dataframe/dataframe.js.map

Large diffs are not rendered by default.