Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
Posts: 136
Registered: ‎01-25-2010
My Device: Z30, Z10, Q10, Dev Alpha B & Bold 9900
My Carrier: Bell
Accepted Solution

Grouping data via GroupDataModel & DataSource

Hi,

 

I'm loading the XML data structure listed below via a DataSource, the data loads properly and the data is displayed in the ListView.

 

<dataresponse>
  <request></request>
  <search>
    <results>
      <cars>
        <carcount type="integer">3</carcount>
          <rating>4.28</rating>
          <car>
            <id type="integer">375802</id>
            <model>Civic</model>
            <manufacturer>
              <id type="integer">589</id>
              <name>Honda</name>
            </manufacturer>
          </car>
          <car>
            <id type="integer">375803</id>
            <model>Accord</model>
            <manufacturer>
              <id type="integer">590</id>
              <name>Honda</name>
            </manufacturer>
          </car>
          <car>
            <id type="integer">375804</id>
            <model>Camry</model>
            <manufacturer>
              <id type="integer">591</id>
              <name>Toyota</name>
            </manufacturer>
          </car>          
        </cars>
    </results>
  </search>
</dataresponse>

 

The GroupDataModel & the DataSource is defined as per below...

 

    attachedObjects: [
        
        GroupDataModel 
        {
            id: dataModel
            
            // This works and the header is displayed properly by rating
            //sortingKeys: ["rating"] 

// Sorting does not work, and listview header is displayed @ top with empty data sortingKeys: ["manufacturer.name"] sortedAscending: true grouping: ItemGrouping.ByFullValue }, DataSource { id: dataSource // Load the XML data from a remote data source source: "http://www.mydataservice.com/getdata.php" query: "/dataresponse/search/results/cars" type: DataSourceType.Xml onDataLoaded: { // After the data is loaded, clear any existing items in the data // model and populate it with the new data dataModel.clear(); dataModel.insertList(data) } } ]

 

The listview is defined has per below...

 

ListView 
{
   id: myListView
   // Associate the list view with the data model that's defined in the
   // attachedObjects list
   dataModel: dataModel
        
   // Sticky header
   layout: StackListLayout { headerMode: ListHeaderMode.Sticky }
        
   listItemComponents: [
            
     ListItemComponent 
     {
        type: "item"
              
        // Use a standard list item to display the data in the data
        // model
        StandardListItem 
        {
            imageSpaceReserved: false;
            title: ListItemData.car.model
            description: ListItemData.manufacturer.name  + " ID: " + ListItemData.manufacturer.id
        }
     }
   ]
}

 

So, in order to have the ability to group the data by car manufacturer, I figured I could simply specify the following sorting key sortingKeys: ["manufacturer.name"] but this does not work.

Any suggestions ?

 

Retired
Posts: 252
Registered: ‎08-17-2012
My Device: BlackBerry Z10 and Q10
My Carrier: Bell

Re: Grouping data via GroupDataModel & DataSource

[ Edited ]

Hi joelajean,

 

As per the documentation at this link "In a GroupDataModel, there are only two levels of items." Looking at how your xml file is formatted, i can see that the manufacturer.name is at a deeper level than the second level and that's probably why you can't retrieve the item. I suggest you try using an XmlDataModel instead of a GroupDataModel or parse your xml file into two levels of items.

@SamarAbdelsayed

Did this answer your question? Please accept post as solution.
Please refrain from posting new questions in solved threads.
Found a bug? Report it using the Issue Tracker
Developer
Posts: 136
Registered: ‎01-25-2010
My Device: Z30, Z10, Q10, Dev Alpha B & Bold 9900
My Carrier: Bell

Re: Grouping data via GroupDataModel & DataSource

Thanks... I will investigate further as per recommendation !