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

Re: How to order JSON by date in QML

ListItemComponent {
                                    type: "header"
                                    Header {
                                        title: Qt.formatDate(new Date(ListItemData * 1))
                                    }
                                },

 Also leaves the headers with no text 

Developer
Posts: 543
Registered: ‎08-31-2013
My Device: Q10, Z10LE, Nokia N950, DAB....
My Carrier: Telekom Slovakia

Re: How to order JSON by date in QML

I think you need to define format which you want Smiley Wink

// 24 Feb 2011
Qt,formatDate(new Date(timestamp), 'dd MMM yyyy')

also you should know that ListItemData for header items returns data which is actually used for sorting. if item is sorted by ID then ListItemData returns ID etc...


If helped give a like. If your problem was solved mark the post as "Solution"
Portfolio: BlackBerry Nokia
Social: Twitter | Facebook
About Me / Blog DevPDA | Blog
Developer
Posts: 385
Registered: ‎07-20-2012
My Device: Blackberry Z10 (White), BlackBerry Dev Alpha C
My Carrier: O2 UK

Re: How to order JSON by date in QML

Yep I know that about the storing, which is why I think I need to do something with the sorting keys 

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

Re: How to order JSON by date in QML

Still can't seem to figure this out and I'm not sure how to order an RSS feed by date either - any help would be greatly appriciated Smiley Happy  

Developer
Posts: 543
Registered: ‎08-31-2013
My Device: Q10, Z10LE, Nokia N950, DAB....
My Carrier: Telekom Slovakia

Re: How to order JSON by date in QML

Sort it by your timestamp . Here is a simple example with 20 items, each item has date (01/01/1111) and timestamp property and are sorted by timestamp

Page {
    Container {
        id: root

        function randomDate(start, end) {
            return new Date(start.getTime() + Math.random() * (end.getTime() - start.getTime()));
            }
            
        ListView {
            onCreationCompleted: {
                for (var i = 0; i < 20; ++i){
                    var d = root.randomDate(new Date(2012, 0, 1), new Date());
                    var item = {"date": Qt.formatDate(d, "dd/MM/yyyy"), "timestamp": d.getTime()}
                    model.insert(item)
                }
            }  
            dataModel: GroupDataModel {
                id: model
                sortedAscending: true
                sortingKeys: ["timestamp"]
            }
            listItemComponents: [
                ListItemComponent {
                    type: "header"
                    Header {
                        title: Qt.formatDate(new Date(ListItemData), "dd.MM.yyyy")
                        subtitle: ListItemData
                    }
                }
            ]
        }
    }
}

 Hope it helps Smiley Wink



If helped give a like. If your problem was solved mark the post as "Solution"
Portfolio: BlackBerry Nokia
Social: Twitter | Facebook
About Me / Blog DevPDA | Blog
Developer
Posts: 385
Registered: ‎07-20-2012
My Device: Blackberry Z10 (White), BlackBerry Dev Alpha C
My Carrier: O2 UK

Re: How to order JSON by date in QML

[ Edited ]

Thanks for putting together a quick example.

I'm currently playing around with this now and the description field shows the timestamp in its numerical format but nothing is displayed for the title; I tried changing it around and changing the date format ("dddd MM MMMM yyyy") but still no luck with anything I've tried.

 

By using your example code, it works perfectly but obviously I want to incorporate my own JSON data. 

Developer
Posts: 543
Registered: ‎08-31-2013
My Device: Q10, Z10LE, Nokia N950, DAB....
My Carrier: Telekom Slovakia

Re: How to order JSON by date in QML

Your date format is not valid. Check this for more info about format date in QML
http://qt-project.org/doc/qt-4.8/qml-qt.html#formatDate-method


If helped give a like. If your problem was solved mark the post as "Solution"
Portfolio: BlackBerry Nokia
Social: Twitter | Facebook
About Me / Blog DevPDA | Blog
Highlighted
Developer
Posts: 385
Registered: ‎07-20-2012
My Device: Blackberry Z10 (White), BlackBerry Dev Alpha C
My Carrier: O2 UK

Re: How to order JSON by date in QML

That's what I have been using for my calendar function (which works perfectly) but changing the format to "dddd MMMM yyyy" didn't make any difference either Smiley Sad