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
New Developer
Posts: 25
Registered: ‎02-14-2012
My Device: PlayBook / Dev Alpha
My Carrier: T-Mobile

XML DataSource is sorting in reverse - unable to change sort order

I'm loading XML into a ListView and no matter what, it's coming in in the reverse order of which it is listed.  Here's my code (with personal website removed)... anyone have any ideas how to change the order back to the way it's originally listed?

 

import bb.cascades 1.0
import bb.data 1.0

Page {
  content: ListView {
    id: myListView
    dataModel: dataModel
    listItemComponents: [
      ListItemComponent {
        type: "item"
        StandardListItem {
           title: ListItemData.test
        }
      }
    ]
  }
  attachedObjects: [
    GroupDataModel {
      id: dataModel
    },
    DataSource {
      id: dataSource
      source: "http://testdata.com/test.xml"
      query: "root/test"
      onDataLoaded: {
        dataModel.insertList(data);
      }
    }
  ]
  onCreationCompleted: { dataSource.load(); }
}

 

I can't use sortingKeys because I need the XML to come in the way it's listed, which isn't sortable.  I tried using sortedAscending: false/true and it didn't change the order.

 

Thank you!


:wq!
Contributor
Posts: 21
Registered: ‎09-23-2012
My Device: BB10 Dev Alpha Device
My Carrier: Vodafone

Re: XML DataSource is sorting in reverse - unable to change sort order

Hi Loomist,

    I am also facing the same issue right now. Did u found its solution?? Can you please share it.

 

Thanks in advance.

Developer
Posts: 54
Registered: ‎05-23-2012
My Device: Developer
My Carrier: Developer

Re: XML DataSource is sorting in reverse - unable to change sort order

Likewise I have the exact same problem described by Loomist.

----
I know exactly where the problem *might* be.
New Developer
Posts: 25
Registered: ‎02-14-2012
My Device: PlayBook / Dev Alpha
My Carrier: T-Mobile

Re: XML DataSource is sorting in reverse - unable to change sort order

[ Edited ]

I still haven't found a solution to this problem.  I have actually set aside the app that is requiring this, because it's just too big of an issue and I won't submit an app with such a glaring problem.  I'm guessing it might be a bug in the XML handling if others are having this issue.


:wq!
Developer
Posts: 54
Registered: ‎05-23-2012
My Device: Developer
My Carrier: Developer

Re: XML DataSource is sorting in reverse - unable to change sort order

[ Edited ]

I'm getting the issue using JSON data. The problem is probably internal to GroupDataModel (unless we're using it incorrectly).

----
I know exactly where the problem *might* be.
Highlighted
Retired
Posts: 252
Registered: ‎08-17-2012
My Device: BlackBerry Z10 and Q10
My Carrier: Bell

Re: XML DataSource is sorting in reverse - unable to change sort order

[ Edited ]

Hi all,

 

Try using an ArrayDataModel instead of a GroupDataModel. A GroupDataModel is designed to sort your data automatically, while an ArrayDataModel allows you to arrange the data in the order you want (including to leave it as is). Also, use the append() function instead of the insert().

 

For more information on the ArrayDataModel class, check this link: https://developer.blackberry.com/cascades/reference/bb__cascades__arraydatamodel.html

@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
Contributor
Posts: 21
Registered: ‎09-23-2012
My Device: BB10 Dev Alpha Device
My Carrier: Vodafone

Re: XML DataSource is sorting in reverse - unable to change sort order

Hi Samar,

 

I tried your solution and it works fine.When trying to delete items it do so from the listview and xml when there is more than one item in the list.

 

But when there exist only a single item in the list, deleting it removes data from xml but doesnt reflect the change in the listview even if I have given datasource.load(); to make the changes effective.

 

Please, Help me out ot find a solution  

Developer
Posts: 165
Registered: ‎10-04-2010
My Device: P'9982 & Z10
My Carrier: alfa Lebanon

Re: XML DataSource is sorting in reverse - unable to change sort order

Hi Dhanya,

Can you please share your code snipper to show how you did it? I'm having the same problem but the ArrayDataModel didn't work.
Wadi