Copied to clipboard

Flag this post as spam?

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


  • Martijn 1 post 71 karma points
    7 days ago
    Martijn
    0

    GetPagedChildren how to orderby and filter

    Hi there,

    I used this method to create a custom controller that I can access thru xhr. (first of all is this still usable / preferable in V8?)

    https://our.umbraco.com/apidocs/v7/csharp/api/Umbraco.Core.Services.ContentService.html#UmbracoCoreServicesContentServiceGetPagedChildrenSystemInt32SystemInt32SystemInt32SystemInt32_SystemStringUmbracoCorePersistenceDatabaseModelDefinitionsDirectionSystemString

    My custom method looks like this and is working. Now I am stuck with the ordering and filtering.

        [System.Web.Http.AcceptVerbs("GET", "POST")]
        [System.Web.Http.HttpGet]
        [System.Web.Http.AllowAnonymous]
        public ActionResult GetNewsByParentId(int Id,int PageIndex = 0,int PageSize = 10
        , string orderby, string direction, string filter = null)
        {
            //are there children for this content id?
            bool hasChildren = Services.ContentService.HasChildren(Id);
    
            //get the first 10 childeren
            IEnumerable<IContent> Children = Services.ContentService.GetPagedChildren(Id, PageIndex, PageSize, out long TotalChildren);
    
            //create Json object
            var result = new JsonResult
            {
                Data = new
                {
                     TotalChildren
                    ,PageIndex
                    ,PageSize
                    ,Children
                },
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };
            return result;
        }
    

    Ordering: I would like to now if I can filter by a 1 or multiple custom field .OrderBy("Tag").ThenBy("Date")

    Or can i only use the default properties (publisheddate, Name etc) (and where can I find a list with witch ones)

    The ordering direction? https://our.umbraco.com/apidocs/v7/csharp/api/Umbraco.Core.Persistence.DatabaseModelDefinitions.Direction.html Is there a example how this works (what do I need to fill in).

    De filter function How can I use to search on multiple tags / words / numbers (is this even possible?) can i use where and or contains?

    I hope somebody can help me with a nice example.

    Services.ContentService.GetPagedChildren(Id, PageIndex, PageSize, out long TotalChildren,"?","?","?");
    

    regards

Please Sign in or register to post replies

Write your reply to:

Draft