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
Loomist
Posts: 25
Registered: ‎02-14-2012
My Device: PlayBook / Dev Alpha

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!
Please use plain text.
Contributor
Dhanya
Posts: 21
Registered: ‎09-23-2012
My Device: BB10 Dev Alpha Device

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.

Please use plain text.
Developer
sketch34
Posts: 54
Registered: ‎05-23-2012
My Device: 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.
Please use plain text.
New Developer
Loomist
Posts: 25
Registered: ‎02-14-2012
My Device: PlayBook / Dev Alpha

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!
Please use plain text.
Developer
sketch34
Posts: 54
Registered: ‎05-23-2012
My Device: 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.
Please use plain text.
BlackBerry Development Advisor
sabdelsayed
Posts: 249
Registered: ‎08-17-2012
My Device: BlackBerry Z10 and Q10

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
Please use plain text.
Contributor
Dhanya
Posts: 21
Registered: ‎09-23-2012
My Device: BB10 Dev Alpha Device

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 :Helpsmilie: 

Please use plain text.
Developer
wantoun
Posts: 165
Registered: ‎10-04-2010
My Device: P'9982 & Z10

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
Please use plain text.