How to Bind OData $count from expanded collection in an XML view

c_y picture c_y · May 22, 2014 · Viewed 27.2k times · Source

May be this is a basic question, but I have trouble binding the OData count in XML view.

In the following example, I want to bind the count of products from the OData model.

<List items="{/Categories}"} >  
  <ObjectListItem
    title="{CategoryName}"
    number="{path : 'Products/$count'}"
    numberUnit="Products"/>
</List>

Each category needs to display count of products in the respective category as in

/Categories(1)/Products/$count
/Categories(2)/Products/$count

Answer

Erik Allen picture Erik Allen · Nov 2, 2016

I had a similar issue. Although I am not thrilled with my solution, it uses expression binding and works without the need for a separate formatter:

<List items="{/Categories}"} >  
  <ObjectListItem 
    title="{CategoryName}"
    number="{= ${Products}.length }"
    numberUnit="Products" />
</List>

Like @Jasper_07, you still need to include Products in the expand, but you are ignoring most of the data coming back.