Treegrid with JSON data in jqgrid

匿名 (未验证) 提交于 2019-12-03 02:06:01

问题:

I am testing trees in jqgrid, so far I am only able to create something like below

I want to have something like jqGrid Demo page

I came up with the below code, but no idea how should I go about expanding each row in the tree from the given json format

$('
').appendTo('#topics'); var grid = jQuery("#list2"); grid.jqGrid({ datastr:topicjson, datatype: "jsonstring", height: "auto", pager: false, loadui: "disable", colNames: ["id","Items","url"], colModel: [ {name: "id",width:1,hidden:true, key:true}, {name: "elementName", width:150, resizable: false}, {name: "url",width:1,hidden:true} ], treeGrid: true, caption: "jqGrid Demos", ExpandColumn: "elementName", autowidth: true, //width: 180, rowNum: 200, //ExpandColClick: true, treeIcons: {leaf:'ui-icon-document-b'}, jsonReader: { repeatitems: false, root: "response" } });

Json format

var topicjson={     "response": [                  {                      "id": "1",                      "elementName": "Grouping",                      "sub": [                          {                              "subelementName": "Simple Grouping"                          },                          {                              "subelementName": "May be some other grouping"                          }                      ]                  },                  {                      "id": "2",                      "elementName": "CustomFormater",                      "sub": [                          {                              "subelementName": "Image Formatter"                          },                          {                              "subelementName": "Anchor Formatter"                          }                      ]                  }              ]          };
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!