Hi
Please help me out. I am breaking my head to achieve the load on demand treelist in kendo. I have followed the instructions as per the url http://demos.telerik.com/aspnet-mvc/treelist/remote-data-binding. But nothing worked out. My scenario is like that I need to load the parent nodes when loading the page first. Then on clicking the parent node, need to fire a call to get the child nodes. For me, it load the parent nodes first, but I can't see the expand icon coming up for nodes having children. Just see the attached image. I don't know what I'm doing wrong. Attaching the view page code and also the controller methods. Please let me know what is the issue? Well appreciated, if you could share some code for sample other than the demo sample.
View code
----------------------
<div>
@(Html.Kendo().TreeList<TelerikMvcApp1.Models.AssetModel>()
.Name("assetTreeList")
.Columns(columns =>
{
columns.Add().Field(a => a.AssetName).Width(70).Expandable(true);
})
.Sortable()
.DataSource(dataSource => dataSource
.Read(read => read.Action("LoadTree", "Home"))
.ServerOperation(false)
.Model(m =>
{
m.Id(e => e.AssetId);
m.ParentId(e => e.ParentAssetId);
m.Field(e => e.AssetName);
m.Field(e => e.ParentAssetId);
})
)
.Scrollable(true)
.Height(540)
//.Events(e => e
////.DataBound("onAssetTreeListDataBound")
//// ////.Change("treelist_change")
//)
)
</div>
Controller Methods
-------------------------------------------------
public IEnumerable<AssetModel> GetAssetTreeListBasedOnPermissions()
{
try
{
List<AssetModel> list = new List<AssetModel>();
list.Add(new AssetModel { AssetId = 1, ParentAssetId = null, AssetName = "asset1" });
list.Add(new AssetModel { AssetId = 2, ParentAssetId = 1, AssetName = "asset2" });
list.Add(new AssetModel { AssetId = 3, ParentAssetId = null, AssetName = "asset3" });
list.Add(new AssetModel { AssetId = 4, ParentAssetId = 2, AssetName = "asset4" });
IEnumerable<AssetModel> enumlist = list
.Select(x => new AssetModel
{
AssetId = x.AssetId,
ParentAssetId = x.ParentAssetId,
AssetName = x.AssetName
});
return enumlist;
}
catch (Exception ex)
{
return null;
}
}
public JsonResult LoadTree([DataSourceRequest] DataSourceRequest request, int? id)
{
var result = GetAssetTreeListBasedOnPermissions().ToTreeDataSourceResult(request,
e => e.AssetId,
e => e.ParentAssetId,
e => id.HasValue ? e.ParentAssetId == id : e.ParentAssetId == null,
e=>e
);
return Json(result, JsonRequestBehavior.AllowGet);
}
Model class
------------------------
public class AssetModel
{
public long AssetId { get; set; }
public long? ParentAssetId { get; set; }
public string AssetName { get; set; }
public bool HasChildren { get; set; }
}
Thanks in advance
Binta Prasad
Please help me out. I am breaking my head to achieve the load on demand treelist in kendo. I have followed the instructions as per the url http://demos.telerik.com/aspnet-mvc/treelist/remote-data-binding. But nothing worked out. My scenario is like that I need to load the parent nodes when loading the page first. Then on clicking the parent node, need to fire a call to get the child nodes. For me, it load the parent nodes first, but I can't see the expand icon coming up for nodes having children. Just see the attached image. I don't know what I'm doing wrong. Attaching the view page code and also the controller methods. Please let me know what is the issue? Well appreciated, if you could share some code for sample other than the demo sample.
View code
----------------------
<div>
@(Html.Kendo().TreeList<TelerikMvcApp1.Models.AssetModel>()
.Name("assetTreeList")
.Columns(columns =>
{
columns.Add().Field(a => a.AssetName).Width(70).Expandable(true);
})
.Sortable()
.DataSource(dataSource => dataSource
.Read(read => read.Action("LoadTree", "Home"))
.ServerOperation(false)
.Model(m =>
{
m.Id(e => e.AssetId);
m.ParentId(e => e.ParentAssetId);
m.Field(e => e.AssetName);
m.Field(e => e.ParentAssetId);
})
)
.Scrollable(true)
.Height(540)
//.Events(e => e
////.DataBound("onAssetTreeListDataBound")
//// ////.Change("treelist_change")
//)
)
</div>
Controller Methods
-------------------------------------------------
public IEnumerable<AssetModel> GetAssetTreeListBasedOnPermissions()
{
try
{
List<AssetModel> list = new List<AssetModel>();
list.Add(new AssetModel { AssetId = 1, ParentAssetId = null, AssetName = "asset1" });
list.Add(new AssetModel { AssetId = 2, ParentAssetId = 1, AssetName = "asset2" });
list.Add(new AssetModel { AssetId = 3, ParentAssetId = null, AssetName = "asset3" });
list.Add(new AssetModel { AssetId = 4, ParentAssetId = 2, AssetName = "asset4" });
IEnumerable<AssetModel> enumlist = list
.Select(x => new AssetModel
{
AssetId = x.AssetId,
ParentAssetId = x.ParentAssetId,
AssetName = x.AssetName
});
return enumlist;
}
catch (Exception ex)
{
return null;
}
}
public JsonResult LoadTree([DataSourceRequest] DataSourceRequest request, int? id)
{
var result = GetAssetTreeListBasedOnPermissions().ToTreeDataSourceResult(request,
e => e.AssetId,
e => e.ParentAssetId,
e => id.HasValue ? e.ParentAssetId == id : e.ParentAssetId == null,
e=>e
);
return Json(result, JsonRequestBehavior.AllowGet);
}
Model class
------------------------
public class AssetModel
{
public long AssetId { get; set; }
public long? ParentAssetId { get; set; }
public string AssetName { get; set; }
public bool HasChildren { get; set; }
}
Thanks in advance
Binta Prasad