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
Developer
Posts: 386
Registered: ‎07-20-2012
My Device: Blackberry Z10 (White), BlackBerry Dev Alpha C
My Carrier: O2 UK
Accepted Solution

Drop Down Query

[ Edited ]

Hello, 

 

I am using a dropDown, within my application to filter results. 

 

Here is my code: 

 

ListView:

ListView {
                            id: listView1
                            dataModel: dataModel1

                            leadingVisual: [
                                Container {
                                    id: dropDownContainer1
                                    topPadding: 20
                                    leftPadding: 20
                                    rightPadding: 20
                                    bottomPadding: 20
                                    background: Color.create("#212121")
                                    DropDown {
                                        id: dropDown1
                                        title: qsTr("Month:")
                                        Option {
                                            text: qsTr("June")
                                            value: "Brazil"
                                        }
                                        Option {
                                            text: qsTr("July")
                                            value: "July"
                                        }
                                        onSelectedIndexChanged: {
                                            dataSource1.sQuery = dropDown1.at(dropDown1.selectedIndex).value;
                                        }
                                    }
                                }
                            ]

                            contextActions: [
                                ActionSet {
                                    id: itemActionSet
                                    title: ListItemData.title
                                    subtitle: qsTr("Actions")
                                    actions: [
                                        ActionItem {
                                            title: qsTr("Add To Saved")
                                            imageSource: "asset:///IMG/ic_add_favorite.png"

                                            onTriggered: {
                                                //Add to saved tab which can then be accessed by the user
                                            }
                                        }
                                    ]
                                }
                            ]
                            listItemComponents: [
                                ListItemComponent {
                                    type: "item"
                                    StandardListItem {
                                        title: ListItemData.listItem.title
                                    }
                                }
                            ]

                            onTriggered: {
                                var selectedItem = dataModel1.data(indexPath);
                                var detail = fixtures.createObject();

                                detail.fixtureInfo = selectedItem.listItem.fixtureInfo
                                detail.dateInfo = selectedItem.listItem.dateInfo
                                detail.timeInfo = selectedItem.listItem.timeInfo
                                detail.stadiumInfo = selectedItem.listItem.stadiumInfo

                                navigationPane1.push(detail)
                            }
                        }

 DataSource: 

attachedObjects: [
                // Definition of the second Page, used to dynamically create the Page above.
                GroupDataModel {
                    id: dataModel1
                    sortingKeys: [ "title" ]
                    grouping: ItemGrouping.ByFullValue
                },
                DataSource {
                    id: dataSource1
                    property string sQuery: ""
                    onSQueryChanged: {
                        dataModel1.clear()
                        load()
                    }
                    source: "asset:///XML/Fixtures.xml"
                    type: DataSourceType.Xml
                    remote: false
                    query: "/root/continent"

                    onDataLoaded: {
                        //create a temporary array tohold the data
                        var tempdata = new Array();
                        for (var i = 0; i < data.length; i ++) {

                            tempdata[i] = data[i]

                            //this is where we handle the search query
                            if (sQuery == "") {
                                //if no query is made, we load all the data
                                dataModel1.insert(tempdata[i])
                            } else {
                                //if the query matches any part of the country TITLE, we insert that into the list
                                //we use a regExp to compare the search query to the COUNTRY TITLE (case insenstive)
                                if (data[i].listItem.title.search(new RegExp(sQuery, "i")) != -1) {
                                    dataModel1.insert(tempdata[i])

                                    //Otherwise, we do nothingand donot insert the item
                                }

                            }

                        }

                        // this if statement below does the same as above,but handles the output if there is only one search result
                        if (tempdata[0] == undefined) {
                            tempdata = data

                            if (sQuery == "") {
                                dataModel1.insert(tempdata)
                            } else {
                                if (data.listItem.title.search(new RegExp(sQuery, "i")) != -1) {
                                    dataModel1.insert(tempdata)
                                }
                            }
                        }
                    }
                    onError: {
                        console.log(errorMessage)
                    }
                },

                ComponentDefinition {
                    id: fixtures
                    source: "FixturesDetail.qml"
                }
            ]
            onCreationCompleted: {
                dataSource1.load()
            }

 XML

<root>
    <continent title="Thursday 12 June 2014"> 
        <listItem title="Brazil vs Croatia">
        <fixtureInfo>Brazil vs Croatia</fixtureInfo>
        <dateInfo>Thursday 12 June 2014</dateInfo>
        <timeInfo>17:00PM (Local Time)</timeInfo>
        <stadiumInfo>Arena de Sao Paulo</stadiumInfo>
        </listItem>
	</continent>
</root>

 

What I am trying to do is have the dropDown filter the results based on the month. Currently, the dropDown works if the word June or July are a ListItem but I need the sQuery to check the headers (continent title) rather than the listItem - as the words June and July are in the headers and not the item. 

 

Fixtures.png

 

As you can see in the image above, the dates are in the wrong order and only a single listItem appears which links to this issue so if anyone could point me where I need to change my code to have the dates in the correct order and how to fix the listitem issue then that'd be great! Smiley Very Happy 

 

So, finally, does anyone have any idea how to go about changing the sQuery to search the header instead? 

 

Thanks Smiley Happy 

Developer
Posts: 386
Registered: ‎07-20-2012
My Device: Blackberry Z10 (White), BlackBerry Dev Alpha C
My Carrier: O2 UK

Re: Drop Down Query

I changed the value to the dates in string form so that the drop down would search the headers instead