PDA

View Full Version : MVC and custom events



Wyx
20 Apr 2012, 1:09 AM
Hi,

I'm trying to build an ExtJS 4 application using MVC.
I use a DataGrid and for some reasons, I must have 2 kinds of row editing :
- double clicking on some cells should start standard row editing (I don't want cell editing)
- double clicking on other cells should start a popup window.

So I use the "beforeedit" event, and in the second case, I want to dispatch a custom event that must be caught by the controller to display the popup.

BUT it was not so easy (tell me if I'm right or wrong)

a/ Neither the editor nor the grid are aware of the controller or the application using them (they don't have any access).
b/ As the row is not an Ext Component, the controller can't listen to the beforeedit event.
c/ The controller method "control()" can only listen to component's events and nothing else.

The way I choose was to add a "controller" property to my DataGrid using the onLaunch controller method. It's not very nice (shame on me !). So from the controller I can have access to the application and then fire my custom event !

Can someone tell me if there is any nicer way for doing that ? (and tell me if a/ b/ and c/ are right or wrong).

Thanx

Wyx

jay@moduscreate.com
15 May 2012, 4:52 AM
That pattern is definitely not suggested and/or supported. You should be able to fire a custom event from your grid panel itself, and your controller will listen for it and react accordingly. I fire custom events all the time and have not had any issues :-\