How can I add data source to kendo-tree-view with this data, my ID in this case is projectAttachmentFolderId and parent id - projectAttachementFolderParentId
var flatData = [{ "projectAttachmentFolderId": null, "projectAttachementFolderParentId": -1, "projectAttachmentFolderName": "Root", "projectIAttachmentHasUniquePermissions": 1, "projectIAttachmentIsFolder": 1, "canCreate": true, "canDelete": true, "canRead": true, "canUpdate": true, "projectAttachmentFolderId2": null, "projectIAttachmentId": -1, "folderType": null, "id": 0 },
{ "projectAttachmentFolderId": 5112, "projectAttachementFolderParentId": null, "projectAttachmentFolderName": "Dokumenty klienta", "projectIAttachmentHasUniquePermissions": 1, "projectIAttachmentIsFolder": 1, "canCreate": true, "canDelete": true, "canRead": true, "canUpdate": true, "projectAttachmentFolderId2": null, "projectIAttachmentId": 6161, "folderType": 4, "id": 0 },
{ "projectAttachmentFolderId": 5156, "projectAttachementFolderParentId": null, "projectAttachmentFolderName": "Dokumenty klienta", "projectIAttachmentHasUniquePermissions": 1, "projectIAttachmentIsFolder": 1, "canCreate": true, "canDelete": true, "canRead": true, "canUpdate": true, "projectAttachmentFolderId2": null, "projectIAttachmentId": 6228, "folderType": 4, "id": 0 },
{ "projectAttachmentFolderId": 5157, "projectAttachementFolderParentId": null, "projectAttachmentFolderName": "Test projekt", "projectIAttachmentHasUniquePermissions": 1, "projectIAttachmentIsFolder": 1, "canCreate": true, "canDelete": true, "canRead": true, "canUpdate": true, "projectAttachmentFolderId2": null, "projectIAttachmentId": 6230, "folderType": 5, "id": 0 },
{ "projectAttachmentFolderId": 5158, "projectAttachementFolderParentId": 5157, "projectAttachmentFolderName": "test2", "projectIAttachmentHasUniquePermissions": 1, "projectIAttachmentIsFolder": 1, "canCreate": true, "canDelete": true, "canRead": true, "canUpdate": true, "projectAttachmentFolderId2": null, "projectIAttachmentId": 6233, "folderType": 1, "id": 0 },
{ "projectAttachmentFolderId": 5159, "projectAttachementFolderParentId": 5157, "projectAttachmentFolderName": "test3", "projectIAttachmentHasUniquePermissions": 1, "projectIAttachmentIsFolder": 1, "canCreate": true, "canDelete": true, "canRead": true, "canUpdate": true, "projectAttachmentFolderId2": null, "projectIAttachmentId": 6235, "folderType": 1, "id": 0 },
{ "projectAttachmentFolderId": 5160, "projectAttachementFolderParentId": 5157, "projectAttachmentFolderName": "test4", "projectIAttachmentHasUniquePermissions": 1, "projectIAttachmentIsFolder": 1, "canCreate": true, "canDelete": true, "canRead": true, "canUpdate": true, "projectAttachmentFolderId2": null, "projectIAttachmentId": 6236, "folderType": 1, "id": 0 },
{ "projectAttachmentFolderId": 5161, "projectAttachementFolderParentId": null, "projectAttachmentFolderName": "testProj2", "projectIAttachmentHasUniquePermissions": 1, "projectIAttachmentIsFolder": 1, "canCreate": true, "canDelete": true, "canRead": true, "canUpdate": true, "projectAttachmentFolderId2": null, "projectIAttachmentId": 6237, "folderType": 5, "id": 0 },
{ "projectAttachmentFolderId": 5162, "projectAttachementFolderParentId": 5161, "projectAttachmentFolderName": "Dokumenty projektowe", "projectIAttachmentHasUniquePermissions": 1, "projectIAttachmentIsFolder": 1, "canCreate": true, "canDelete": true, "canRead": true, "canUpdate": true, "projectAttachmentFolderId2": null, "projectIAttachmentId": 6238, "folderType": 1, "id": 0 },
{ "projectAttachmentFolderId": 5163, "projectAttachementFolderParentId": 5162, "projectAttachmentFolderName": "FleBOK", "projectIAttachmentHasUniquePermissions": 1, "projectIAttachmentIsFolder": 1, "canCreate": true, "canDelete": true, "canRead": true, "canUpdate": true, "projectAttachmentFolderId2": null, "projectIAttachmentId": 6239, "folderType": 1, "id": 0 },
{ "projectAttachmentFolderId": 5164, "projectAttachementFolderParentId": 5163, "projectAttachmentFolderName": "Dokumenty robocze", "projectIAttachmentHasUniquePermissions": 1, "projectIAttachmentIsFolder": 1, "canCreate": true, "canDelete": true, "canRead": true, "canUpdate": true, "projectAttachmentFolderId2": null, "projectIAttachmentId": 6240, "folderType": 1, "id": 0 },
{ "projectAttachmentFolderId": 5165, "projectAttachementFolderParentId": 5157, "projectAttachmentFolderName": "Dokumenty projektowe", "projectIAttachmentHasUniquePermissions": 1, "projectIAttachmentIsFolder": 1, "canCreate": true, "canDelete": true, "canRead": true, "canUpdate": true, "projectAttachmentFolderId2": null, "projectIAttachmentId": 6242, "folderType": 1, "id": 0 },
{ "projectAttachmentFolderId": 5166, "projectAttachementFolderParentId": 5165, "projectAttachmentFolderName": "FlexBOK", "projectIAttachmentHasUniquePermissions": 1, "projectIAttachmentIsFolder": 1, "canCreate": true, "canDelete": true, "canRead": true, "canUpdate": true, "projectAttachmentFolderId2": null, "projectIAttachmentId": 6243, "folderType": 1, "id": 0 },
{ "projectAttachmentFolderId": 5167, "projectAttachementFolderParentId": 5166, "projectAttachmentFolderName": "Dokumenty finalne", "projectIAttachmentHasUniquePermissions": 1, "projectIAttachmentIsFolder": 1, "canCreate": true, "canDelete": true, "canRead": true, "canUpdate": true, "projectAttachmentFolderId2": null, "projectIAttachmentId": 6244, "folderType": 2, "id": 0 },
{ "projectAttachmentFolderId": 5168, "projectAttachementFolderParentId": 5163, "projectAttachmentFolderName": "Dokumenty finalne", "projectIAttachmentHasUniquePermissions": 1, "projectIAttachmentIsFolder": 1, "canCreate": true, "canDelete": true, "canRead": true, "canUpdate": true, "projectAttachmentFolderId2": null, "projectIAttachmentId": 6248, "folderType": 2, "id": 0 }];
vm.folders2 = processTable(flatData, "projectAttachmentFolderId", "projectAttachementFolderParentId", -1);
Next I convert flatData to herarchical folders vm.folders2. Here is this function:
function processTable(data, idField, foreignKey, rootLevel) {
var hash = {};
for (var i = 0; i < data.length; i++) {
var item = data[i];
var id = item[idField];
var parentId = item[foreignKey];
hash[id] = hash[id] || [];
hash[parentId] = hash[parentId] || [];
item.items = hash[id];
hash[parentId].push(item);
}
return hash[rootLevel];
}
Next I try data to my HierarchicalDataSource.
$scope.treeNewDataSource = new kendo.data.HierarchicalDataSource({
data: vm.folders2,
schema: {
model: {
id: "projectattachmentfolderid",
fields: {
projectAttachmentFolderId:{ type: "number" },
projectAttachementFolderParentId: { type: "number" },
projectAttachmentFolderName: { type: "string" },
projectIAttachmentHasUniquePermissions: { type: "number" },
projectIAttachmentIsFolder: { type: "number" },
canCreate: { type: "boolean" },
canDelete: { type: "boolean" },
canRead: { type: "boolean" },
canUpdate: { type: "boolean" },
projectAttachmentFolderId2: { type: "number" },
projectIAttachmentId: { type: "number" },
folderType: { type: "number" },
id: { type: "number" }
},
haschildren: function (x) {
var id = x.projectattachmentfolderid;
//alert('id:' + x.id + ' parent: ' + x.parent);
var flatData = vm.folders2;
for (var i = 0; i < flatdata.length; i++) {
if (flatdata[i].projectattachementfolderparentid == id) {
return true;
}
}
return false;
}
}
}
});
At lest I add this to my treeview in cshtml:
<div kendo-tree-view="tree" class="hasMenu" id="tree" k-data-source="treeData">
<span class="hasMenu treeViewSpans" k-template id="{{dataItem.projectAttachmentFolderId}}" projectattachmentfolderid="{{dataItem.projectAttachmentFolderId}}" projectattachementfolderparentid="{{dataItem.projectAttachementFolderParentId}}">
{{dataItem.projectAttachmentFolderName}}
</span>
</div>
When I do this I dont have nodes in tree...What is wrong ?
First I see this errors :
var dsTree = new kendo.data.HierarchicalDataSource({
data: vm.folders2,
schema: {
model: {
id: "projectAttachmentFolderId",
children: "items",
hasChildren: "HasChildren"
}
}
});
look at prop: hasChildren
and it's children
and not fields