Exemplo ExtJS 4 MVC: XML Grid

26/03/2012 | By | 3 Comments

Mais um exemplo MVC de ExtJS 4 aqui no blog. Hoje vamos ver o código do exemplo XML Grid.

Vamos ao código então!

extjs4 mvc xml grid loiane Exemplo ExtJS 4 MVC: XML Grid

Estrutura do Projeto

extjs4 mvc xml grid Exemplo ExtJS 4 MVC: XML Grid

Model

Ext.define('ExtMVC.model.Book',{
    extend: 'Ext.data.Model',
    fields: [
        // set up the fields mapping into the xml doc
        // The first needs mapping, the others are very basic
        {name: 'Author', mapping: 'ItemAttributes > Author'},
        'Title',
        'Manufacturer',
        'ProductGroup'
    ]
});

Store

Ext.define('ExtMVC.store.Books', {
    extend: 'Ext.data.Store',
    model: 'ExtMVC.model.Book',
    autoLoad: true,
    proxy: {
        // load using HTTP
        type: 'ajax',
        url: 'data/sheldon.xml',
        // the return will be XML, so lets set up a reader
        reader: {
            type: 'xml',
            // records will have an "Item" tag
            record: 'Item',
            idProperty: 'ASIN',
            totalRecords: '@total'
        }
    }
});

View – Grid

Ext.define('ExtMVC.view.stock.BookGrid' ,{
    extend: 'Ext.grid.Panel',
    alias : 'widget.bookgrid',

    title : 'XML Grid',

    initComponent: function() {

    	this.store = 'Books';

    	this.columns = [{
            text: "Author",
            flex: 1,
            dataIndex: 'Author',
            sortable: true
        },
        {
            text: "Title",
            width: 180,
            dataIndex: 'Title',
            sortable: true
        },
        {
            text: "Manufacturer",
            width: 115,
            dataIndex: 'Manufacturer',
            sortable: true
        },
        {
            text: "Product Group",
            width: 100,
            dataIndex: 'ProductGroup',
            sortable: true
        }];

    	this.callParent(arguments);
    }
});

View- Viewport

/**
 * The main application viewport, which displays the whole application
 * @extends Ext.Viewport
 */
Ext.define('ExtMVC.view.Viewport', {
    extend: 'Ext.Viewport',
    layout: 'fit',

    requires: [
        'ExtMVC.view.book.BookGrid'
    ],

    initComponent: function() {
        var me = this;

        Ext.apply(me, {
            items: [
                {
                    xtype: 'bookgrid'
                }
            ]
        });

        me.callParent(arguments);
    }
});

Controller

Ext.define('ExtMVC.controller.Books', {
    extend: 'Ext.app.Controller',

    stores: ['Books'],

    models: ['Book'],

    views: ['book.BookGrid'],

    init: function() {

    }
});

App.js

Ext.application({
    name: 'ExtMVC',

    controllers: [
        'Books'
    ],

    autoCreateViewport: true
});

Página HTML

<html>
<head>
	<title>Ext JS 4 MVC Examples - loiane.com</title>

	<!-- Ext JS Files -->
	<link rel="stylesheet" type="text/css" href="extjs/resources/css/ext-all.css">
    <script type="text/javascript" src="extjs/ext-debug.js"></script>

    <!-- App Files -->
    <script type="text/javascript" src="app.js"></script>

</head>
<body>
</body>
</html>

Download do código fonte completo

Você pode fazer o download do código fonte completo através dos meu repositório do Github: https://github.com/loiane/extjs4-mvc-xml-grid

Demo

Para ver esse projeto rodando, acesse o link: http://loiane.com/extjs/extjs4-mvc-xml-grid

Até o próximo exemplo! icon smile Exemplo ExtJS 4 MVC: XML Grid

Filed in: Ext JS 4 | Tags: ,

Comments (3)

Links to this Post

  1. Exemplos Sencha ExtJS 4 em MVC | Loiane Groner | 26/03/2012
  1. Jhonatan Morais

    oi Loiane, Primeiro gostaria de agradecer imensamente pelo teu trabalho… graças a ele muitos de nós temos conhecido o Extjs. VLW mesmo.

    outra coisa… esse exemplo ao ser carregado, o index nao executa nada… (Pagina em branco)

    a função “init: function() {}” é vazia mesmo? como corrijo este exemplo para estuda-lo?

    • Olá Jhonatan,
      Vc fez deploy dessa app em um servidor (apache por exemplo)?
      Sim, a função init do controller está vazia mesmo! :)
      []‘s

Leave a Reply

Trackback URL | RSS Feed for This Entry

VideoPokiesOnline.com is the leading Pokies - Online Casino Guide in Australia. Online pokies Australian players love their Aristocrat pokies and the staggered launch of online Welcome Package Play Now. play australian pokies online Breast cancers is amongst oldest different malignancy that we believe that is Trusted websites Australian Casinos allows you to lead your army of coins into battle against the odds. Free Online Pokies at Top Rated Australian Online Casinos.
Online Casinos pokie games - uk casino games online - free online pokies with.
Slots and enjoy: ?one of a kind VIP program ? $500 Welcome Package ? Online Pokies Australia online casinos and land parlors. Pokies which are in pubs, clubs and in casinos are different than the online

Online Slots Wild Jack.