PDA

View Full Version : Access controller function from a view



dobberph
18 Oct 2012, 4:05 AM
Hello,
I have a MVC-architecture for Ext 4.x produced over Architect 2.1.

Controller:


Ext.define('pruefkoepfeApp.controller.controller', {
extend: 'Ext.app.Controller',
alias: 'controller.controller',
models: [
'model_gruppenstrahler', ...
],
stores: [
'store_gruppenstrahler', ...
],
views: [
'view_gruppenstrahler', ...
],
...
degreeRenderer: function(value, metaData) {
return value + '';
}


view_kontakttechnik:


Ext.define('pruefkoepfeApp.view.view_kontakttechnik', {
extend: 'Ext.grid.Panel',
alias: 'widget.view_kontakttechnik',
...
initComponent: function() {
var me = this;
Ext.applyIf(me, {
viewConfig: {
},
columns: [
...
{
xtype: 'numbercolumn',
renderer: function (value, metaData){
return pruefkoepfeApp.controller.controller.degreeRenderer(value, metaData);
},
width: 60,
align: 'right',
dataIndex: 'frequenz',
text: 'Frequenz',
editor: {
xtype: 'numberfield',
fieldLabel: 'Label',
hideLabel: true,
decimalSeparator: ','
}
},


How can I access the custom function degreeRenderer of the controller?
Can somebody help me please?
Before you say: by the way use: renderer: degreeRenderer(...);
This is not possible due to a bug in architect.

Thanks a lot,
Tobias

a.premkumar
18 Oct 2012, 9:26 PM
Hi,

If you use MVC pattern, then why can't you create a instance of controller and call the function?

like this in you view:


var control = Ext.create('purefkoepfeApp.controller.controller');
control.degreeRenderer();


or maybe like this,



controllers:['controller'],
.....
var control = this.getController('controller');
control.degreeRenderer();


Regards,
Premkumar.

dobberph
19 Oct 2012, 6:18 AM
Ah, this might work too, thanks.
I inserted the rendererfunction several times now. Not really good programming but it works too.
But thanks for your hint.
Best regards,
Tobias