Jquery EasyUI實(shí)現(xiàn)treegrid上顯示checkbox并取選定值的方法
先放個最終的效果圖:

然后是代碼:
html文件:
<body> <h1>TreeGrid</h1> <div> <a id="consle" href="#">consle</a> </div> <table id="test" title="Folder Browser" style="width:400px;height:300px" > </table> </body>
說明:沒什么內(nèi)容,標(biāo)題,然后是一個表格,我為了做些測試放了個按鈕consle,不用刪掉即可,當(dāng)然要引用幾個js文件和css文件:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta name="keywords" content="jquery,ui,easy,easyui,web"> <meta name="description" content="easyui help you build your web page easily!"> <title>jQuery EasyUI Demo</title> <link rel="stylesheet" type="text/css" > <link rel="stylesheet" type="text/css" > <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.1.min.js"></script> <script type="text/javascript" src="http://www.jeasyui.com/easyui/jquery.easyui.min.js"></script> <script type="text/javascript" src="ws.js"></script>
接著是js文件:
$(function(){
$('#test').treegrid({
url:"data/treegrid_data.json",
idField:'id',
treeField:'name',
animate:"true",
rownumbers:"true",
columns:[[
{title:'Task Name',field:'name',formatter:function(value,rowData,rowIndex){
return " " + rowData.name;
},width:180},
{field:'size',title:'Persons',width:60,align:'right'},
{field:'date',title:'Begin Date',width:80}
]]
});
$("#consle").bind("click",consleclick)
});
function set_power_status(){
var idList = "";
$("input:checked").each(function(){
var id = $(this).attr("id");
if(id.indexOf("ceshi_")>-1)
idList += id.replace("ceshi_",'')+',';
})
alert(idList);
}
function consleclick(){
var node = $('#test').treegrid('expandAll',2);
}
說明:調(diào)用了easyUI的treegrid,為了顯示checkbox,對第一列做了個formatter,為了展示效果綁定了取得選中checkbox的事件,不用可以去掉,也可以去掉alert,更改為其他的事件處理函數(shù)。
最后附上數(shù)據(jù)json文件:
[{
"id":1,
"name":"C",
"size":"",
"date":"02/19/2010",
"children":[{
"id":2,
"name":"Program Files",
"size":"120 MB",
"date":"03/20/2010",
"children":[{
"id":21,
"name":"Java",
"size":"",
"date":"01/13/2010",
"state":"closed",
"children":[{
"id":211,
"name":"java.exe",
"size":"142 KB",
"date":"01/13/2010"
},{
"id":212,
"name":"jawt.dll",
"size":"5 KB",
"date":"01/13/2010"
}]
},{
"id":22,
"name":"MySQL",
"size":"",
"date":"01/13/2010",
"state":"closed",
"children":[{
"id":221,
"name":"my.ini",
"size":"10 KB",
"date":"02/26/2009"
},{
"id":222,
"name":"my-huge.ini",
"size":"5 KB",
"date":"02/26/2009"
},{
"id":223,
"name":"my-large.ini",
"size":"5 KB",
"date":"02/26/2009"
}]
}]
},{
"id":3,
"name":"eclipse",
"size":"",
"date":"01/20/2010",
"children":[{
"id":31,
"name":"eclipse.exe",
"size":"56 KB",
"date":"05/19/2009"
},{
"id":32,
"name":"eclipse.ini",
"size":"1 KB",
"date":"04/20/2010"
},{
"id":33,
"name":"notice.html",
"size":"7 KB",
"date":"03/17/2005"
}]
}]
}]
說明:
這個json直接從官網(wǎng)down的,隨處可見,也可改為url方式。
本文非原創(chuàng)摘自:http://blog.sina.com.cn/s/blog_4782108f0101eul4.html
相關(guān)文章
利用jQuery的動畫函數(shù)animate實(shí)現(xiàn)豌豆發(fā)射效果
本文主要講解jQuery的animate函數(shù)的基本用法,利用動畫函數(shù)animate實(shí)現(xiàn)豌豆發(fā)射的效果,對于學(xué)習(xí)animate很有幫助,有需要的可以參考借鑒。2016-08-08
etmvc+jQuery EasyUI+combobox多值操作實(shí)現(xiàn)角色授權(quán)實(shí)例
本篇文章主要介紹了etmvc+jQuery EasyUI+combobox多值操作實(shí)現(xiàn)角色授權(quán),實(shí)現(xiàn)對角色role進(jìn)行授權(quán)操作,有需要的可以了解一下。2016-11-11
JQuery通過后臺獲取數(shù)據(jù)遍歷到前臺的方法
今天小編就為大家分享一篇JQuery通過后臺獲取數(shù)據(jù)遍歷到前臺的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-08-08
jQuery的 $.ajax防止重復(fù)提交的兩種方法(推薦)
本文給大家分享兩種jquery 的ajax防止重復(fù)提交的方法,第一種方法對于onclick事件觸發(fā)的ajax,在beforeSend中使點(diǎn)擊按鈕不可用,ajax結(jié)果返回后置為可用,第二種利用jquery ajaxPrefilter中斷請求,對于詳情請參考下本文2016-10-10
『jQuery』.html(),.text()和.val()的概述及使用
如何使用jQuery中的.html(),.text()和.val()三種方法,用于讀取,修改元素的html結(jié)構(gòu),元素的文本內(nèi)容,以及表單元素的value值的方法2013-04-04
jQuery獲取所有父級元素及同級元素及子元素的方法(推薦)
這篇文章主要介紹了jQuery獲取所有父級元素及同級元素及子元素的方法,本文給大家介紹的非常詳細(xì),具有參考借鑒價值 ,需要的朋友可以參考下2018-01-01
基于jQuery的網(wǎng)頁右下角彈出廣告(IE7,firefox)
以前曾寫過一個,不過太麻煩了,呵呵```現(xiàn)在改進(jìn)了一下,其實(shí)很簡單:css定位層一直在右下角,用js控制層的高度增減。2010-08-08

