Skip to content

Instantly share code, notes, and snippets.

@deniskyashif
Last active June 20, 2017 08:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deniskyashif/bbf9be4d4c6e2bec7f3302ad9651d3d4 to your computer and use it in GitHub Desktop.
Save deniskyashif/bbf9be4d4c6e2bec7f3302ad9651d3d4 to your computer and use it in GitHub Desktop.
// hard-code that the item will always have children
hasChildren: true
// map the hasChildren property to the hasSubordinates field, serialized from the server
hasChildren: "hasSubordinates"
// compute whether the given item will have children
hasChildren: function(item) {
return item.hasEmployees && item.relatedDepartment;
}
var dataSource = new kendo.data.TreeListDataSource({
data: [
{ employeeId: 1, name: 'Montgomery Burns', reportsTo: null, hasSubordinates: true },
{ employeeId: 2, name: "Homer Simpson", reportsTo: 1, hasSubordinates: false },
{ employeeId: 3, name: "Lenford Leonard", reportsTo: 1, hasSubordinates: false }
]
});
var treeListDataSource = new kendo.data.TreeListDataSource({
transport: {
read: {
url: 'api/employees',
type: 'GET',
dataType: 'json'
}
},
schema: { /* ... */ }
});
var treeListDataSource = new kendo.data.TreeListDataSource({
transport: { /* ... */ },
schema: {
// property mapping
model: {
id: 'employeeId', // unique id field name
parentId: 'reportsTo', // relation with another record's id
hasChildren: 'hasSubordinates', // indicates that there're records that haven't been loaded
fields: {
employeeId: { type: 'number', nullable: false },
name: { type: 'string', nullable: false },
reportsTo: { type: 'number', nullable: true }
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment