Extjs4 Treegrid 使用心得分享(經(jīng)驗(yàn)篇)
使用treegrid,需要在調(diào)用頁(yè)面的head中加載以下幾個(gè)文件:
<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>
然后在頁(yè)面的body中寫上一個(gè)div
<div id="tree-example"></div>
記得把json數(shù)據(jù)文件和css文件等拷貝到調(diào)用目錄下。
完成的treegrid.js代碼為:
/*
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)文章
extjs 時(shí)間范圍選擇自動(dòng)判斷的實(shí)現(xiàn)代碼
這篇文章主要介紹了extjs 時(shí)間范圍選擇自動(dòng)判斷的實(shí)現(xiàn)代碼,需要的朋友可以參考下2014-06-06
ExtJS 2.0實(shí)用簡(jiǎn)明教程之應(yīng)用ExtJS
應(yīng)用extjs需要在頁(yè)面中引入extjs的樣式及extjs庫(kù)文件2009-04-04
ExtJs 學(xué)習(xí)筆記基礎(chǔ)篇 Ext組件的使用
昨天剛接觸到Extjs,簡(jiǎn)單寫了篇學(xué)習(xí)筆記,今天繼續(xù)。2008-12-12
extjs 分頁(yè)使用jsp傳遞數(shù)據(jù)示例
extjs實(shí)現(xiàn)的分頁(yè),使用jsp傳遞數(shù)據(jù),具體實(shí)現(xiàn)過(guò)程如下,需要的朋友莫錯(cuò)過(guò)2014-07-07
ExtJs 學(xué)習(xí)筆記 Hello World!
最近學(xué)ajax,接觸到了Extjs這個(gè)強(qiáng)大的框架。我想通過(guò)我的學(xué)習(xí)筆記,最后可以讓大家上手在項(xiàng)目中使用Ext。首先我會(huì)寫一些基本的用于入門Ext的文章,打好基礎(chǔ)是很重要的。2008-12-12
extJs 下拉框聯(lián)動(dòng)實(shí)現(xiàn)代碼
extJs 下拉框聯(lián)動(dòng)實(shí)現(xiàn)代碼,需要的朋友可以參考下。2010-04-04
Extjs中TabPane如何嵌套在其他網(wǎng)頁(yè)中實(shí)現(xiàn)思路及代碼
Extjs中TabPane在一些特殊用途時(shí)把其嵌在其他的網(wǎng)頁(yè)中,很多新手朋友可能對(duì)此不是很熟悉,小編就在本文章中詳細(xì)的介紹一下,感興趣的你可不要錯(cuò)過(guò)了啊,希望本文對(duì)你有所幫助2013-01-01
解決Extjs 4 Panel作為Window組件的子組件時(shí)出現(xiàn)雙重邊框問(wèn)題
Extjs的Panel和Window等組件在默認(rèn)情況下是帶邊框的,通常情況下,單獨(dú)使用沒(méi)有什么關(guān)系,但是將Panel作為Window組件的子組件時(shí)就會(huì)出現(xiàn)雙重邊框的現(xiàn)象于是想辦法將兩重邊框去掉,變成單邊框,感興趣的朋友可以了解下2013-01-01

