c# 部门List数据怎么映射成treeReader jqgrid 4.6版本 展示树形数据
时间: 2024-03-05 13:51:03 浏览: 30
您可以使用以下步骤将C#部门List数据映射为treeReader jqgrid 4.6版本展示树形数据:
1. 将C#部门List数据转换为JSON格式数据。
2. 在jqGrid中配置treeGrid属性为true,并设置treeGridModel为'adjacency'。
3. 配置colModel中的name属性为'parent',index属性为'parent_id',hidden属性为true,表示父节点id,用于构建树形结构。
4. 配置colModel中的name属性为'id',index属性为'id',key属性为true,表示当前节点id。
5. 配置colModel中的name属性为'name',index属性为'name',表示节点名称。
6. 在jqGrid中配置treeReader属性,包括level_field、parent_id_field、leaf_field、expanded_field、loaded、icon_field等属性,用于解析JSON数据并构建树形结构。
以下是一个基本的示例代码:
```csharp
// C#部门List数据
List<Department> departments = new List<Department>();
// 转换为JSON格式数据
var jsonDepartments = JsonConvert.SerializeObject(departments);
// jqGrid配置
$("#treeGrid").jqGrid({
url: "your_url",
datatype: "json",
mtype: "GET",
colModel: [
{name: 'parent', index: 'parent_id', hidden: true},
{name: 'id', index: 'id', key: true},
{name: 'name', index: 'name'}
],
treeGrid: true,
treeGridModel: 'adjacency',
ExpandColumn: 'name',
ExpandColClick: true,
height: 'auto',
pager: '#pager',
rowNum: 10,
rowList: [10, 20, 30],
sortname: 'id',
sortorder: 'asc',
viewrecords: true,
treeReader: {
level_field: "level",
parent_id_field: "parent",
leaf_field: "isLeaf",
expanded_field: "expanded",
loaded: "loaded",
icon_field: "icon"
}
});
// 加载JSON数据
$("#treeGrid").jqGrid('setGridParam', {
datatype: 'json',
data: jsonDepartments
}).trigger('reloadGrid');
```
注意:需要引入jQuery、jqGrid和Newtonsoft.Json三个库。同时,需要根据实际情况修改配置项和JSON数据格式。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)