Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve performance #39

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions examples/example-huge.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,39 @@
//create huge treetable
var count_root_elements=100;
var count_deep=10;
console.log('init');
console.log('generate...');
for(var i=0; i<count_root_elements; i++){
console.log('add');
var tr=$("<tr></tr>").addClass("treegrid-"+i+"-0").appendTo($('.tree')).html("<td>Root node "+i+"</td><td>Additional info</td>");

for(var j=1; j<count_deep; j++){
$("<tr></tr>").addClass("treegrid-"+i+"-"+j).addClass("treegrid-parent-"+i+"-"+(j-1)).appendTo($('.tree')).html("<td>Child node "+i+"-"+j+"</td><td>Additional info</td>");
}
}

console.log('init...');
console.profile('treegrid init');
$('.tree').treegrid();
console.profileEnd();
});
</script>



<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>
<div class="wrapper">


<h1><a href="http://maxazan.github.io/jquery-treegrid/">TreeGrid</a> Big data example</h1>

<table class="tree"></table>
<table class="tree"></table>

<h2>Code</h2>

<pre>
<code class='html'>
&lt;!doctype html&gt;
Expand Down Expand Up @@ -81,7 +83,7 @@ <h2>Code</h2>
&lt;tr class=&quot;treegrid-4 treegrid-parent-3&quot;&gt;
&lt;td&gt;Node 1-2-1&lt;/td&gt;&lt;td&gt;Additional info&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/table&gt;

&lt;/body&gt;
&lt;/html&gt;
Expand Down Expand Up @@ -110,4 +112,4 @@ <h2>Code</h2>
</script>

</body>
</html>
</html>
28 changes: 12 additions & 16 deletions js/jquery.treegrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
return this.each(function() {
var $this = $(this);
$this.treegrid('setTreeContainer', settings.getTreeGridContainer.apply(this));
$this.attr('id', 'treegrid-' + $(this).treegrid('getNodeId'));
$this.treegrid('getChildNodes').treegrid('initNode', settings);
$this.treegrid('initExpander').treegrid('initIndent').treegrid('initEvents').treegrid('initState').treegrid('initChangeEvent').treegrid("initSettingsEvents");
});
Expand Down Expand Up @@ -559,6 +560,11 @@
$.error('Method with name ' + method + ' does not exists for jQuery.treegrid');
}
};
/**
* Pre-init RegExp objects
*/
var templateClass = /treegrid-([\w-]+)/,
templateParentClass = /treegrid-parent-([\w-]+)/;
/**
* Plugin's default options
*/
Expand All @@ -576,22 +582,16 @@
return $(this).find('.treegrid-expander');
},
getNodeId: function() {
var template = /treegrid-([A-Za-z0-9_-]+)/;
if (template.test($(this).attr('class'))) {
return template.exec($(this).attr('class'))[1];
}
return null;
var result = templateClass.exec($(this).attr('class'));
return result ? result[1] : null;
},
getParentNodeId: function() {
var template = /treegrid-parent-([A-Za-z0-9_-]+)/;
if (template.test($(this).attr('class'))) {
return template.exec($(this).attr('class'))[1];
}
return null;
var result = templateParentClass.exec($(this).attr('class'));
return result ? result[1] : null;
},
getNodeById: function(id, treegridContainer) {
var templateClass = "treegrid-" + id;
return treegridContainer.find('tr.' + templateClass);
return treegridContainer.find('#' + templateClass);
},
getChildNodes: function(id, treegridContainer) {
var templateClass = "treegrid-parent-" + id;
Expand All @@ -603,17 +603,13 @@
getRootNodes: function(treegridContainer) {
var result = $.grep(treegridContainer.find('tr'), function(element) {
var classNames = $(element).attr('class');
var templateClass = /treegrid-([A-Za-z0-9_-]+)/;
var templateParentClass = /treegrid-parent-([A-Za-z0-9_-]+)/;
return templateClass.test(classNames) && !templateParentClass.test(classNames);
});
return $(result);
},
getAllNodes: function(treegridContainer) {
var result = $.grep(treegridContainer.find('tr'), function(element) {
var classNames = $(element).attr('class');
var templateClass = /treegrid-([A-Za-z0-9_-]+)/;
return templateClass.test(classNames);
return templateClass.test($(element).attr('class'));
});
return $(result);
},
Expand Down
Loading