PDA

View Full Version : ComponentView with various Item Types?



andystalick
11 Jan 2012, 10:28 AM
Hello All-

I'm working on a list (using ComponentList, actually, but let's set that aside) and I want to use several types of custom components for Items, depending on a Type declared in the data.

One might be "text with an icon" while another might be a structured bar with icons and text. These might extend DataItem or the might each be a child of a common DataItem component that instantiates them based on data.

Ideas?

mitchellsimoens
11 Jan 2012, 11:15 AM
You can override the getDataItemConfig method within the ComponentView. By default it is:


getDataItemConfig: function(xtype, record, itemConfig) {
return {
xtype: xtype,
record: record,
defaults: itemConfig
};
}

The xtype will be the value in the defaultType config but you can return whatever you want really.

andystalick
11 Jan 2012, 11:34 AM
That is exactly what I was looking for!

I modded it like this:


getDataItemConfig: function(xtype, record, itemConfig) {
if(record.data.itemType) {
xtype = record.data.itemType;
}
return {
xtype: xtype,
record: record,
defaults: itemConfig
};
}


Now to write some more DataItem extensions that support group headers. Got one already that works!