Я надеюсь, что вы можете мне помочь, у меня есть такая структура:
- root A
-child_A1
-child_A1_1
-child_A1_2
-child_A1_3
-child_A2
-child_A2_1
-child_A2_2
-child_A2_3
- root B
- child_B1
-child_B1_1
-child_B1_2
-child_B1_3
Но когда я показываю данные в TreeGrid, они выглядят так:
- root A
-child_A1
-child_A2
-child_A1_1
- root B
- child_B1
-child_B1_1
-child_B1_2
-child_B1_3
-child_A1_2
-child_A1_3
-child_A2_1
-child_A2_2
-child_A2_3
Кто-нибудь знает почему .. ??? пожалуйста, помогите, я ищу информацию об этой ошибке, но не повезло ....
Вот мой JavaScript:
<script type="text/javascript">
$(document).ready(function () {
var lastsel;
$(function () {
jQuery('#tree').jqGrid({
url: '/Ubicacion/TreeGrid/',
datatype: 'json',
height: 250,
colNames: ['Nombre', 'Descripcion'],
colModel: [
{ name: 'Nombre', index: 'Nombre', width: 100, sortable: true, editable: true, edittype: "text"},
{ name: 'Descripcion', index: 'Descripcion', width: 80, editable: true, edittype: "text" }
],
caption: 'Listado de Ubicaciones',
treeGridModel: 'adjacency',
sortname: 'Nombre',
loadonce: true,
height: 'auto',
width: '500',
pager: "#pager",
treeGrid: true,
ExpandColumn: 'Id',
ExpandColClick: true,
});
});
});
А вот серверная функция, которую я использовал для генерации строки json:
public ActionResult TreeGrid(string sidx, string sord, int? page, int? rows)
{
List<Ubicacion> ubicacion = new List<Ubicacion>();
ubicacion = UbicacionRepository.GetAll().ToList<Ubicacion>();
int pageIndex = Convert.ToInt32(page) - 1;
int totalrecords = ubicacion.Count();
JsonResult json = new JsonResult();
json.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
json.Data = new
{
sidx = "Nombre",
sord = "asc",
page = page,
records = totalrecords,
rows = (from ubi in ubicacion
select new
{
cell = new string[]
{
ubi.Nombre,
ubi.Descripcion,
ubi.Nivel.ToString(),
ubi.IdPadre == 0 ? "null" : ubi.IdPadre.ToString(),
ubi.Nivel < 2 ? "false" : "true",
"false",
"true"
}
})
};
return json;
}
А вот сгенерированный JSON:
{"total":1,"page":null,"records":18,"rows":[
{"cell":["Parent A","ubicacion","0","null","false","false","true"]},
{"cell":["Child A1","ubicacion","1","1","false","false","true"]},
{"cell":["Child A2","ubicacion","1","1","false","false","true"]},
{"cell":["Child A1_1","ubicacion","2","2","true","false","true"]},
{"cell":["Parent B","ubicacion","0","null","false","false","true"]},
{"cell":["Child B1","ubicacion","1","5","false","false","true"]},
{"cell":["Child B1_1","ubicacion","2","6","true","false","true"]},
{"cell":["Child B1_2","ubicacion","2","6","true","false","true"]},
{"cell":["Child B1_3","ubicacion","2","6","true","false","true"]},
{"cell":["Child A1_2","ubicacion","2","2","true","false","true"]},
{"cell":["Child_A1_3","ubicacion","2","2","true","false","true"]},
{"cell":["Child A2_1","ubicacion","2","3","true","false","true"]},
{"cell":["Child A2_2","ubicacion","2","3","true","false","true"]},
{"cell":["Child A2_3","ubicacion","2","3","true","false","true"]}
]}