Skip to content

Instantly share code, notes, and snippets.

@kfranqueiro
Created September 13, 2012 01:01
Show Gist options
  • Save kfranqueiro/3711117 to your computer and use it in GitHub Desktop.
Save kfranqueiro/3711117 to your computer and use it in GitHub Desktop.
Test for dgrid #277
<!DOCTYPE html>
<html>
<head>
<style>
#hierarchyTree {
height: 200px;
}
#hierarchyTree .dgrid-cell {
width: 100px;
}
#hierarchyTree .dgrid-header .dgrid-cell-padding {
padding: 10px;
}
#hierarchyTree .dgrid-header .dgrid-cell {
background-color: #75923c;
color: #fff;
}
</style>
</head>
<body>
<div id="hierarchyTree"></div>
<script src="dojo/dojo.js" data-dojo-config="async: true"></script>
<script>
require(["dojo/on",
"dgrid/OnDemandGrid", "dgrid/extensions/DijitRegistry", "dgrid/tree",
"dojo/_base/declare", "dojo/dom",
"dojo/store/Memory", "dojo/store/Observable", "dojo/_base/Deferred",
"dojo/store/util/QueryResults", "dojo/domReady!"],
function(on, Grid, DijitRegistry, tree, declare, dom, Memory, Observable, Deferred, QueryResults) {
var teamStore = Observable(new Memory({
data: [{
"EmployeeID": 0,
"EmployeeName": "Test Employee 1",
"ManagerEmployeeID": null,
"PrevFYYTD": 100.00,
"CurrentFYYTD": 200.00,
"PCTGrowth": 10.0,
"DollarGrowth": 100.00,
"HasChildren": true,
"HasParent": false},
{
"EmployeeID": 1,
"EmployeeName": "Test Employee 2",
"ManagerEmployeeID": 0,
"PrevFYYTD": 100.00,
"CurrentFYYTD": 200.00,
"PCTGrowth": 10.0,
"DollarGrowth": 100.00,
"HasChildren": false,
"HasParent": true},
{
"EmployeeID": 2,
"EmployeeName": "Test Employee 3",
"ManagerEmployeeID": 0,
"PrevFYYTD": 100.00,
"CurrentFYYTD": 200.00,
"PCTGrowth": 10.0,
"DollarGrowth": 100.00,
"HasChildren": false,
"HasParent": true}
],
idProperty: "EmployeeID",
getChildren: function(parent, options) {
return this.query({
ManagerEmployeeID: parent.EmployeeID
}, {
sort: [{
attribute: 'DollarGrowth',
descending: true}]
});
},
mayHaveChildren: function(parent) {
return parent.HasChildren;
},
query: function(query, options) {
var def = new Deferred();
var immediateResults = this.queryEngine(query, options)(this.data);
setTimeout(function() {
def.resolve(immediateResults);
}, 200);
var qresults = new QueryResults(def.promise);
return qresults;
}
}));
window.hierarchyTree = new (declare([Grid, DijitRegistry]))({
id: "hierarchyTree",
store: teamStore,
query: {
EmployeeID: 0 },
selectionMode: "single",
columns: {
EmployeeName: tree({
label: 'Team Members',
sortable: false
}),
CurrentFYYTD: {
label: 'FYTD1',
sortable: false
},
PrevFYYTD: {
label: 'FYTD2',
sortable: false
},
PCTGrowth: {
label: '% Growth',
sortable: false
},
DollarGrowth: {
label: 'Growth',
sortable: false
},
EmployeeID: {
label: 'YTD Summary (TTQ)',
sortable: false
},
ManagerEmployeeID: {
label: 'Market & Territory by Commission Category',
sortable: false
},
HasChildren: {
label: 'Market & Territory NO Commission Category',
sortable: false
}
}
}, "hierarchyTree");
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment