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. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Cascades Development

Reply
Contributor
joanpuigsanz
Posts: 24
Registered: ‎07-30-2011
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!

Please use plain text.
Developer
bcs925
Posts: 212
Registered: ‎07-13-2012
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
Please use plain text.