Skip to content

Commit d6e4781

Browse files
added switch to enable/disable sorting
1 parent 1c8fd39 commit d6e4781

File tree

4 files changed

+46
-13
lines changed

4 files changed

+46
-13
lines changed

client/packages/lowcoder/src/comps/comps/listViewComp/listView.tsx

+40-12
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ import { childrenToProps } from "@lowcoder-ee/comps/generators/multi";
2323
import { AnimationStyleType } from "@lowcoder-ee/comps/controls/styleControlConstants";
2424
import { getBackgroundStyle } from "@lowcoder-ee/util/styleUtils";
2525
import { DndContext } from "@dnd-kit/core";
26-
import { SortableContext, useSortable, verticalListSortingStrategy } from "@dnd-kit/sortable";
27-
import { restrictToVerticalAxis } from "@dnd-kit/modifiers";
26+
import { SortableContext, useSortable } from "@dnd-kit/sortable";
2827
import { CSS } from "@dnd-kit/utilities";
2928
import { JSONObject } from "@lowcoder-ee/index.sdk";
3029

@@ -94,7 +93,7 @@ const MinHorizontalWidthContext = createContext<MinHorizontalWidthContextType>({
9493
minHorizontalWidth: '100px',
9594
});
9695

97-
const ContainerInListView = (props: ContainerBaseProps & {itemIdx: number} ) => {
96+
const ContainerInListView = (props: ContainerBaseProps & {itemIdx: number, enableSorting?: boolean} ) => {
9897
const {
9998
horizontalWidth,
10099
minHorizontalWidth
@@ -104,6 +103,24 @@ const ContainerInListView = (props: ContainerBaseProps & {itemIdx: number} ) =>
104103
id: String(props.itemIdx),
105104
});
106105

106+
if (!props.enableSorting) {
107+
return (
108+
<div
109+
style={{
110+
width: horizontalWidth,
111+
minWidth: minHorizontalWidth || '0px',
112+
}}
113+
>
114+
<InnerGrid
115+
{...props}
116+
emptyRows={15}
117+
containerPadding={[4, 4]}
118+
hintPlaceholder={HintPlaceHolder}
119+
/>
120+
</div>
121+
)
122+
}
123+
107124
return (
108125
<div
109126
ref={setNodeRef}
@@ -139,6 +156,7 @@ type ListItemProps = {
139156
unMountFn?: () => void;
140157
minHorizontalWidth?: string;
141158
horizontalWidth: string;
159+
enableSorting?: boolean;
142160
};
143161

144162
function ListItem({
@@ -154,6 +172,7 @@ function ListItem({
154172
scrollContainerRef,
155173
minHeight,
156174
horizontalGridCells,
175+
enableSorting,
157176
} = props;
158177

159178
// disable the unmount function to save user's state with pagination
@@ -195,6 +214,7 @@ function ListItem({
195214
overflow={"hidden"}
196215
minHeight={minHeight}
197216
enableGridLines={true}
217+
enableSorting={enableSorting}
198218
/>
199219
</MinHorizontalWidthContext.Provider>
200220
);
@@ -248,6 +268,8 @@ export function ListView(props: Props) {
248268
};
249269
}, [children.pagination, totalCount]);
250270

271+
const enableSorting = useMemo(() => children.enableSorting.getView(), [children.enableSorting]);
272+
251273
useEffect(() => {
252274
children.listData.dispatchChangeValueAction(data);
253275
}, [JSON.stringify(data)]);
@@ -313,6 +335,7 @@ export function ListView(props: Props) {
313335
unMountFn={unMountFn}
314336
horizontalWidth={`${100 / noOfColumns}%`}
315337
minHorizontalWidth={horizontal ? minHorizontalWidth : undefined}
338+
enableSorting={enableSorting}
316339
/>
317340
);
318341
})}
@@ -365,15 +388,20 @@ export function ListView(props: Props) {
365388
$isGrid={noOfColumns > 1}
366389
$autoHeight={autoHeight}
367390
>
368-
<DndContext onDragEnd={handleDragEnd}>
369-
<SortableContext
370-
items={
371-
_.range(0, totalCount).map((colIdx) => String(colIdx))
372-
}
373-
>
374-
{renders}
375-
</SortableContext>
376-
</DndContext>
391+
{!enableSorting
392+
? renders
393+
: (
394+
<DndContext onDragEnd={handleDragEnd}>
395+
<SortableContext
396+
items={
397+
_.range(0, totalCount).map((colIdx) => String(colIdx))
398+
}
399+
>
400+
{renders}
401+
</SortableContext>
402+
</DndContext>
403+
)
404+
}
377405
</ListOrientationWrapper>
378406
)}
379407
>

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

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ const childrenMap = {
6161
animationStyle: styleControl(AnimationStyle, 'animationStyle'),
6262
horizontal: withDefault(BoolControl, false),
6363
minHorizontalWidth: withDefault(RadiusControl, '100px'),
64+
enableSorting: withDefault(BoolControl, false),
6465
};
6566

6667
const ListViewTmpComp = new UICompBuilder(childrenMap, () => <></>)

client/packages/lowcoder/src/comps/comps/listViewComp/listViewPropertyView.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ export function listPropertyView(compType: ListCompType) {
5757
<Section name={sectionNames.interaction}>
5858
{hiddenPropertyView(children)}
5959
{showDataLoadingIndicatorsPropertyView(children)}
60+
{children.enableSorting.propertyView({
61+
label: trans('listView.enableSorting'),
62+
})}
6063
</Section>
6164
)}
6265

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -2598,7 +2598,8 @@ export const en = {
25982598
"itemDataNameDesc": "The Variable Name Referring to the Item's Data Object, Default as {default}",
25992599
"itemsDesc": "Exposing Data of Components in List",
26002600
"dataDesc": "The JSON Data Used in the Current List",
2601-
"dataTooltip": "If You just Set a Number, This Field Will Be Regarded as Row Count, and the Data Will Be Regarded as Empty."
2601+
"dataTooltip": "If You just Set a Number, This Field Will Be Regarded as Row Count, and the Data Will Be Regarded as Empty.",
2602+
"enableSorting": "Allow Sorting"
26022603
},
26032604
"navigation": {
26042605
"addText": "Add Submenu Item",

0 commit comments

Comments
 (0)