create-emsgrid 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -74,7 +74,19 @@ export function Grid<TData>(props: GridProps<TData>) {
|
|
|
74
74
|
rowHeight,
|
|
75
75
|
overscan,
|
|
76
76
|
});
|
|
77
|
+
const tableWidth = table.getTotalSize();
|
|
77
78
|
const firstContentColumnId = table.getVisibleLeafColumns().find((col) => col.id !== 'select')?.id;
|
|
79
|
+
const headerRef = React.useRef<HTMLDivElement | null>(null);
|
|
80
|
+
const syncHorizontalScroll = React.useCallback(
|
|
81
|
+
(source: HTMLDivElement | null, target: HTMLDivElement | null) => {
|
|
82
|
+
if (!source || !target) return;
|
|
83
|
+
const nextLeft = source.scrollLeft;
|
|
84
|
+
if (target.scrollLeft !== nextLeft) {
|
|
85
|
+
target.scrollLeft = nextLeft;
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
[]
|
|
89
|
+
);
|
|
78
90
|
const [menu, setMenu] = React.useState<{
|
|
79
91
|
open: boolean;
|
|
80
92
|
x: number;
|
|
@@ -95,16 +107,22 @@ export function Grid<TData>(props: GridProps<TData>) {
|
|
|
95
107
|
|
|
96
108
|
return (
|
|
97
109
|
<div className="grid-shell">
|
|
98
|
-
<
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
110
|
+
<div ref={headerRef} className="scroll-header">
|
|
111
|
+
<Header
|
|
112
|
+
table={table}
|
|
113
|
+
showFilters={showFilters}
|
|
114
|
+
onHeaderDragStart={handleHeaderDragStart}
|
|
115
|
+
onHeaderDrop={handleHeaderDrop}
|
|
116
|
+
isReorderableColumn={isReorderable}
|
|
117
|
+
/>
|
|
118
|
+
</div>
|
|
105
119
|
|
|
106
|
-
<div
|
|
107
|
-
|
|
120
|
+
<div
|
|
121
|
+
ref={parentRef}
|
|
122
|
+
className="scroll"
|
|
123
|
+
onScroll={() => syncHorizontalScroll(parentRef.current, headerRef.current)}
|
|
124
|
+
>
|
|
125
|
+
<div style={{ height: totalSize, position: 'relative', width: tableWidth, minWidth: '100%' }}>
|
|
108
126
|
{isLoading ? (
|
|
109
127
|
<div style={{ padding: 12, opacity: 0.8 }}>Загрузка…</div>
|
|
110
128
|
) : (
|
|
@@ -117,6 +135,7 @@ export function Grid<TData>(props: GridProps<TData>) {
|
|
|
117
135
|
row={row}
|
|
118
136
|
top={vi.start}
|
|
119
137
|
rowHeight={rowHeight}
|
|
138
|
+
tableWidth={tableWidth}
|
|
120
139
|
firstContentColumnId={firstContentColumnId}
|
|
121
140
|
renderAggregatedCell={renderAggregatedCell}
|
|
122
141
|
isGroupMode={isGroupMode}
|
|
@@ -16,6 +16,7 @@ export function Cell<TData>({
|
|
|
16
16
|
isGroupMode = false,
|
|
17
17
|
}: CellProps<TData>) {
|
|
18
18
|
const depth = cell.row.depth;
|
|
19
|
+
const isGroupedCell = isGroupMode ? (cell.getIsGrouped?.() ?? false) : false;
|
|
19
20
|
const canExpand = isExpanderCell && cell.row.getCanExpand();
|
|
20
21
|
const isExpanded = canExpand ? cell.row.getIsExpanded() : false;
|
|
21
22
|
const paddingLeft = isExpanderCell ? 10 + depth * 14 : undefined;
|
|
@@ -58,11 +59,13 @@ export function Cell<TData>({
|
|
|
58
59
|
);
|
|
59
60
|
} else if (isAggregatedCell) {
|
|
60
61
|
content = aggregatedRenderer(cell);
|
|
61
|
-
} else {
|
|
62
|
+
} else if (isPlaceholder || isGroupedCell) {
|
|
62
63
|
content = null;
|
|
64
|
+
} else {
|
|
65
|
+
content = defaultRenderer;
|
|
63
66
|
}
|
|
64
67
|
} else if (isPlaceholder) {
|
|
65
|
-
content =
|
|
68
|
+
content = defaultRenderer;
|
|
66
69
|
} else if (isExpanderCell && canExpand) {
|
|
67
70
|
content = (
|
|
68
71
|
<>
|
|
@@ -14,11 +14,12 @@ type HeaderProps<TData> = {
|
|
|
14
14
|
|
|
15
15
|
export function Header<TData>(props: HeaderProps<TData>) {
|
|
16
16
|
const { table, showFilters, onHeaderDragStart, onHeaderDrop, isReorderableColumn } = props;
|
|
17
|
+
const tableWidth = table.getTotalSize();
|
|
17
18
|
|
|
18
19
|
return (
|
|
19
|
-
<div className="grid-header">
|
|
20
|
+
<div className="grid-header" style={{ width: tableWidth, minWidth: '100%' }}>
|
|
20
21
|
{table.getHeaderGroups().map((hg) => (
|
|
21
|
-
<div key={hg.id} className="row">
|
|
22
|
+
<div key={hg.id} className="row" style={{ width: tableWidth, minWidth: '100%' }}>
|
|
22
23
|
{hg.headers.map((header) => {
|
|
23
24
|
const col = header.column;
|
|
24
25
|
const size = col.getSize();
|
|
@@ -6,6 +6,7 @@ type RowProps<TData> = {
|
|
|
6
6
|
row: TableRow<TData>;
|
|
7
7
|
top: number;
|
|
8
8
|
rowHeight: number;
|
|
9
|
+
tableWidth: number;
|
|
9
10
|
firstContentColumnId?: string;
|
|
10
11
|
renderAggregatedCell?: (cell: TableCell<TData, unknown>) => React.ReactNode;
|
|
11
12
|
isGroupMode?: boolean;
|
|
@@ -16,6 +17,7 @@ export function Row<TData>({
|
|
|
16
17
|
row,
|
|
17
18
|
top,
|
|
18
19
|
rowHeight,
|
|
20
|
+
tableWidth,
|
|
19
21
|
firstContentColumnId,
|
|
20
22
|
renderAggregatedCell,
|
|
21
23
|
isGroupMode,
|
|
@@ -28,7 +30,8 @@ export function Row<TData>({
|
|
|
28
30
|
position: 'absolute',
|
|
29
31
|
top,
|
|
30
32
|
left: 0,
|
|
31
|
-
|
|
33
|
+
width: tableWidth,
|
|
34
|
+
minWidth: '100%',
|
|
32
35
|
height: rowHeight,
|
|
33
36
|
}}
|
|
34
37
|
onContextMenu={onContextMenu}
|