Dynamic Loading in TreeGrid
--Source Code
<link href="<%=Url.Content("~/Scripts/jquery-easyui-1.3.2/themes/bootstrap/easyui.css")%>" rel="stylesheet" type="text/css" />
<link href="<%=Url.Content("~/Scripts/jquery-easyui-1.3.2/themes//icon.css")%>" rel="stylesheet" type="text/css" />
<link href="<%=Url.Content("~/Scripts/jquery-easyui-1.3.2/themes/demo/demo.css")%>" rel="stylesheet" type="text/css" />
<script src="<%=Url.Content("~/Scripts/jquery-easyui-1.3.2/jquery.easyui.min.js")%>" type="text/javascript"></script>
<script type="text/javascript">
function formatProgress(value) {
if (value) {
var s = '<div style="width:100%;border:1px solid #ccc">' +
'<div style="width:' + value + '%;background:#cc0000;color:#fff">' + value + '%' + '</div>'
'</div>';
return s;
} else {
return '';
}
}
// function collapseAll() {
// $('#tg').treegrid('collapseAll');
// }
// function expandAll() {
// $('#tg').treegrid('expandAll');
// }
</script>
<%--<div style="margin:10px 0;">
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="collapseAll()">全部收起</a>
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="expandAll()">全部展开</a>
</div>--%>
--Create TreeGrid
<table id="tg" title="组织架构图" class="easyui-treegrid" style="width:850px; height:350px"
data-options="
iconCls: 'icon-ok',
rownumbers: true,
animate: true,
collapsible: true,
fitColumns: true,
url: '<%=Url.Content("~/PersonalInformationEnquiry/LoadHierarchyJson") %>',
loadMsg:'正在处理,请稍后···',
idField: 'AgentCode',
treeField: 'AgentName'">
<thead>
<tr>
<th data-options="field:'AgentName'" width="290">编号/名称</th>
<th data-options="field:'AgentRank'" width="90">属性</th>
<th data-options="field:'ContractEffectiveDate'" width="100">入职日期</th>
</tr>
</thead>
</table>
--Controller返回JSON
Public Function LoadHierarchyJson() As ActionResult
Dim _agentCode As String = Request("id")
Dim _result As New List(Of Object)
Dim _json As New Dictionary(Of String, Object)
Dim _hlist As List(Of ListHierarchyContract) = Session(WebConstants.SEARCH_HIERARCHY_LIST)
For Each h In _hlist
If _agentCode Is Nothing Then
If h.ParentAgentCode Is Nothing Then
_result.Add(New With {.AgentCode = h.AgentCode,
.AgentName = h.AgentCode & "/" & h.AgentName,
.AgentRank = h.AgentRank,
.ContractEffectiveDate = Utility.DateCnToString(h.ContractEffectiveDate),
._parentId = h.ParentAgentCode,
.state = "closed"})
End If
Else
If _agentCode.Equals(h.ParentAgentCode) Then
_result.Add(New With {.AgentCode = h.AgentCode,
.AgentName = h.AgentCode & "/" & h.AgentName,
.AgentRank = h.AgentRank,
.ContractEffectiveDate = Utility.DateCnToString(h.ContractEffectiveDate),
._parentId = h.ParentAgentCode,
.state = "closed"})
End If
End If
Next
_json.Add("total", _result.Count)
_json.Add("rows", _result)
Return Json(_json)
End Function
--jQuery官方PHP解决方案
--The Server Code
--treegrid3_getdata.php
$id = isset($_POST['id']) ? intval($_POST['id']) : 0;
include 'conn.php';
$result = array();
$rs = mysql_query("select * from products where parentId=$id");
while($row = mysql_fetch_array($rs)){
$row['state'] = has_child($row['id']) ? 'closed' : 'open';
$row['total'] = $row['price']*$row['quantity'];
array_push($result, $row);
}
echo json_encode($result);
function has_child($id){
$rs = mysql_query("select count(*) from products where parentId=$id");
$row = mysql_fetch_array($rs);
return $row[0] > 0 ? true : false;
}
· 智能桌面机器人:使用 .NET 为树莓派开发 Wifi 配网功能
· C# 模式匹配全解:原理、用法与易错点
· 记一次SSD性能瓶颈排查之路——寿命与性能之间的取舍
· 理解 .NET 结构体字段的内存布局
· .NET 9中的异常处理性能提升分析:为什么过去慢,未来快
· 我的开源十年
· .net入行第4年
· C#/.NET/.NET Core优秀项目和框架2025年5月简报
· (包含5w字提示词开源)手把手教你搭建开源提示词优化平台
· 上周热点回顾(6.2-6.8)