Skip to content

Commit 1971a6e

Browse files
authored
Merge pull request #536 from lowcoder-org/feat-layout-mode-table
Dev to Feature
2 parents bd3cf48 + a90b975 commit 1971a6e

File tree

7 files changed

+57
-13
lines changed

7 files changed

+57
-13
lines changed

client/packages/lowcoder/src/comps/comps/tableComp/tableComp.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ export class TableImplComp extends TableInitComp implements IContainer {
6161
readonly filterData: RecordType[] = [];
6262
readonly columnAggrData: ColumnsAggrData = {};
6363

64+
override autoHeight(): boolean {
65+
return this.children.autoHeight.getView();
66+
}
67+
6468
private getSlotContainer() {
6569
return this.children.expansion.children.slot.getSelectedComp().getComp().children.container;
6670
}

client/packages/lowcoder/src/comps/comps/tableComp/tableCompView.tsx

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ const TableWrapper = styled.div<{
158158
$rowStyle: TableRowStyleType;
159159
toolbarPosition: "above" | "below" | "close";
160160
}>`
161-
overflow: hidden;
161+
max-height: 100%;
162+
overflow-y: auto;
162163
background: white;
163164
border: 1px solid #d7d9e0;
164165
@@ -275,6 +276,7 @@ const TableTd = styled.td<{
275276
border-color: ${(props) => props.$style.border} !important;
276277
border-width: ${(props) => props.$style.borderWidth} !important;
277278
border-radius: ${(props) => props.$style.radius};
279+
padding: 0 !important;
278280
279281
> div > div {
280282
color: ${(props) => props.$style.text};
@@ -362,6 +364,9 @@ type CustomTableProps<RecordType> = Omit<TableProps<RecordType>, "components" |
362364
viewModeResizable: boolean;
363365
rowColorFn: RowColorViewType;
364366
columnsStyle: TableColumnStyleType;
367+
fixedHeader: boolean;
368+
height?: number;
369+
autoHeight?: boolean;
365370
};
366371

367372
function TableCellView(props: {
@@ -533,7 +538,12 @@ function ResizeableTable<RecordType extends object>(props: CustomTableProps<Reco
533538
{...props}
534539
pagination={false}
535540
columns={columns}
536-
scroll={{ x: COL_MIN_WIDTH * columns.length }}
541+
scroll={{
542+
x: COL_MIN_WIDTH * columns.length,
543+
y: props.fixedHeader && props.height && !props.autoHeight
544+
? `${props.height - 100}px`
545+
: undefined,
546+
}}
537547
></Table>
538548
);
539549
}
@@ -546,11 +556,10 @@ export function TableCompView(props: {
546556
onDownload: (fileName: string) => void;
547557
}) {
548558
const editorState = useContext(EditorContext);
549-
// const editorModeStatus = editorState.editorModeStatus;
550-
const { width, ref } = useResizeDetector({
559+
const { width, height, ref } = useResizeDetector({
551560
refreshMode: "debounce",
552561
refreshRate: 600,
553-
handleHeight: false,
562+
handleHeight: true,
554563
});
555564
const viewMode = useUserViewMode();
556565
const compName = useContext(CompNameContext);
@@ -575,6 +584,7 @@ export function TableCompView(props: {
575584
() => compChildren.dynamicColumnConfig.getView(),
576585
[compChildren.dynamicColumnConfig]
577586
);
587+
const autoHeight = compChildren.autoHeight.getView();
578588
const columnsAggrData = comp.columnAggrData;
579589
const expansion = useMemo(() => compChildren.expansion.getView(), [compChildren.expansion]);
580590
const antdColumns = useMemo(
@@ -666,8 +676,8 @@ export function TableCompView(props: {
666676

667677
return (
668678
<BackgroundColorContext.Provider value={style.background}>
679+
<div ref={ref} style={{height: '100%'}}>
669680
<TableWrapper
670-
ref={ref}
671681
$style={style}
672682
$rowStyle={rowStyle}
673683
toolbarPosition={toolbar.position}
@@ -691,12 +701,15 @@ export function TableCompView(props: {
691701
onTableChange(pagination, filters, sorter, extra, comp.dispatch, onEvent);
692702
}}
693703
showHeader={!compChildren.hideHeader.getView()}
704+
fixedHeader={compChildren.fixedHeader.getView()}
694705
columns={antdColumns}
695706
columnsStyle={columnsStyle}
696707
viewModeResizable={compChildren.viewModeResizable.getView()}
697708
dataSource={pageDataInfo.data}
698709
size={compChildren.size.getView()}
699710
tableLayout="fixed"
711+
height={height}
712+
autoHeight={autoHeight}
700713
loading={
701714
loading ||
702715
// fixme isLoading type
@@ -710,6 +723,7 @@ export function TableCompView(props: {
710723
{expansion.expandModalView}
711724
</SlotConfigContext.Provider>
712725
</TableWrapper>
726+
</div>
713727
</BackgroundColorContext.Provider>
714728
);
715729
}

client/packages/lowcoder/src/comps/comps/tableComp/tableTypes.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
BoolCodeControl,
77
ColorOrBoolCodeControl,
88
JSONObjectArrayControl,
9+
RadiusControl,
910
StringControl,
1011
} from "comps/controls/codeControl";
1112
import { dropdownControl } from "comps/controls/dropdownControl";
@@ -33,6 +34,7 @@ import { JSONObject } from "util/jsonTypes";
3334
import { ExpansionControl } from "./expansionControl";
3435
import { PaginationControl } from "./paginationControl";
3536
import { SelectionControl } from "./selectionControl";
37+
import { AutoHeightControl } from "comps/controls/autoHeightControl";
3638

3739
const sizeOptions = [
3840
{
@@ -135,6 +137,8 @@ export type RowColorViewType = (param: {
135137
const tableChildrenMap = {
136138
hideBordered: BoolControl,
137139
hideHeader: BoolControl,
140+
fixedHeader: BoolControl,
141+
autoHeight: withDefault(AutoHeightControl, "auto"),
138142
data: withIsLoadingMethod(JSONObjectArrayControl),
139143
showDataLoadSpinner: withDefault(BoolPureControl, true),
140144
columns: ColumnListComp,

client/packages/lowcoder/src/comps/hooks/screenInfoComp.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,16 @@ function useScreenInfo() {
4040
}
4141

4242
const getScreenInfo = useCallback(() => {
43-
const { width, height } = window.screen;
43+
const { innerWidth, innerHeight } = window;
4444
const deviceType = getDeviceType();
4545
const flags = getFlagsByDeviceType(deviceType);
4646

47-
return { width, height, deviceType, ...flags };
47+
return {
48+
width: innerWidth,
49+
height: innerHeight,
50+
deviceType,
51+
...flags
52+
};
4853
}, [])
4954

5055
const [screenInfo, setScreenInfo] = useState<ScreenInfo>({});

client/packages/lowcoder/src/i18n/locales/en.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,6 +1248,8 @@ export const en = {
12481248
type: "Type",
12491249
tableSize: "Table size",
12501250
hideHeader: "Hide table header",
1251+
fixedHeader: "Fixed table header",
1252+
fixedHeaderTooltip: "Header will be fixed for vertically scrollable table",
12511253
hideBordered: "Hide column border",
12521254
deleteColumn: "Delete column",
12531255
confirmDeleteColumn: "Confirm delete column: ",

client/packages/lowcoder/src/i18n/locales/zh.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,6 +1174,8 @@ table: {
11741174
type: "类型",
11751175
tableSize: "表格尺寸",
11761176
hideHeader: "隐藏表头",
1177+
fixedHeader: "固定表头",
1178+
fixedHeaderTooltip: "垂直滚动表格的标题将被固定",
11771179
hideBordered: "隐藏列边框",
11781180
deleteColumn: "删除列",
11791181
confirmDeleteColumn: "确认删除列:",

client/packages/lowcoder/src/pages/editor/right/uiCompPanel.tsx

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
RightPanelContentWrapper,
1414
} from "pages/editor/right/styledComponent";
1515
import { tableDragClassName } from "pages/tutorials/tutorialsConstant";
16-
import React, { useContext, useMemo, useState } from "react";
16+
import React, { useContext, useEffect, useMemo, useState } from "react";
1717
import styled from "styled-components";
1818
import {
1919
BaseSection,
@@ -99,6 +99,7 @@ Object.keys(uiCompCategoryNames).forEach((cat) => {
9999
export const UICompPanel = () => {
100100
const { onDrag, searchValue } = useContext(RightContext);
101101
const [propertySectionState, setPropertySectionState] = useState<PropertySectionState>(initialState);
102+
const [searchedPropertySectionState, setSearchedPropertySectionState] = useState<PropertySectionState>({});
102103

103104
const categories = useMemo(() => {
104105
const cats: Record<string, [string, UICompManifest][]> = Object.fromEntries(
@@ -113,11 +114,18 @@ export const UICompPanel = () => {
113114
}, []);
114115

115116
const propertySectionContextValue = useMemo<PropertySectionContextType>(() => {
117+
const state = searchValue
118+
? searchedPropertySectionState
119+
: propertySectionState;
120+
const setStateFn = searchValue
121+
? setSearchedPropertySectionState
122+
: setPropertySectionState;
123+
116124
return {
117125
compName: stateCompName,
118-
state: propertySectionState,
126+
state,
119127
toggle: (compName: string, sectionName: string) => {
120-
setPropertySectionState((oldState) => {
128+
setStateFn((oldState) => {
121129
const nextSectionState: PropertySectionState = { ...oldState };
122130
const compState = nextSectionState[compName] || {};
123131
compState[sectionName] = compState[sectionName] === false;
@@ -126,7 +134,13 @@ export const UICompPanel = () => {
126134
});
127135
},
128136
};
129-
}, [propertySectionState]);
137+
}, [searchValue, propertySectionState, searchedPropertySectionState]);
138+
139+
useEffect(() => {
140+
if(!searchValue) {
141+
setSearchedPropertySectionState({})
142+
}
143+
}, [searchValue])
130144

131145
const compList = useMemo(
132146
() =>
@@ -187,7 +201,6 @@ export const UICompPanel = () => {
187201

188202
return (
189203
<RightPanelContentWrapper>
190-
{/* {compList.length > 0 ? compList : <EmptyCompContent />} */}
191204
<PropertySectionContext.Provider
192205
value={propertySectionContextValue}
193206
>

0 commit comments

Comments
 (0)