Building EXT.JS MVC applications

Exj.js it’s very powerful framework that is based entirely on JavaScript using Ajax, DHTML and DOM scripting. Originally built as YUI extension, ext.js is getting more and more popular recently thanks to cross-browser compatibility and ability to easily implement solutions on mobile devices using Sencha Touch.
To fully unleash the power of Ext.js it needs to be implemented along with one of the well known server side technologies such as, php etc.

As a example we will build simple CRM application that displays and manages client’s entities.

Using Ext.js MVC pattern is very popular in conjunction with restful services. In this situation Ext.js simply executes ajax requests that are being routed to controllers that send back json response to be processed on the client side by ext.js.

Lets define basic MVC structure.


Having MVC structure ready, the first thing to do is to create model, view and controller for the entity we are going to implement. In our case we will implement Client entity. This will allow us to list, add end edit clients that we load to our store.

Let’s define our model by defining property names and it’s types. Non defined type means the the auto type will be applied (the type will be inferred from the property value at runtime).

  Ext.define('ExtMVC.model.Client', {
    extend: '',
    fields: [
        {name: 'name'},
        {name: 'address'},
        {name: 'revenue', type: 'float'},
        {name: 'growth',  type: 'float'},
        {name: 'product', type: 'float'},
        {name: 'market',  type: 'float'}

We will define our client store as array store, so we can quickly add and display client list.

  Ext.define('', {
    extend: '',
    model: 'ExtMVC.model.Client'

In our controller we need to define the model, store and views that we will be referencing.

  Ext.define('ExtMVC.controller.Clients', {
    extend: '',

    models: ['Client'],

    stores: ['Clients'],

    views: [ 

We also need to load controller when application starts. We can also load controller dynamically at any time during application lifetime.

    name: 'ExtMVC',

    controllers: [

    autoCreateViewport: true


 var controller = Ext.create(this.getModuleClassName('Clients', 'controller'), {

Last thing to do is to extend view port class and define startup objects to be displayed when application starts.

 Ext.define('ExtMVC.view.Viewport', {
    extend: 'Ext.Viewport',       
    layout: 'fit',   
    requires: [
    initComponent: function() {
        var me = this;      
        Ext.apply(me, {
            items: [
                    xtype: 'clientform'


1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)