Skip to content

Commit ec793cf

Browse files
committed
feat: add default sorting support for foreign inline list
1 parent c9fdf3d commit ec793cf

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

custom/InlineList.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,9 @@ async function getList() {
309309
310310
onMounted( async () => {
311311
loading.value = true;
312+
if (props.meta?.defaultSort && sort.value.length === 0) {
313+
sort.value = [props.meta.defaultSort];
314+
}
312315
const foreighResourceId = props.meta.foreignResourceId;
313316
listResource.value = (await callAdminForthApi({
314317
path: `/plugin/${props.meta.pluginInstanceId}/get_resource`,

index.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,12 @@ export default class ForeignInlineListPlugin extends AdminForthPlugin {
111111
const similar = suggestIfTypo(adminforth.config.resources.map((res) => res.resourceId), this.options.foreignResourceId);
112112
throw new Error(`ForeignInlineListPlugin: Resource with ID "${this.options.foreignResourceId}" not found. ${similar ? `Did you mean "${similar}"?` : ''}`);
113113
}
114+
115+
if (this.options.modifyTableResourceConfig) {
116+
this.options.modifyTableResourceConfig(this.foreignResource);
117+
}
114118

119+
const defaultSort = this.foreignResource.options?.defaultSort;
115120
const newColumn = {
116121
name: `foreignInlineList_${this.foreignResource.resourceId}`,
117122
label: 'Foreign Inline List',
@@ -128,7 +133,16 @@ export default class ForeignInlineListPlugin extends AdminForthPlugin {
128133
file: this.componentPath('InlineList.vue'),
129134
meta: {
130135
...this.options,
131-
pluginInstanceId: this.pluginInstanceId
136+
pluginInstanceId: this.pluginInstanceId,
137+
...(defaultSort
138+
? {
139+
defaultSort: {
140+
field: defaultSort.columnName,
141+
direction: defaultSort.direction,
142+
}
143+
}
144+
: {}
145+
)
132146
}
133147
}
134148
},

0 commit comments

Comments
 (0)