Extjs4 Treegrid 使用心得分享(經(jīng)驗(yàn)篇)
更新時(shí)間:2013年07月01日 17:31:04 投稿:whsnow
最近調(diào)試EXTJS 4的treegrid實(shí)例,看了很多水友的文章,以及官方的demo,沒一個(gè)可靠的,于是乎自己折騰中...感興趣的朋友可以了解下本文或許對你有所幫助
使用treegrid,需要在調(diào)用頁面的head中加載以下幾個(gè)文件:
復(fù)制代碼 代碼如下:
<link rel="stylesheet" type="text/css" href="css/ext-all.css">
<script type="text/javascript" src="ext-all.js"></script>
<script type="text/javascript" src="treegrid.js"></script>
然后在頁面的body中寫上一個(gè)div
復(fù)制代碼 代碼如下:
<div id="tree-example"></div>
記得把json數(shù)據(jù)文件和css文件等拷貝到調(diào)用目錄下。
完成的treegrid.js代碼為:
復(fù)制代碼 代碼如下:
/*
This file is part of Ext JS 4
Copyright (c) 2011 Sencha Inc
Contact: http://www.sencha.com/contact
GNU General Public License Usage
This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
*/
Ext.require([
'Ext.data.*',
'Ext.grid.*',
'Ext.tree.*'
]);
Ext.onReady(function() {
//we want to setup a model and store instead of using dataUrl
Ext.define('Task', {
extend: 'Ext.data.Model',
fields: [
{name: 'task', type: 'string'},
{name: 'user', type: 'string'},
{name: 'duration', type: 'string'}
]
});
var store = Ext.create('Ext.data.TreeStore', {
model: 'Task',
proxy: {
type: 'ajax',
//the store will get the content from the .json file
url: 'treegrid.json'
},
folderSort: true
});
//Ext.ux.tree.TreeGrid is no longer a Ux. You can simply use a tree.TreePanel
var tree = Ext.create('Ext.tree.Panel', {
title: 'Core Team Projects',
width: 500,
height: 300,
collapsible: true,
useArrows: true,
rootVisible: false,
store: store,
multiSelect: true,
singleExpand: true,
//the 'columns' property is now 'headers'
columns: [{
xtype: 'treecolumn', //this is so we know which column will show the tree
text: 'Task',
flex: 2,
sortable: true,
dataIndex: 'task'
},{
//we must use the templateheader component so we can use a custom tpl
xtype: 'templatecolumn',
text: 'Duration',
flex: 1,
sortable: true,
dataIndex: 'duration',
align: 'center',
//add in the custom tpl for the rows
tpl: Ext.create('Ext.XTemplate', '{duration:this.formatHours}', {
formatHours: function(v) {
if (v < 1) {
return Math.round(v * 60) + ' mins';
} else if (Math.floor(v) !== v) {
var min = v - Math.floor(v);
return Math.floor(v) + 'h ' + Math.round(min * 60) + 'm';
} else {
return v + ' hour' + (v === 1 ? '' : 's');
}
}
})
},{
text: 'Assigned To',
flex: 1,
dataIndex: 'user',
sortable: true
}]
});
});
相關(guān)文章
ExtJS4 組件化編程,動態(tài)加載,面向?qū)ο?,Direct
ExtJS4終于出了正式版,體驗(yàn)一下面官方推薦的向?qū)ο缶幊套罴褜?shí)踐 過去的做法是new對象或者Ext.create一個(gè)對象,每個(gè)對象都要先實(shí)例化才能使用2011-05-05Extjs EditorGridPanel中ComboBox列的顯示問題
EditorGridPanel中嵌入ComboBox通常不會正常顯示ComboBox的store中本想顯示字段,而是顯示的EditorGridPanel中 store的dataindex指定的字段內(nèi)容。2011-07-07Extjs中DisplayField的日期或者數(shù)字格式化擴(kuò)展
在用Extjs的時(shí)候,有時(shí)需要對 Ext.form.DisplyField 進(jìn)行格式化。2010-09-09extjs DataReader、JsonReader、XmlReader的構(gòu)造方法
DataReader、JsonReader、XmlReader的構(gòu)造方法,需要的朋友可以參考下。2009-11-11extjs_02_grid顯示本地?cái)?shù)據(jù)、顯示跨域數(shù)據(jù)
這篇文章主要介紹了extjs_02_grid顯示本地?cái)?shù)據(jù)、顯示跨域數(shù)據(jù)的具體實(shí)現(xiàn),需要的朋友可以參考下2014-06-06Extjs學(xué)習(xí)筆記之三 extjs form更多的表單項(xiàng)
本文接著上講Extjs學(xué)習(xí)筆記之二 Extjs之Form介紹Extjs的表單。Extjs除了類似普通的html form的表單項(xiàng)之外,還有一些功能更為豐富實(shí)用的表單項(xiàng)。2010-01-01