PDA

View Full Version : All events from a gridPanel or any of its components, managed by a controller?



neo1010
17 Oct 2014, 11:03 AM
Hy,

1 .I am a configuring a property "tools" in a GridPanel to render some buttons and I am adding handlers for these buttons in the GridPanel but according to the MVC pattern, should I add these handlers in the controller for this GridPanel or not?

2. All the events from a GridPanel itself or any of its components, should they be managed by the controller? What are the recommended practices?

Thanks

slemmon
18 Oct 2014, 12:41 AM
Yes, you've got the right idea. Ideally, you'd handle the events from the grid and any of its descendent components (tools, buttons in toolbars, or event from the grid itself) in the controller.

For the tool you can give the tool an itemId and then in the controller's listen / control method you'll listen for that tool's click event.

If the itemId was 'myTool' then the listener config would be:


control({
'#myTool': {
click: 'theNameOfTheHandlerMethod' // this method will live on the controller
}
});

neo1010
18 Oct 2014, 6:57 AM
Thanks.

I think it is a recommended practice because if you have a gridpanel and some events are handled inside and others outside it will become a mess to find a handler; its better to have them centralized in one controller and easier to find.