使用Ext.grid.Panel產生表格

來源:互聯網
上載者:User

使用Ext.grid.Panel產生表格Ext.grid.Panel繼承了Ext.panel.Panel,因此它的很多地方都類似於Ext.panel.Panel,但定義Ext.grid.Panel時必須指定如下兩個選項。Ø store:該選項指定的Store對象負責為該表格提供資料。Ø columns:指定Ext.grid.column.Column數組或一個包含items屬性(該屬性值為Ext.grid.column.Column數組)的對象,該Ext.grid.column.Column數組指定Ext.grid.Panel產生的表格包含的所有列。如下代碼示範了如何使用Ext.grid.Panel來產生表格。程式清單:codes\06\6.8\Ext.grid\Ext.grid.Panel.html<body><script type="text/javascript">Ext.onReady(function(){    Ext.define('Book', {         extend: 'Ext.data.Model',         fields: [               {name: 'name', type: 'string'},               {name: 'author', type: 'string'},               {name: 'price', type: 'float'},               {name: 'publishDate', type: 'date'}         ]    });    // 建立一個Ext.data.Store對象    var bookStore = Ext.create('Ext.data.Store',    {         // 指定使用Book Model管理記錄         model: 'Book',         // 直接使用data指定資料         data : [               {"id": 1, name: "瘋狂Java講義",                    author:'李剛' , price: 109, publishDate:'2012-01-01'},               {"id": 2, name:"輕量級Java EE公司專屬應用程式實戰",                    author:'李剛' , price: 99, publishDate:'2011-09-02'},               {"id": 3, name: "瘋狂Ajax講義",                    author:'李剛' , price: 69, publishDate:'2012-09-08'},         ]    });    Ext.create('Ext.grid.Panel', {         title: '查看圖書',         width: 550, // 指定表單寬度         renderTo: Ext.getBody(),         // 定義該表格包含的所有資料列         columns: [   www.2cto.com               { text: '書名', dataIndex: 'name' , flex: 1 }, // 第1個資料列               { text: '作者', dataIndex: 'author', flex: 1 }, // 第2個資料列               { text: '價格', dataIndex: 'price' , flex: 1 }, // 第3個資料列               // 第4個資料列               { text: '出版時間', dataIndex: 'publishDate',                    xtype:'datecolumn' , format:'Y年m月d日' , flex: 1},         ],         store: bookStore    });});</script></body> 上面的樣本建立了一個Ext.grid.Panel,這個Panel對象將會在頁面上產生一個表格。定義該Ext.grid.Panel對象時指定了columns、store兩個選項,其中columns選項指定該表格包含的資料列,以及各列所顯示的資料;store選項指定一個Store對象,該Store負責提供該表格顯示的資料。在瀏覽器中瀏覽該頁面,可以看到6.71所示效果。圖6.71 使用Ext.grid.Panel產生表格從圖6.71可以看出,使用Ext.grid.Panel產生的表格比普通HTML表格更美觀,而且該表格預設可以對各列進行排序,並且可以自由控制各列的顯示、隱藏。除此之外,Ext.grid.Panel產生表格的列預設允許通過拖動改變列寬、通過拖動改變列與列之間的排列順序。 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.