Kentico ListInfo Object Types

SHARE

ListInfo object types in Kentico - what is it, how and where it can be used.

All Kentico APIs are based on Info and InfoProvider classes that have methods to manage database entities (like UserInfo, UserInfoProvider, AccountInfo, AccountInfoProvider - system data classes or some custom data classes that are generated for your custom entities).

Like Info data object contains information about one data item, ListInfo data object returns information about a collection of data items that might come from different sources (tables). ListInfo objects can be used in UniGrid configuration xml file, or in Kentico REST service in case data should be retrieved from different database tables, or when some data aggregation needed and some complex SQL query is required to get this data list. 

Let's consider an example of the ListInfo class implementation and usage. For example, let's imagine our site has to display some gallery of products and possible colors (here is nothing to do with E-commerce, just display some product information on web site).  We built some custom module for managing the product and product colors entities and created appropriate custom classes BO.Product and BO.ProductColor. In BO.ProductColor we have foreign key ProductID to reference product that this color is related to. Also appropriate classes ProductInfo, ProductInfoProvider, ProductColorInfo and ProuductColorInfoProvider are generated.

So now we have to set up user interface for managing product and product colors. Creation of custom module can be found in the documentation. The first step is to create UI element to display products grid. The only additional requirement is to display number of colors related to that product in the grid. 

Obviously there is no straight way to set this 'Colors Count' column in the grid. Possible way is to create extender to the grid with some external source binding. But another effective way is using ListInfo object type. It gives more flexibility and allows pull appropriate data (even complex request) in one SQL query.

List info class is widely used in Kentico UniGrid definitions. One of such examples is grid that displays Booking Events list in admin. This grid uses cms.bookingeventlist object type that collects data from booking event page types and appropriate tree nodes information and displays attendees count. The class for cms.bookingeventlist is defined in CMS.EventManager namespace (CMS.EventManager.BookingEventListInfo) and has internal modifier.

ListInfo class, similar to other Info classes, is inherited form generic CMS.DataEngine​.AbstractInfo class and is internal. TYPEINFO property is defined and custom Object type name is set. To define list of data that is returned by class, GetDataQueryInternal method  is overridden. This method returns object of IDataQuery type
where appropriate sql query is set. 

Here is an example of ListInfo class for the scenario described above.
using System.Data;
using CMS;
using CMS.DataEngine;
using CMS.Base;

[assembly: RegisterObjectType(typeof(ProductsListInfo), ProductsListInfo.OBJECT_TYPE)]

namespace BO
{
    internal class ProductsListInfo : AbstractInfo<ProductsListInfo>
    {
        /// <summary>
        /// Type information. 
        /// </summary>
        public static ObjectTypeInfo TYPEINFO = new ObjectTypeInfo("bo.productslist", ProductInfo.TYPEINFO)
        {
            IDColumn = "ProductID",
            ModuleName = "BOProducts",            
        };

        /// <summary>
        /// Object type
        /// </summary>
        public const string OBJECT_TYPE = "bo.productslist";

        public ProductsListInfo()
            : base(ProductsListInfo.TYPEINFO)
        {
        }

        public ProductsListInfo(DataRow dr)
            : base(ProductsListInfo.TYPEINFO, dr)
        {
        }

        /// <summary>
        /// Gets the data query for this object type
        /// </summary>
        protected override IDataQuery GetDataQueryInternal()
        {
            return (IDataQuery)new DataQuery("bo.product", "selectallproducts");
        }
    }
}


SQL query bo.product.selectallproducts for the example will look like this:
 
SELECT ##TOPN## ##COLUMNS##
FROM [BO_Product] JOIN 
(SELECT  P.ProductID as ColorProductID, count(P.ProductID) AS ColorsCount
 FROM  [BO_ProductColor] P 
 GROUP BY P.ProductID) C ON C.ColorProductID = [BO_Product].ProductID
WHERE ##WHERE##
ORDER BY ##ORDERBY##

So now when class and query is set up we can define UniGrid xml file:
 
<?xml version="1.0" encoding="utf-8" ?>
<grid>
  <actions>
    <action name="edit" caption="$general.action$" fonticonclass="icon-edit" fonticonstyle="allow" ></action>
  </actions>
  <columns>
    <column source="ProductNumber" caption="Product number">
      <filter type="text" size="50"/>
    </column>
    <column source="ProductName" caption="Name">
      <filter type="text" size="100"/>
    </column>
    <column source="ColorsCount" caption="Colors count"/>
  </columns>
  <options>
    <key name="DisplayFilter" value="true" />
  </options>
  <objecttype name="bo.productslist" columns="ProductID, ProductNumber, ProductName, ColorsCount"/>
</grid>
Please pay attention on bo.productslist object type using in UniGrid definition.

You can use defined bo.productslist object type in Kentico REST requests:
<site domain name>/rest/bo.productslist/?<parameters>

Author

Check other articles

Bitsorchestra 5 5

What our clients say

Bits Orchestra team are outstanding developers​. They listen carefully to our business needs and easily turns our business objectives into a well thought out and executed development effort. Roman is very bright and definitely the most capable developer that has worked on our site. He is not only a Kentico expert but has successfully tackled other complicated development assignments demonstrating expertise in both front and backend development. Roman takes initiative to suggest enhancements that make site maintenance easier while improving the customer experience. The team is very responsive to our work requests and has great follow up. They have also worked very business partners and this has reflected positively on our company. Roman is a true partner for us and a tremendous asset to our organization. We will continue to work with them and would highly recommend Roman and his team for your development needs. He and his team will exceed your expectations!
 Alan Lehmann
Alan Lehmann
President at In energy sector

What our clients say

The Bits Orchestra team does excellent work. They are always available and I appreciate our frequent calls and screen-shares together. Their dedication to the projects and knowledge of Kentico is outstanding. They truly care about the quality of their work, and became a part of our team easily!
Shena Lowe
Shena Lowe
Managing Partner at Consensus Interactive

What our clients say

We hired Roman for a Kentico analysis project and have been very satisfied. He is very skilled and professional. We are looking to hire him and his team again on future projects.
Sylvain Audet
Sylvain Audet
CEO at MyDevPartner.com

What our clients say

Roman and team have taken over an existing Kentico EMS site for a large US Oil Company. So far, they have handled every single request that we have thrown at them and these were diverse, challenging, often bespoke, usually urgent and almost daily, over the last 11 months. Their work is of an extremely high quality, they are capable, quick and we have great confidence in the support that we are getting.
Jon Hollis
Jon Hollis
Head of Web Development at confidential

What our clients say

Bits Orchestra team was very helpful, they had a good understanding of the brief and deep knowledge of the system. They were always keen to provide advice and recommendations that benefit the project substantially.
Ramon Lapenta
Ramon Lapenta
Senior Front End Developer at Cyber-Duck Ltd