Created
February 27, 2014 13:14
-
-
Save rhpijnacker/9249778 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML> | |
<html> | |
<head> | |
<title>dgrid performance test</title> | |
<link rel="stylesheet" href="dijit/themes/claro/claro.css" /> | |
<script type="text/javascript"> | |
var dojoConfig = { | |
async: true, | |
baseUrl: "./", | |
parseOnLoad: false, | |
paths: { | |
"dojo": "./dojo", | |
"dojox": "./dojox", | |
"dijit": "./dijit", | |
"dgrid": "./dgrid", | |
"put-selector": "./put-selector", | |
"xstyle": "./xstyle" | |
} | |
}; | |
</script> | |
<script src="dojo/dojo.js" type="text/javascript"></script> | |
</head> | |
<body class="claro"> | |
<div style="display: inline; width: 100%; height: 100%"> | |
<div id="grid" style="height: 800px"></div> | |
</div> | |
<script> | |
require([ | |
'dojo/_base/array', | |
'dojo/_base/declare', | |
'dojo/date/locale', | |
'dojo/store/Memory', | |
'dojo/store/Observable', | |
'dijit/Menu', | |
'dijit/MenuItem', | |
'dgrid/OnDemandGrid', | |
'dgrid/Selection', | |
'dojo/ready' | |
], function( | |
array, | |
declare, | |
dateLocale, | |
Memory, | |
Observable, | |
Menu, | |
MenuItem, | |
OnDemandGrid, | |
Selection | |
) { | |
var SIZE = 26; | |
var now = Date.now(); | |
var memory = new Memory(); | |
var observable = new Observable(memory); | |
var store = observable; | |
function createItem(id) { | |
var item = { | |
id: id, | |
integer: Math.floor(Math.random() * 100), | |
floatNum: Math.random() * 100, | |
date: new Date(now * Math.random() * 2), | |
date2: new Date(now - Math.random() * 1000000000), | |
text: "A number in text " + Math.random(), | |
bool: Math.random() > 0.5, | |
bool2: Math.random() > 0.5, | |
price: Math.random() * 100 | |
}; | |
return item; | |
} | |
function fillStore(store) { | |
for (var i = 0; i < SIZE; i++) { | |
var item = createItem(i); | |
store.add(item); | |
} | |
} | |
function gridSelection(grid) { | |
var selection = grid.selection; | |
var gridSelection = []; | |
for (var id in selection) { | |
if (selection[id]) { | |
gridSelection.push(grid.store.get(id)); | |
} | |
} | |
return gridSelection; | |
} | |
function updatePrice(grid) { | |
var selection = gridSelection(grid); | |
array.forEach(selection, function(obj) { | |
obj.price = - obj.price; | |
grid.store.notify(obj, obj.id); | |
}); | |
} | |
function formatDate(date) { | |
return dateLocale.format(date, { selector: 'date', formatLength: 'medium' }); | |
} | |
function createGrid(gridId, textId, query) { | |
var columns = [ | |
{ name: 'Column 0', field: 'id' }, | |
{ name: 'Column 1', field: 'integer' }, | |
{ name: 'Column 2', field: 'floatNum' }, | |
{ name: 'Column 3', field: 'date', get: function(item) { return formatDate(item.date) } }, | |
{ name: 'Column 4', field: 'date2', get: function(item) { return formatDate(item.date2) } }, | |
{ name: 'Column 5', field: 'bool' }, | |
{ name: 'Column 6', field: 'bool2' }, | |
{ name: 'Column 7', field: 'price' }, | |
]; | |
var CustomGrid = declare('Grid', [OnDemandGrid, Selection]); | |
var grid = new CustomGrid({ columns: columns }, gridId); | |
grid.on("dgrid-select", function(event){ | |
// Iterate through all currently-selected items | |
for(var id in grid.selection){ | |
if(grid.selection[id]){ | |
var obj = grid.store.get(id); | |
setTimeout(function() { | |
grid.store.notify(obj, obj.id); | |
}, 0); | |
} | |
} | |
}); | |
return grid; | |
} | |
var grid = createGrid('grid'); | |
fillStore(store); | |
grid.set("store", store); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment