Telerik Forums
Kendo UI for jQuery Forum
4 answers
171 views

I'm trying to create an editor for a HierarchicalDataSource (remotely loaded as JSON). 

I'm using `kendo.bind($('#target'),kendo.observable({data: new kendo.data.HierarchicalDataSource(<..config...>)});` to bind a hierarchical datasource with 3 levels of depth (customer -> location -> stores) [as an example]. For each level, I have a separate template for each type of child. I have a dojo demonstrating a static version.

I have several issues:

  1. Using a HierarchicalDataSource means that even if all the data is loaded at once, the tree doesn't fully populate.
  2. Declaring custom fields for child nodes doesn't auto-populate populated child nodes 
  3. In the static `data: [...]` version, it is possible to load child collections by calling `datasource.data().at(i).load()`, but it must be called twice to display the template for the children 
  4. In the remote-datasource version, load() doesn't load the data in the custom child collection ("locations"), though it does populate the dataitem.children collection. 
  5. Binding the template to `data-bind="source: children"` results in an Invalid Template error in the static version
  6. Binding the same template from #5 to `data-bind="source: locations"` works, but error #3 occurs, and load() doesn't work when first called. 
In short: given a heterogenous hierarchical dataset, how do I display nested editors for each node and its (different to itself) children?
Plamen
Telerik team
 answered on 07 Nov 2017
13 answers
1.2K+ views
Starting with the idea that there was a data query that returned multiple levels of a hierarchy in one query, what is the best way to populate a hierarchical data source with it?

For instance, take a table that has Continent, Country, Region, City as four separate columns.
How could we avoid the inefficiency of populating the hierarchy with a few thousand queries and subqueries, and instead parse the single recordset and populate the hierarchy.

Example Data:
North America, United States, Virginia, Richmond
North America, United States, Virginia, Charlottesville
North America, United States, Alaska, Anchorage
North America, Canada, Ontario, Windsor
Europe, England, Essex, Rochford

Example Hierarchy:
--- North America
--- North America --- Canada
--- North America --- Canada --- Ontario
--- North America --- Canada --- Ontario --- Windsor
--- North America --- United States
--- North America --- United States --- Alaska
--- North America --- United States --- Alaska --- Anchorage
--- North America --- United States --- Virginia
--- North America --- United States --- Virginia --- Richmond
--- North America --- United States --- Virginia --- Charlottesville
--- Europe 
--- Europe --- England
--- Europe --- England --- Essex
--- Europe --- England --- Essex --- Rochford

Alex Hajigeorgieva
Telerik team
 answered on 06 Nov 2017
2 answers
257 views

In a non-MVVM enviroment, I can define the child entities of my hierarchical datasource by setting the schema:

var datasource = new kendo.data.HierarchicalDataSource({  
    data: [ /*... */ ],  
    schema: { 
        model: {
            children: "Assets"
        }
    }
});

 

In a viewModel I am defining the same datasource like this:

function buildDataSource(data) {
     _.map(data.assets, function(item) {
        item.type = "folder";
   });
   var tree = unflatten(data.assets);
   return tree;
}
 
function loadTreeView(dataSource) {
    documentsModel.set("treeviewSource", kendo.observableHierarchy(dataSource));
    kendo.bind($("#Treeview"), documentsModel);
}
 
$.ajax({
     dataType: "json",
     url: "scripts/assets.json"
})
.then(buildDataSource)
.then(loadTreeView);

 

What is happening here, that I am loading a flat array of json objects from a file (later api endpoint) and unflatten this list, so it is in a hierachical format. The method to unflatten this array is naming the children "Assets". Running this, the treeview fails to display. If I change the unflatten method to name those children "items", the treebiew works.

You can reproduce this in this Dojo: http://dojo.telerik.com/UTOBe/3

Change items, to anything else and it stops working. How can I configure the kendo.observableHierarchy, so it uses any other property then "items" to determine if an object has children using a viewModel?

Marco
Top achievements
Rank 1
 answered on 25 Apr 2017
4 answers
661 views

Hello,

I wanted to update my TreeView control which uses a HierarchicalDataSource after I updated the array it uses.

You can see the fiddle here: https://jsfiddle.net/ZoolWay/gev9zj4j/

How can I update/refresh my TreeView after adding items? Changing a text works this way...

// how the datasource is configured:
var myData = ... // already contains two items, one with subitems
var myDataSource = new kendo.data.HierarchicalDataSource({
      data: myData
    });
 
// add item to the array:
myData.push({ 'id': 3, 'text': 'Item 3'});     
 
// read the updated array
myDataSource.read();
Alex Hajigeorgieva
Telerik team
 answered on 30 Jan 2017
1 answer
95 views

Currently i am using kendo ui hierarchical . I try to passing ID through url but its not working .

The the problem will solve if  can  get value from filter . 

How do i get value from filter which looking 

filter[filters][0][Value_ID]:1472.

 

Alex Hajigeorgieva
Telerik team
 answered on 14 Nov 2016
2 answers
125 views

Hi,

I am using ASP.NET Web API Odata as server side code to render kendo treeview using hierarchical datasource upto child node level 5. This is really very slow. Now, I need to take it up to level 10. Can you suggest any other solution, apart from Odata, where I can go upto level 10?

Prakash
Top achievements
Rank 1
 answered on 28 Apr 2016
1 answer
69 views

Hi,

I'm trying to append an "opened" class to the k-master-row tr when it's clicked and remove it when it's closed so I can do some css styling to the nested grid's parent row. Is there a way to fire a javascript function when you expand or collapse a hierarchical grid or an easier way to do this?

Kevin
Top achievements
Rank 1
 answered on 23 Mar 2016
7 answers
970 views
Dear admin,
I need to bind Hierarchy grid on main grid by button click.  Following is my example code.

001.var people = new kendo.data.DataSource({
002.      data: {!Output},
003.      batch: true,
004.      schema: {
005.            model: {
006.                fields: {
007.                    carId: { type: "string" },
008.                    vehicleId: { type: "string", editable:false  },
009.                    Percentage: { type: "number", editable:false  },
010.                    Price: { type: "string", editable:false},
011.                    CarType: { type: "string", editable:false},
012.                    CarSize: { type: "string", editable:false},
013.                    CarPerCase: { type: "number", editable:false },
014.                    Family: { type: "string", editable:false},
015.                    ModelType: { type: "string", editable:false},
016.                    EPId: { type: "string" },
017.                    Tax: { type: "string" }
018.                }
019.            }
020.        },
021.      pageSize: 20,
022.      sort: { field: "vehicleId", dir: "asc" }
023.    });   
024.var element = $("#grid").kendoGrid({
025.        dataSource: people,
026.        navigatable: true,
027.        pageable: true,
028.        toolbar: [
029.            "save",
030.            "cancel",
031.             {
032.                name: "Add",
033.                text: "Show Car Price",
034.                click: function(e) {                        
035.                    return false;
036.                }
037.             },
038.             {
039.                name: "Delete",
040.                text: "Hide Car Price",
041.                click: function(e) {                        
042.                    return false;
043.                }
044.             }
045.        ],
046.        columns:[                 
047.              {
048.                  field: "carId",
049.                  title: "Car ID",
050.                  width: 150, 
051.                  hidden:true                   
052.              },
053.              {
054.                  field: "vehicleId",
055.                  title: "Vehicle ID",
056.                  width: 100
057.              },
058.              {
059.                  field: "Percentage",
060.                  title: "Percentage",
061.                  width: 70
062.              },
063.              {
064.                  field: "Price",
065.                  title: "Price",
066.                  width: 250
067.              },
068.              {
069.                  field: "CarType",
070.                  title: "Car Type"
071.              },
072.              {
073.                  field: "CarSize",
074.                  title: "Car Size"
075.              },
076.              {
077.                  field: "CarPerCase",
078.                  title: "Car Per Case"
079.              },
080.              {
081.                  field: "Family",
082.                  title: "Family"
083.              },
084.              {
085.                  field: "ModelType",
086.                  title: "Model Type",
087.                  width: 100
088.              },
089.              {
090.                  field: "EPId",
091.                  title: "EP Id",
092.                  hidden: false
093.              },                
094.              {
095.                  field: "Tax",
096.                  title: "Tax",
097.                  format: "{0:c}",
098.                  width: 100
099.              }
100.          ],  
101.          editable:true,                                                                          
102.         groupable: true
103.         filterable: true,                    
104.         sortable: true,
105.         reorderable: true,
106.         resizable: true,
107.         columnMenu: true,                         
108.         pageable: {
109.            refresh: true,
110.            pageSizes: [10, 20, 50],
111.            buttonCount: 5
112.         },
113.         editable: "incell",              
114.         detailInit: detailInit                  
115.      });
116.// hierarchy grid
117.      function detailInit(e) {                
118.              var detailRow = e.detailRow;
119.              codeDetailData = e.data;
120. 
121.            $("<div/>").appendTo(e.detailCell).kendoGrid({                   
122.                dataSource: e.data.ItemPrices.toJSON(),                                       
123.                editable:true,
124.                navigatable: true,
125.                scrollable: false,
126.                sortable: true,
127.                pageable: true,
128.                columns: [
129.                    {
130.                        field: "Engine",
131.                        width: "200px",
132.                        editor: serviceItemAutoCompleteEditor  
133.                    },
134.                    {
135.                        field: "TN",
136.                        title:"TN",
137.                        width: "110px"
138.                    },
139.                    {
140.                        field: "TaxApplied",
141.                        title:"Tax Applied"
142.                    },
143.                    {
144.                        field: "TaxChange",
145.                        title: "Tax Change",
146.                        width: "300px"
147.                    },
148.                    {
149.                        field: "StartDate",
150.                        title: "Start Date",
151.                        format:"{0:dd-MM-yyyy}",
152.                        editor: dateTimeEditor
153.                    },
154.                    {
155.                        field: "EndDate",
156.                        title: "End Date",
157.                        format:"{0:dd-MM-yyyy}",
158.                        editor: dateTimeEditor 
159.                    }
160.                ]
161.            });
162. 
163.         }


My requirement is that the line 114 detailInit: detailInit (responsible for hierarchy grid), should not be there at the time of load of grid. There should be a button, that bind/attach hierarchy grid to main grid on click.
Hiding columns of arrows is not an option.
Vladimir Iliev
Telerik team
 answered on 23 Mar 2016
3 answers
184 views

Hi,

I have a complex object like

ID 

Name

Dob

EmploymentDetailsObject

EmergencyContactObject

I want to bind this to a Kendo Grid so the ID/Name/Dob/ are the parent row and the EmploymentDetails and EmergencyContact are child rows to this parent

I return a collection of these from an API. I thought I could just bind this collection to the Grid but it doesn't seem to work?

 Can I do this? What do I need to do?

 

Thanks

Alexander Popov
Telerik team
 answered on 20 Jan 2016
1 answer
289 views

I have a Hierarchical grid and I'm trying to add a custom editor for pop-up editing.  When I add the template to the child grid and click on the "edit" button, i get a invalid template error.  If i add that same template to the parent, it works fine.

Here is the error in console:

Uncaught Error: Invalid template:'<div class="row popupForm">    <div class="col-xs-10">  

 

I've attached a screenshot of what my grid looks like.

Here is the code

<PARENT>

  @(Html.Kendo().Grid<ParentViewModel>()
                  .Name("GridAdjax")
                  .DataSource(dataSource => dataSource
                      .Ajax()
                      .PageSize(20)
                      .Events(events => events.Error("error_handler"))
                      .Read(read => read.Action("Read", "controller"))
                      .Model(model =>
                      {
                          model.Id(c => c.Id);
                      })
                      .ServerOperation(false)
                      .Events(events => events.Error("error_handler"))
                      .Events(events => events.RequestEnd("onRequestEnd"))
                     
                  )
                  .Columns(columns =>
                  {
                      columns.Bound(p => p.CompanyName).Title("Company Name");
                      columns.Bound(p => p.CompanyDomain).Title("Company Domain");
                      columns.Bound(p => p.CompanySecurityRole).Title("Security Role");
                      columns.Bound(p => p.CompanySecurityGroup).Title("Security Group");
                  })
                  .ClientDetailTemplateId("template")
                  .Pageable()
                  .Sortable()
                  .Resizable(resize => resize.Columns(true))
                  .Events(e => e.DataBound("OnDataBound"))
                  .Deferred()

                  )
            <script id="template" type="text/kendo-tmpl">
                @(Html.Kendo().Grid<ChildlViewModel>()
            .Name("grid_#=CompanyId#")
            .DataSource(dataSource => dataSource
                .Ajax()
                .PageSize(10)
                .Update(update => update.Action("CompanyList_Update", "Administration"))
                .Read(read => read.Action("Read", "Child", new { companyId = "#=CompanyId#" }))
                        .Model(model =>
                              {
                                  model.Id(c => c.Id);
                                  model.Field(c => c.CompanySoldTo).Editable(true);
                                  model.Field(c => c.CompanyDistributionChannel).Editable(true);
                                  model.Field(c => c.CompanyDivision).Editable(true);
                                  model.Field(c => c.CompanyPlant).Editable(true);
                                  model.Field(c => c.CompanySalesOrg).Editable(true);
                              })
            )
            .Columns(columns =>
                  {
                      columns.Bound(p => p.CompanySoldTo).Title("Sold To");
                      columns.Bound(p => p.CompanyDistributionChannel).Title("Dist. Chan.");
                      columns.Bound(p => p.CompanyPlant).Title("Plant");
                      columns.Bound(p => p.CompanySalesOrg).Title("Sales Org");
                      columns.Command(command => { command.Edit(); }).Title(("Edit SAP Info."));
                  })
                    .Editable(ed => ed.Mode(GridEditMode.PopUp).TemplateName("Detail"))
            .Pageable()
            .Sortable()
            .ToClientTemplate()
                )
            </script>
            <script>
                function dataBound() {
                    this.expandRow(this.tbody.find("tr.k-master-row").first());
                }
            </script>

Mike
Top achievements
Rank 1
 answered on 26 Dec 2015
Narrow your results
Selected tags
Tags
+? more
Top users last month
Mark
Top achievements
Rank 1
Yurii
Top achievements
Rank 1
Leland
Top achievements
Rank 2
Iron
Iron
Iron
Hon
Top achievements
Rank 1
Iron
Deltaohm
Top achievements
Rank 3
Bronze
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Mark
Top achievements
Rank 1
Yurii
Top achievements
Rank 1
Leland
Top achievements
Rank 2
Iron
Iron
Iron
Hon
Top achievements
Rank 1
Iron
Deltaohm
Top achievements
Rank 3
Bronze
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?