ektron

Ektron: How to change the Framework API's default page size?


I've noticed that when pulling content form the framework API that there is a default page size of 50. I've tried adjusting the "ek_PageSize" AppSetting, but that doesn't seem to affect the API.

Basically in all my code I need to create a new PaginInfo object to update the number of items being returned.

var criteria = new ContentTaxonomyCriteria(ContentProperty.Id, EkEnumeration.OrderByDirection.Descending);
criteria.PagingInfo = new PagingInfo(100);

Does anyone know if there's a way to change that default value (for the entire site) without having to modify the PagingInfo object on the criteria on each call?


Solution

  • You could create a factory method that creates your criteria object. Then instead of instantiating the criteria object, you would call this factory method. From here, you can define an AppSetting that is unique to your code. There are several types of criteria objects used by the ContentManager, so you could even make the factory method generic.

    private T GetContentCriteria<T>() where T : ContentCriteria, new()
    {
        // Sorting by Id descending will ensure newer content blocks are favored over older content.
        var criteria = new T
        {
            OrderByField = ContentProperty.Id,
            OrderByDirection = EkEnumeration.OrderByDirection.Descending
        };
    
        int maxRecords;
        int.TryParse(ConfigurationManager.AppSettings["CmsContentService_PageSize"], out maxRecords);
    
        // Only set the PagingInfo if a valid value exists in AppSettings.
        // The Framework API's default page size of 50 will be used otherwise.
        if (maxRecords > 0)
        {
            criteria.PagingInfo = new PagingInfo(maxRecords);
        }
    
        return criteria;
    }