-
-
Save ItsAsbreuk/4006858 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 PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> | |
<html> | |
<head> | |
<title>DT Destroy</title> | |
<meta http-equiv="content-type" content="text/html; charset=utf-8"> | |
</head> | |
<body class="yui3-skin-sam"> | |
<button id="btnRebuild">Rebuild it!</button> | |
<div>build times: <span id="count"></span></div> | |
<br/> | |
<div id="dtable"></div> | |
<script src="http://yui.yahooapis.com/3.7.3/build/yui/yui-min.js"></script> | |
<script> | |
YUI().use("node","datatable",function(Y){ | |
var dt, i, looptimes = 50000; | |
function destroyDT(){ | |
if(dt) { | |
Y.log('dt will be destroyed'); | |
// dt.get('contentBox').remove(true); | |
dt.destroy(); | |
dt = null; | |
} | |
else {Y.log('cannot destroy: dt does not exist');} | |
} | |
function buildDT(){ | |
if(dt) { | |
Y.log('dt cannot be created because it exists'); | |
return; | |
} | |
var somedata = [ | |
{rid:10, rtext:'text A', col3:12345 }, | |
{rid:13, rtext:'text B', col3:12345 }, | |
{rid:15, rtext:'text C', col3:12345 }, | |
{rid:17, rtext:'text D', col3:12345 }, | |
{rid:19, rtext:'text E', col3:12345 } | |
]; | |
dt = new Y.DataTable({ | |
columns: [ 'rid', 'rtext', 'col3' ], | |
data: somedata | |
}); | |
dt.after( | |
'render', | |
function() { | |
i++; | |
Y.log('dt is rendered for the ' + i + 'th time'); | |
destroyDT(); | |
} | |
); | |
dt.after( | |
'destroy', | |
function() { | |
Y.log('dt is destroyed'); | |
Y.fire('rebuild'); | |
} | |
); | |
dt.render('#dtable'); | |
} | |
function startBuildDT(){ | |
i=0; | |
buildDT(); | |
} | |
Y.on( | |
'rebuild', | |
function(){ | |
if (i<looptimes) { | |
Y.log('rebuilding dt'); | |
Y.one('#count').setHTML(i); | |
Y.later(10, null, buildDT); | |
} | |
} | |
); | |
Y.one("#btnRebuild").on("click", startBuildDT); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment