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
oddboy
Posts: 136
Registered: ‎05-24-2011
My Device: Z30 running 10.2 and Playbook 4GLTE running OS2.1
Accepted Solution

filtering a data model?

Hi,

 

i have a GroupDataModel defined as a Q_PROPERTY of a custom object attached to a ListView that holds pointers to another custom class.

 

ListView {

  dataModel: myClass.model

}

 

I'd like to be able to filter the contents in the GroupDataModel so it shows either All items, or some items based on one of the properties of the custom object in the GroupDataModel, but i'm not clear on the best way to approach this.  if it matters, i'm trying to display this in a  segmentedControl with two options... one for All, and one for "Active".

 

i tried doing this with two listViews attached to different properties of the custom object - as in:

 

ListView { dataModel: myClass.model }

 

and

 

ListView { dataModel: myClass.modelFiltered }

 

and then making one visible: true, and one visible: false depending onthe selectedIndex of the SegmentedControl.

 

that didn't work, and it seems a bit sloppy to me.

 

is there a nice clean way to do this?  mainly:

 

provide a GroupDataModel as a property of a custom object 

be able to filter or unfilter the list (simple bool)

have the UI update when the list changes

 

?

 

 

bron: a cron-like scheduler for BlackBerry 10
http://apps.oddelement.com
Developer
oddboy
Posts: 136
Registered: ‎05-24-2011
My Device: Z30 running 10.2 and Playbook 4GLTE running OS2.1

Re: filtering a data model?

I ended up with two data models, one for the complete list, and one for the filtered list.

I suppose I could have also clear()'d the model and repopulate it with a filter applied, but I didn't do it that way for reasons unknown to myself.

Anyway, seems those are the two options to use.

bron: a cron-like scheduler for BlackBerry 10
http://apps.oddelement.com
Developer
BBSJdev
Posts: 6,116
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30

Re: filtering a data model?

[ Edited ]

Another old thread.

 

For reasons unknown to yourself? Curious expression. :smileyhappy:

 

Did you look at the Filtered Model sample before embarking on this I beleive it existed then?

 

http://developer.blackberry.com/native/sampleapps/

 

In conlusion then do you think you took the right path?

I went the filtered way for my app.

 

And if you are going to resurrect this old a thread you might as well set your posting as the solution. :smileyhappy:


If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Developer
BBSJdev
Posts: 6,116
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30

Re: filtering a data model?

MIght as well mention there is also the third option of creating your own DataModel with an IndexMapper.


If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Developer
oddboy
Posts: 136
Registered: ‎05-24-2011
My Device: Z30 running 10.2 and Playbook 4GLTE running OS2.1

Re: filtering a data model?

I replied to my original question because someone asked me to by PM.

I'm satisfied enough with my solution.

Thanks for the feedback on etiquette.
bron: a cron-like scheduler for BlackBerry 10
http://apps.oddelement.com