Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jesper Ordrup 1019 posts 1528 karma points MVP
    May 22, 2014 @ 14:59
    Jesper Ordrup
    0

    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

  • Bo Jacobsen 593 posts 2389 karma points
    Feb 26, 2019 @ 18:57
    Bo Jacobsen
    0

    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.

    enter image description here

    I am trying with:

    contentResource.getChildren($routeParams.id, { orderDirection: "Ascending", orderBy: "Name" })
    contentResource.getChildren($routeParams.id, { orderDirection: "Descending", orderBy: "Name" })
    contentResource.getChildren($routeParams.id, { orderDirection: "Ascending", orderBy: "CreateDate" })
    contentResource.getChildren($routeParams.id, { orderDirection: "Descending", orderBy: "CreateDate" })
    contentResource.getChildren($routeParams.id, { orderDirection: "Descending", orderBy: "SortOrder" })
    

    But all comes back sorted like default { orderDirection: "Ascending", orderBy: "SortOrder" }

  • Jesper Ordrup 1019 posts 1528 karma points MVP
    Feb 26, 2019 @ 19:02
    Jesper Ordrup
    0

    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

  • Bo Jacobsen 593 posts 2389 karma points
    Feb 26, 2019 @ 19:09
    Bo Jacobsen
    0

    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.

            /**
      * @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);
        },
    
  • Bo Jacobsen 593 posts 2389 karma points
    Feb 27, 2019 @ 07:57
    Bo Jacobsen
    1

    We found out why.

    pageNumber and pageSize has to be more then 0 in order for the sorting to work.

    This will work.

    contentResource.getChildren($routeParams.id, { orderDirection: "Ascending", orderBy: "Name", pageNumber: 1, pageSize: 10 })
    

    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 :)

Please Sign in or register to post replies

Write your reply to:

Draft