原創(chuàng)|使用教程|編輯:龔雪|2016-08-10 09:22:17.000|閱讀 843 次
概述:有時我們已經(jīng)得到充分的分層樹形網(wǎng)格的數(shù)據(jù),我們還想讓樹形網(wǎng)格按層次延遲加載節(jié)點。本教程展示如何創(chuàng)建帶有延遲加載特性的樹形網(wǎng)格。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
Kendo UI for jQuery——創(chuàng)建現(xiàn)代Web應(yīng)用程序的最完整UI庫!查看詳情>>>
有時我們已經(jīng)得到充分的分層樹形網(wǎng)格的數(shù)據(jù),我們還想讓樹形網(wǎng)格按層次延遲加載節(jié)點。首先,只加載頂層節(jié)點;然后點擊節(jié)點的展開圖標來加載它的子節(jié)點。本教程展示如何創(chuàng)建帶有延遲加載特性的樹形網(wǎng)格。

<table id="test" title="Folder Browser" class="easyui-treegrid" style="width:700px;height:300px" data-options=" url: 'data/treegrid_data.json', method: 'get', rownumbers: true, idField: 'id', treeField: 'name', loadFilter: myLoadFilter "> <thead> <tr> <th field="name" width="220">Name</th> <th field="size" width="100" align="right">Size</th> <th field="date" width="150">Modified Date</th> </tr> </thead> </table>
為了放置加載子節(jié)點,我們需要為每個節(jié)點重命名'children'屬性。 正如下面的代碼所示,'children'屬性重命名為'children1'。 當(dāng)展開一個節(jié)點時,我們調(diào)用'append'方法來加載它的子節(jié)點數(shù)據(jù)。
function myLoadFilter(data,parentId){
function setData(data){
var todo = [];
for(var i=0; i<data.length; i++){
todo.push(data[i]);
}
while(todo.length){
var node = todo.shift();
if (node.children && node.children.length){
node.state = 'closed';
node.children1 = node.children;
node.children = undefined;
todo = todo.concat(node.children1);
}
}
}
setData(data);
var tg = $(this);
var opts = tg.treegrid('options');
opts.onBeforeExpand = function(row){
if (row.children1){
tg.treegrid('append',{
parent: row[opts.idField],
data: row.children1
});
row.children1 = undefined;
tg.treegrid('expand', row[opts.idField]);
}
return row.children1 == undefined;
};
return data;
}
下載EasyUI示例:
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@ke049m.cn
文章轉(zhuǎn)載自:慧都控件網(wǎng)