Skip to content

Instantly share code, notes, and snippets.

@ItsAsbreuk
Forked from stlsmiths/dtDestroy0.html
Created November 3, 2012 09:59
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 ItsAsbreuk/4006858 to your computer and use it in GitHub Desktop.
Save ItsAsbreuk/4006858 to your computer and use it in GitHub Desktop.
<!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