extjs學習筆記4—grid

來源:互聯網
上載者:User

grid在整個項目中是比較重要的一塊,所以把它化簡了看下主體

        Ext.onReady(function () {            //myData的資料            var myData = [        ['3m Co', 71.72, 0.02, 0.03, '9/1 12:00am'],        ['Alcoa Inc', 29.01, 0.42, 1.47, '9/1 12:00am'],        ['Altria Group Inc', 83.81, 0.28, 0.34, '9/1 12:00am'],        ['American Express Company', 52.55, 0.01, 0.02, '9/1 12:00am']    ];            //創立一個store            var store = new Ext.data.ArrayStore({                fields: [           { name: 'company' },           { name: 'price', type: 'float' },           { name: 'change', type: 'float' },           { name: 'pctChange', type: 'float' },           { name: 'lastChange', type: 'date', dateFormat: 'n/j h:ia' }        ]            });            //裝載資料            store.loadData(myData);            // create the Grid            var grid = new Ext.grid.GridPanel({                //從store中讀取grid資料store: store,                columns: [            {                id: 'company',                header: 'Company',                width: 160            },            {                header: 'Price',                width: 75            },            {                header: 'Change',                width: 75            },            {                header: '% Change',                width: 75            },            {                header: 'Last Updated',                width: 85                renderer: Ext.util.Format.dateRenderer('m/Y/d')            }        ],                height: 350,                width: 600            });            //render到grid所在的div            grid.render('grid-example');        });

  

 

2012-11-2

  最近由於項目的原因有寫了很多js代碼,對extjs中grid的用法有了些新的感悟。

1、對結構進行模組化

View Code

 1 grid=Ext.extend(Ext.grid.GridPanel,{ 2     initComponent : function(){ 3     this.ds=new Ext.data.Store({ 4      //對store的執行個體化 5 });//等三種store模式 6     this.sm=new Ext.grid.CheckboxSelectionModel();//grid中表示選中行號的 7     this.cm=new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(),this.sm, 8     {header:''...dataIndex:''}         9 ]);//grid中的表頭  columnmodel10 Ext.apply(this.{11     store:this.ds,12     sm:this.sm,13     cm:this.cm,14     autoExpandColumn:'',//grid的自動拓展列''中的內容為cm中設定的id值15     bbar:new Ext.PagingToolbar({});//底部工具列16     tbar:[] //頂部工具列   17 });18 grid.superclass.initComponent.call(this);//調用父類的構建函數19 }  20 //各類其它函數  例如雙擊事件21 ,dblclick:function(){}22 });

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.