PDA

View Full Version : Putting a record into multiple groups.



incutonez
17 Aug 2012, 9:09 AM
Is it possible to group a single record into multiple groups? Let's say I have the following code:



Ext.onReady(function() {
var store = Ext.create('Ext.data.Store', {
fields: ['name', 'profession'],
groupField: 'profession',
data: [
{name: 'jack johnson', profession: 'surfer'},
{name: 'dan aykroyd', profession: 'ghostbuster'},
{name: 'dwayne johnson', profession: 'actor'},
{name: 'chino moreno', profession: 'musician'}
]
});
var grid = Ext.create('Ext.grid.Panel', {
store: store,
columns: [{
text: 'Name',
dataIndex: 'name',
flex: 1
}, {
text: 'Profession',
dataIndex: 'profession',
flex: 2
}],
features: [{ftype: 'grouping'}],
height: 400,
width: 400,
renderTo: Ext.getBody()
});
});


Don't read too much into the professions because this is a toy example, but let's say I want to group Dan Aykroyd into two groups... "ghostbuster" and "musician." However, I don't see any examples of this online, so I'm wondering if it can be done. It seems like it can be done because I'm under the assumption that a filter is applied to the store, so it should be possible, but I have been known to be wrong.

If anyone has any insight, that'd be awesome! Thanks.

scottmartin
17 Aug 2012, 9:52 AM
Based on your model, the quickest would be to add Dan again if he belonged to both groups



{name: 'dan aykroyd', profession: 'ghostbuster'},
{name: 'dan aykroyd', profession: 'musician'},


You would have to make changes to your model if this was too clumsy.

Scott.

incutonez
17 Aug 2012, 12:18 PM
Hmm, don't like that approach. What if I had 1,000 records and each one had 2 groups they belonged to? I'd have to copy/double my data... there's got to be a cleaner way.

Would it be possible to make profession an array and then group on the array of professions for that record?

scottmartin
17 Aug 2012, 12:37 PM
Based on your current data, how do we know Dan was also a Blues Brother?


{name: 'dan aykroyd', profession: 'ghostbuster'}

Scott.

incutonez
17 Aug 2012, 5:20 PM
Who said anything about him being a Blues Brother? Haha :) But if one were to prove it, one would simply put on Soul Man (http://www.youtube.com/watch?v=YnaSRhMB_qo).

But seriously, I don't have a way of showing he's an actor and a musician... I'm wondering if you can filter on an array though. May toy around with that idea.