mongo sort

This commit is contained in:
Jan Prochazka 2021-04-08 10:25:27 +02:00
parent 0db9ae7cb1
commit 007b40bf9b

View File

@ -1,5 +1,5 @@
<script context="module" lang="ts"> <script context="module" lang="ts">
export function buildGridMongoCondition(props) { function buildGridMongoCondition(props) {
const filters = props?.display?.config?.filters; const filters = props?.display?.config?.filters;
const conditions = []; const conditions = [];
@ -27,6 +27,19 @@
: undefined; : undefined;
} }
function buildMongoSort(props) {
const sort = props?.display?.config?.sort;
if (sort?.length > 0) {
return _.zipObject(
sort.map(col => col.uniqueName),
sort.map(col => (col.order == 'DESC' ? -1 : 1))
);
}
return null;
}
export async function loadCollectionDataPage(props, offset, limit) { export async function loadCollectionDataPage(props, offset, limit) {
const { conid, database } = props; const { conid, database } = props;
@ -43,6 +56,7 @@
limit, limit,
skip: offset, skip: offset,
condition: buildGridMongoCondition(props), condition: buildGridMongoCondition(props),
sort: buildMongoSort(props),
}, },
}, },
}); });