熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> PHP編程 >> 正文

Extjs4 Treegrid 使用心得分享(經驗篇)

2013-11-15 12:28:48  來源: PHP編程 

  最近調試EXTJS 的treegrid實例看了很多水友的文章以及官方的demo 沒一個可靠的全都無法顯示出來像對於我們習慣用C++的coder來說EXTJS簡直就是一群無政府土匪來維護的官網上連個搜索框都沒有找資料基本靠遍歷還是人工的

使用treegrid需要在調用頁面的head中加載以下幾個文件

復制代碼 代碼如下:
<link rel="stylesheet" type="text/css" href="css/extallcss">
<script type="text/javascript" src="extalljs"></script>
<script type="text/javascript" src="treegridjs"></script>

  
然後在頁面的body中寫上一個div

復制代碼 代碼如下:
<div id="treeexample"></div>

  
以上官方就這麼寫的BUT蛋疼的是JS裡沒有改不改就沒法運行成功把treegridjs中的renderto改成我們的div的ID就行了

記得把json數據文件和css文件等拷貝到調用目錄下
完成的treegridjs代碼為

復制代碼 代碼如下:

  
/*
This file is part of Ext JS
Copyright (c) Sencha Inc
Contact:
GNU General Public License Usage
This file may be used under the terms of the GNU General Public License version 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 requirements will be met:
If you are unsure which license is appropriate for your use please contact the sales department at
*/
Extrequire([
Extdata*
Extgrid*
Exttree*
]);
ExtonReady(function() {
//we want to setup a model and store instead of using dataUrl
Extdefine(Task {
extend: ExtdataModel
fields: [
{name: task type: string}
{name: user type: string}
{name: duration type: string}
]
});
var store = Extcreate(ExtdataTreeStore {
model: Task
proxy: {
type: ajax
//the store will get the content from the json file
url: treegridjson
}
folderSort: true
});
//ExtuxtreeTreeGrid is no longer a Ux You can simply use a treeTreePanel
var tree = Extcreate(ExttreePanel {
title: Core Team Projects
width:
height:
renderTo: treeexample//B的官方和SV黨們這裡竟然是getbodybo你妹啊
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:
sortable: true
dataIndex: task
}{
//we must use the templateheader component so we can use a custom tpl
xtype: templatecolumn
text: Duration
flex:
sortable: true
dataIndex: duration
align: center
//add in the custom tpl for the rows
tpl: Extcreate(ExtXTemplate {duration:thisformatHours} {
formatHours: function(v) {
if (v < ) {
return Mathround(v * ) + mins;
} else if (Mathfloor(v) !== v) {
var min = v Mathfloor(v);
return Mathfloor(v) + h + Mathround(min * ) + m;
} else {
return v + hour + (v === ? : s);
}
}
})
}{
text: Assigned To
flex:
dataIndex: user
sortable: true
}]
});
});


From:http://tw.wingwit.com/Article/program/PHP/201311/21028.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.