on 01-16-2021 5:56 AM
Hello ,
We are facing an issue where every service defined in CAP (Nodejs module) returns the result set in sorted order of primary key by default . We want to remove this and provide our own custom sorting . However writing an order by statement after entity select is not causing any change to the output result set and is still sorted by primary key .
From cap documentation i have read that there is some implicit sorting mechanism involved here . In JAVA runtime we can remove the implicit sorting by adding cds.query.implicitSorting.enabled: false in some config file . (https://cap.cloud.sap/docs/java/development/properties) . How do we achieve the same in NodeJS environment? Please provide the full syntax if possible as i tried adding the same as a nested structure in package.json and it didnt work .
Regards,
Akshat Malhotra
This only works as of now for us using a custom on after handler on service and sorting the json response on sort column (javascript object sorting) .
async function _afterReadServiceHandler(res,req) {
res.sort((a, b) => (a.SORTORDER > b.SORTORDER) ? 1 : -1)
}
Please note : writing order by query in on before handler does not work as the default behavior of sorting on key gets applied anyway .
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Check this documentation about implicit sorting:
https://cap.cloud.sap/docs/guides/generic#implicit-sorting
The key is always the default sort order, but if you specify other orders yourself, they have a higher priority.
BR
Samuel
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Good day, sambr
what should I do if a key of an external service defined by edmx/cds is annotated by sap:sortable="false"
I have a read-only access to this service (SuccessFactors sandbox)
so I'm receiving an error error.Error during request to remote service:
[COE0003]Bad property expression: backgroundElementId; backgroundElementId is not sortableI would expect that adding orderby to your odata request would work...
A workaround could be the create an after read eventhandler and do the sorting yourself in js: https://cap.cloud.sap/docs/node.js/services#event-handlers
But maybe there is a beter way to do this...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am not a UI expert but I understand there is some challenge calling service with $orderby especially in smart tree table control . By using handlers I understand could be the only way for now . I was just wondering if there is an option to just turn the implicit sorting on primary key off and specify the custom order by clause within service implementation file(.cds) itself , thereby avoiding writing handlers .
eg. entity as select from <table> {*} order by SORTCOLUMN asc . Currently this order by clause is being ignored for some reason .
Try using this annotation https://github.com/SAP/odata-vocabularies/blob/master/vocabularies/Common.md#SortOrder
User | Count |
---|---|
91 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.