Right now my best option is properly to do a sort on the returning array my self.
I have debugged the Umbraco Controller to see if it is passing the right option values, and it is.
/**
* @ngdoc method
* @name umbraco.resources.contentResource#getChildren
* @methodOf umbraco.resources.contentResource
*
* @description
* Gets children of a content item with a given id
*
* ##usage
* <pre>
* contentResource.getChildren(1234, {pageSize: 10, pageNumber: 2})
* .then(function(contentArray) {
* var children = contentArray;
* alert('they are here!');
* });
* </pre>
*
* @param {Int} parentid id of content item to return children of
* @param {Object} options optional options object
* @param {Int} options.pageSize if paging data, number of nodes per page, default = 0
* @param {Int} options.pageNumber if paging data, current page index, default = 0
* @param {String} options.filter if provided, query will only return those with names matching the filter
* @param {String} options.orderDirection can be `Ascending` or `Descending` - Default: `Ascending`
* @param {String} options.orderBy property to order items by, default: `SortOrder`
* @returns {Promise} resourcePromise object containing an array of content items.
*
*/
getChildren: function (parentId, options) {
var defaults = {
includeProperties: [],
pageSize: 0,
pageNumber: 0,
filter: '',
orderDirection: 'Ascending',
orderBy: 'SortOrder',
orderBySystemField: true
};
if (options === undefined) {
options = {};
}
//overwrite the defaults if there are any specified
angular.extend(defaults, options);
//now copy back to the options we will use
options = defaults;
//change asc/desct
if (options.orderDirection === 'asc') {
options.orderDirection = 'Ascending';
} else if (options.orderDirection === 'desc') {
options.orderDirection = 'Descending';
}
//converts the value to a js bool
function toBool(v) {
if (angular.isNumber(v)) {
return v > 0;
}
if (angular.isString(v)) {
return v === 'true';
}
if (typeof v === 'boolean') {
return v;
}
return false;
}
return umbRequestHelper.resourcePromise($http.get(umbRequestHelper.getApiUrl('contentApiBaseUrl', 'GetChildren', {
id: parentId,
includeProperties: _.pluck(options.includeProperties, 'alias').join(','),
pageNumber: options.pageNumber,
pageSize: options.pageSize,
orderBy: options.orderBy,
orderDirection: options.orderDirection,
orderBySystemField: toBool(options.orderBySystemField),
filter: options.filter
})), 'Failed to retrieve children for content item ' + parentId);
},
ContentResource.GetChildren .. options?
From an Angular Controller I'm trying to do fetch data sorted on a custom node property. Is it not possible?
$scope.options = {
pageSize: 100,
pageNumber: 1,
filter: '',
orderBy: 'myCustomProperty',
orderDirection: "desc"
};
contentResource.getChildren(id, $scope.options)
/Jesper
Hi Jesper.
I am trying to do the same thing today. Did you find a solution?
According to Umbraco Backoffice UI API Documentation at https://our.umbraco.com/apidocs/ui/#/api/umbraco.resources.contentResource#methods_getchildren it should be possible.
I am trying with:
But all comes back sorted like default { orderDirection: "Ascending", orderBy: "SortOrder" }
Hi Bo
Its too far away. Sorry. Anything more than 3 days ago is actually :-)
But let me know how it goes. I might retry for you.
Best Jeeper
It's only 5 years ago ;)
Right now my best option is properly to do a sort on the returning array my self.
I have debugged the Umbraco Controller to see if it is passing the right option values, and it is.
We found out why.
pageNumber and pageSize has to be more then 0 in order for the sorting to work.
This will work.
So if you want all children i guess you have to get the number of them before calling this method. I am lazy so i just sat it to 1000 :)
is working on a reply...