范例:checkbox单选
<input type="button" value="展开/折叠 所有节点" onclick="expandAll()"> <input type="button" value="取得选中的checkbox" onclick="getSelectedCheckboxValues()"> <input type="button" value="取得当前行的数据" onclick="getSelected()"> <br><br> <textarea id="currentRow" rows="4" cols="100"></textarea> <br><br><div id="div1" style="width:850px;"></div>
<script language="javascript"> var config = { "id_field": "id", "chk_show": true, "chk_only_selected": true, "show_summary": true, "columns":[ {"title": "组织名称", "field": "orgName"}, {"title": "ID", "field": "id", "align": "center", "width": "30", fieldCal: true, calStyle: "min"}, {"title": "组织编号", "field": "orgCode", "align": "center", "width": "60"}, {"title": "描述", "field": "orgDesc", "align": "center", "width": "100"}, {"title": "操作人", "field": "operator", "align": "center", "width": "60"}, {"title": "总人数", "field": "count", "align": "center", "width": "60", fieldCal: true, calStyle: "sum"}, {"title": "薪水", "field": "salary", "align": "center", "width": "60", fieldCal: true, calStyle: "avg", digit: 2}, {"title": "查看", "handler": "customLook", "align": "center", "width": "120"} ], "dataset":[ {"id": 1,"orgName": "城区分公司", "orgCode": "CQ", "operator": "cjm", "count": 200, "salary": 3000.50, "children":[ {"id": 5,"orgName": "城区卡品分销中心", "count": 100, "salary": 2000.00}, {"id": 6,"orgName": "先锋服务厅", "count": 50, "salary": 1000.00, "children":[ {"id": 7,"orgName": "chlid1", "count": 30, "salary": 1000.00}, {"id": 8,"orgName": "chlid2", "count": 20, "salary": 900.00}, {"id": 9,"orgName": "chlid3", "count": 20, "salary": 800.00, "children": [ {"id": 10,"orgName": "chlid3-1", "count": 10, "salary": 500.00}, {"id": 11,"orgName": "chlid3-2", "count": 10, "salary": 500.00}, {"id": 12,"orgName": "chlid3-3", "count": 10, "salary": 500.00}, {"id": 13,"orgName": "chlid3-4", "count": 10, "salary": 500.00} ]} ]}, {"id": 14,"orgName": "半环服务厅", "count": 10, "salary": 500.00} ]}, {"id": 2,"orgName": "清新分公司", "orgCode": "QX", "operator": "", "count": 10, "salary": 500.00}, {"id": 3,"orgName": "英德分公司", "orgCode": "YD", "operator": "", "count": 10, "salary": 500.00}, {"id": 4,"orgName": "佛冈分公司", "orgCode": "FG", "operator": "", "count": 10, "salary": 500.00} ] }; var treeGrid = jQuery("#div1").showTreeGrid(config); //方法返回单元格的显示内容 function customLook(trid, ptrid, row, col){ return "<a href='javascript:void(0);' style='color:blue;'>查看</a> <a href='javascript:void(0);' style='color:blue;'>编辑</a> <a href='javascript:alert(0);' style='color:blue;'>删除</a>"; } function getSelectedCheckboxValues(){ jQuery("#textarea1").val(""); var s = "values: " + treeGrid.getSelectedCheckboxValues() + "\n"; s += "level: " + treeGrid.getSelectedRowLevel() + "\n"; var items = treeGrid.getSelections(); if(items && items.length > 0){ s += "selections length: " + "\n"; s += "id,pid,index,level,orgname" + "\n"; for(var i=0; i<items.length; i++){ var item = items[i]; s += item.id + ", " + item.pid + ", " + item.index + ", " + item.level + ", " + item.data.orgName + "\n"; } } jQuery("#currentRow").val(s); } //取得当前选中的行,方法返回TreeGridItem对象 function getSelected(){ jQuery("#textarea1").val(""); var val = ""; var treeGridItem = treeGrid.getSelected(); if(treeGridItem != null){ val += "id,pid,index,level,orgname" + "\n"; //获取父数据行 var parent = treeGrid.getParent(); if(parent != null){ val += parent.id + ", " + parent.pid + ", " + parent.index + ", " + parent.level + ", " + parent.data.orgName + "\n"; } //获取当前数据 val += treeGridItem.id + ", " + treeGridItem.pid + ", " + treeGridItem.index + ", " + treeGridItem.level + ", " + treeGridItem.data.orgName + "\n"; //获取子数据行集 var children = treeGrid.getChildren(); if(children != null && children.length > 0){ for(var i=0; i<children.length; i++){ var c = children[i]; val += c.id + ", " + c.pid + ", " + c.index + ", " + c.level + ", " + c.data.orgName + "\n"; } } } jQuery("#currentRow").val(val); } </script>