Permalink
Browse files

Performance optimizations and code cleanup.

git-svn-id: http://slickgrid.googlecode.com/svn/trunk@32 daa67922-0c33-11de-a42d-873b86d837ff
  • Loading branch information...
1 parent 5c733e0 commit 857195f3121cec8853d4598f1046fcae06444ab5 michael.leibman@gmail.com committed Mar 31, 2009
Showing with 71 additions and 37 deletions.
  1. +1 −4 example4-model.html
  2. +70 −33 slick.grid.js
View
@@ -205,10 +205,7 @@
});
dataView.onRowsChanged.subscribe(function(rows) {
- for (var i=0, rl=rows.length; i<rl; i++) {
- grid.removeRow(rows[i]);
- }
-
+ grid.removeRows(rows);
grid.render();
});
View
@@ -379,6 +379,39 @@ function SlickGrid($container,data,columns,options)
return html.join("");
}
+
+ function cleanupRows(visibleFrom,visibleTo) {
+ console.time("cleanupRows");
+
+ var rowsBefore = renderedRows;
+ var parentNode = $divMain[0];
+
+ for (var i in rowsCache)
+ {
+ if (i != currentRow && (i < visibleFrom || i > visibleTo))
+ {
+ parentNode.removeChild(rowsCache[i]);
+
+ delete rowsCache[i];
+ renderedRows--;
+
+ counter_rows_removed++;
+ }
+ }
+
+ console.log("removed " + (rowsBefore - renderedRows) + " rows");
+ console.timeEnd("cleanupRows");
+ }
+
+ function removeAllRows() {
+ console.time("removeAllRows");
+
+ $divMain[0].innerHTML = "";
+ rowsCache= {};
+ counter_rows_removed += renderedRows;
+ renderedRows = 0;
+ console.timeEnd("removeAllRows");
+ }
function removeRow(row) {
var node = rowsCache[row];
@@ -399,6 +432,42 @@ function SlickGrid($container,data,columns,options)
counter_rows_removed++;
}
+ function removeRows(rows) {
+ console.time("removeRows");
+
+ if (!rows || !rows.length) return;
+
+ scrollDir = 0;
+ var nodes = [];
+
+ for (var i=0, rl=rows.length; i<rl; i++) {
+ if (currentEditor && currentRow == i)
+ throw "Grid : removeRow : Cannot remove a row that is currently in edit mode";
+
+ var node = rowsCache[i];
+ if (!node) continue;
+
+ nodes.push(i);
+ }
+
+ if (nodes.length == renderedRows) {
+ $divMain[0].innerHTML = "";
+ rowsCache= {};
+ counter_rows_removed += renderedRows;
+ renderedRows = 0;
+ } else {
+ for (var i=0, nl=nodes.length; i<n; i++) {
+ var node = rowsCache[nodes[i]];
+ node.parentNode.removeChild(node);
+ delete rowsCache[nodes[i]];
+ renderedRows--;
+ counter_rows_removed++;
+ }
+ }
+
+ console.timeEnd("removeRows");
+ }
+
function updateCell(row,cell) {
if (!rowsCache[row]) return;
var $cell = $(rowsCache[row]).find(".c[cell=" + cell + "]");
@@ -475,39 +544,6 @@ function SlickGrid($container,data,columns,options)
bottom: Math.floor((currentScrollTop + viewportH) / ROW_HEIGHT)
};
}
-
- function removeAllRows() {
- console.time("removeAllRows");
-
- $divMain[0].innerHTML = "";
- rowsCache= {};
- renderedRows = 0;
-
- console.timeEnd("removeAllRows");
- }
-
- function cleanupRows(visibleFrom,visibleTo) {
- console.time("cleanupRows");
-
- var rowsBefore = renderedRows;
- var parentNode = $divMain[0];
-
- for (var i in rowsCache)
- {
- if (i != currentRow && (i < visibleFrom || i > visibleTo))
- {
- parentNode.removeChild(rowsCache[i]);
-
- delete rowsCache[i];
- renderedRows--;
-
- counter_rows_removed++;
- }
- }
-
- console.log("removed " + (rowsBefore - renderedRows) + " rows");
- console.timeEnd("cleanupRows");
- }
function renderRows(from,to) {
console.time("renderRows");
@@ -1055,6 +1091,7 @@ function SlickGrid($container,data,columns,options)
"updateCell": updateCell,
"updateRow": updateRow,
"removeRow": removeRow,
+ "removeRows": removeRows,
"removeAllRows": removeAllRows,
"render": render,
"getViewport": getViewport,

0 comments on commit 857195f

Please sign in to comment.