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
Highlighted
Contributor
Posts: 27
Registered: ‎07-30-2011
My Device: Z10
My Carrier: Tmobile

Sort list in QML (data form XML)

HI all,

 

I would like to know how to sort a list that is filled with an XML (form assets).

 

This is the code:

import bb.cascades 1.0
import bb.data 1.0
import "Common"

NavigationPane {
    id: nav
    peekEnabled: true
    Page {
        Container {
            layout: StackLayout {
            }
            Label {
                horizontalAlignment: HorizontalAlignment.Center
                text: "text"
                textStyle.base: textStyleBoldBig.style
                id: labelTest
            }
            Container {
                topPadding: 5
                bottomPadding: topPadding
                ListView {
                    id: countriesList
                    dataModel: XmlDataModel {
                        source: "models/countries.xml"
                    }
                    listItemComponents: [
                        ListItemComponent {
                            type: "country"
                            CountryItem {
                            }
                        }
                    ]
                    onTriggered: {
                        var chosenItem = dataModel.data(indexPath);
                        var contentPage = phoneListDefinition.createObject();
                        var modelFile = chosenItem.file;
                        if (! modelFile) {
                            modelFile = "models/countries/" + chosenItem.name.toLowerCase() + ".xml";
                        }
                        contentPage.listDataModel.source = modelFile;
                        nav.push(contentPage);
                    }
                    layout: FlowListLayout {
                        orientation: LayoutOrientation.TopToBottom
                        headerMode: ListHeaderMode.Standard
                    }
                }
            } // End list Container
        } //End main Container
    } // End Page
    attachedObjects: [
        ComponentDefinition {
            id: phoneListDefinition
            source: "PhoneList.qml"
        }
    ]
}

 

Thanks!

Developer
Posts: 262
Registered: ‎07-13-2012
My Device: PlayBook, DA B, DA C, LE Z10 #102, Q10, Z30
My Carrier: T-Mobile

Re: Sort list in QML (data form XML)

Use sorting keys in the GroupDataModel of ListView. https://developer.blackberry.com/cascades/reference/bb__cascades__groupdatamodel.html

---
Check out my BB10 Cascades Coding site: BBcascades.com & Cascades Blog: bbcascadescode.tumblr.com

My Built for BlackBerry app: The Dive Plan