PDA

View Full Version : Cleanest way to use Column Renderer with MVC?



Tim Toady
13 Apr 2012, 1:27 PM
Hey.

How are you guys using renderers with MVC? I don't really want to do the logic in the view, but dynamically setting them from the controller seems sorta weird too. The feed-viewer mvc example does it in the view. How do you guys handle it?

Thanks

Tim Toady
16 Apr 2012, 4:25 AM
nobody?

friend
16 Apr 2012, 4:30 AM
I typically create a Singleton Renderer class which contains all the renderers used throughout my app.



/**
* Singleton which encapsulates system-specific renderers.
*/
Ext.define('Myapp.view.widgets.Renderers', {
singleton: true,

active: function(value, p, record) {
var image = null;
if (value == true) {
image = 'active.png';
} else {
image = 'inactive.png';
}
return '<img src="resources/images/' + image + '">';
},

activeOnly: function(value, p, record)
{
var result = '';
if (value == true) {
result = '<img src="resources/images/active.png">';
}
return result;
},

expired: function(value, p, record) {
var result = '';
if (value == true) {
result = true
}
return result;
},


locked: function(value, p, record) {
var result = '';
if (value) {
result = '<img src="resources/images/lock.png">';
}
return result;
},

roleQuickTip: function(value, metaData, record, rowIndex, colIndex, store) {
metaData.tdAttr = 'data-qtip="' + record.get('description') + '"';

// primary roles get highlighted.
if (record.get('primaryRole') == 1) {
value = '<span class="primaryRole">' + value + '</span>';
}
return value;
}

});