This is a migrated thread and some comments may be shown as answers.

Datasource in tree

1 Answer 86 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 07 Sep 2013, 12:48 PM
Hello there. 
I am using kendo Mvc Ui on my application. 
In my scenario I have to used a tree view on the left side, and on the right the details section. when i click a node from the tree view, on details section it will show its details.

It is fine upto now, now the problem is like I need to show records from two tables on the tree.
Like, I have a sector table, Id and Name, another table category is Id, SectorId and name.
So now I have to bind the grid as
Sector1
      Category1
      Category2
             Category2-1
              category2-2
 
Sector2
      Category1
      Category2
             Category2-1
              category2-2
and it is based on ajax data source.

here is my configurations
@(Html.Kendo().TreeView()
   .Name("categoryList")
   .DataTextField("Name")
   .DragAndDrop(true)
   .DataSource(ds =>
   {
       // ds.Read("ajaxCateegoryList", "category");
       ds.Read(read => read.Action("ajaxCateegoryList", "category"));
   })
   .Events(evt =>
               {
                   evt.Expand("expandHandler");
                   evt.Select("selectedHandler");
               })
   )
My controller

public JsonResult ajaxCateegoryList(string id)
       {
           if (string.IsNullOrEmpty(id))
               id = Request.QueryString["id"];
 
           var cats = new List<Category>();
 
           if (!string.IsNullOrEmpty(id))
               cats = _categoryService.GetAllCategoriesByParentCategoryId(Convert.ToInt64(id)).ToList();
           else
               cats = _categoryService.getAllParentCategories();
 
 
           var model = cats.Select(x =>
               {
                   return new
                   {
                       id = x.Id,
                       Name = x.Name,
                       hasChildren = _categoryService.GetAllCategoriesByParentCategoryId(x.Id).Count > 0
                   };
               });
 
           return Json(model, JsonRequestBehavior.AllowGet);
       }
This one is being used for only category navigation. I m clue less how to make it sector base from ajax datasource, I means how the tree will understand what is sector and what is category.

1 Answer, 1 is accepted

Sort by
0
Alexander Popov
Telerik team
answered on 11 Sep 2013, 07:26 AM
Hi David,

Currently this functionality is not supported out of the box, however similar behavior could be achieved either by binding the TreeView to local data or by using Hierarchical DataSource for Kendo UI Web.

Regards,
Alexander Popov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
TreeView
Asked by
David
Top achievements
Rank 1
Answers by
Alexander Popov
Telerik team
Share this question
or