首頁  >  文章  >  web前端  >  Extjs4 Treegrid 用心得分享(經驗篇)_extjs

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

WBOY
WBOY原創
2016-05-16 17:30:321303瀏覽

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

使用treegrid,需要在呼叫頁面的head中載入以下幾個檔案:

複製程式碼 程式碼如下:





然後在頁面的body中寫上一個div
複製程式碼 程式碼如下:

 


以上官方就這麼寫的,BUT,蛋痛的是,JS裡沒有改,不改就沒辦法運行成功。把treegrid.js中的renderto,改成我們的div的ID就行了。

記得把json資料檔和css檔等拷貝到呼叫目錄下。
完成的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 follo information to 0wing information to Publicure GNU NUversion. 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,
renderTo: 'tree-example',//2B的官方和SV黨們,這裡竟然是getbody,bo你妹啊。
collapsible: true,
useArrows: true,
rootVisible: false,
store: store,
multiSelect: true,
singleExpand: true, /thetrue' ' 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: 'templaten'
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 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 }] }); });
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn