Author: abelevich
Date: 2007-05-14 14:05:06 -0400 (Mon, 14 May 2007)
New Revision: 751
Modified:
trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/Grid2.js
trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/GridBody2.js
Log:
Modified:
trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/Grid2.js
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/Grid2.js 2007-05-14
18:04:27 UTC (rev 750)
+++
trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/Grid2.js 2007-05-14
18:05:06 UTC (rev 751)
@@ -170,6 +170,7 @@
}
}
+ this.getBody().adjustColumnWidth(index, width);
this.updateLayout();
if(ClientUILib.isIE) {
Modified:
trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/GridBody2.js
===================================================================
---
trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/GridBody2.js 2007-05-14
18:04:27 UTC (rev 750)
+++
trunk/sandbox/scrollable-grid/src/main/javascript/ClientUI/controls/grid/GridBody2.js 2007-05-14
18:05:06 UTC (rev 751)
@@ -94,7 +94,7 @@
}
*/
- ClientUILib.log(ClientUILogger.WARNING, "data for "+options.count+" rows
loaded over: " + ((new Date()).getTime() - currTime) + " miliseconds.");
+ ClientUILib.log(ClientUILogger.ERROR, "data for "+options.count+" rows
loaded over: " + ((new Date()).getTime() - currTime) + " miliseconds.");
ClientUILib.log(ClientUILogger.WARNING, "start index: " + options.index +
", and startRow: " + options.startRow);
ClientUILib.log(ClientUILogger.WARNING, "load data delta time: " +
(this.taskStartTime - this.taskDefineTime));
ClientUILib.log(ClientUILogger.WARNING, "data prepare time: " +
(this.taskStartLoadingTime - this.taskStartTime));
@@ -187,26 +187,21 @@
templFrozen.rows[i].index = i;
templNormal.rows[i].index = i;
}
+ this.helpObj = new ClientUI.common.box.Box(templFrozen, null, true);
this.countToLoad = 0;
this.startRow = 0;
- this.startIndex = 0;
+ this.startIndex = 0;
+ this.currRange = $R(0,this.rowsCount);
return true;
},
updateColumns: function() {
var width = 0;
var columns = this.grid.getHeader().getColumns();
- for(var i=0; i<columns.lenght; i++) {
- width = columns[i].width;
- if(ClientUILib.isGecko) {
- width -= this.getBorderWidth("lr") + this.getPadding("lr");
- }
- this.adjustColumnWidth(i, width);
+ for(var i=0; i<columns.length; i++) {
+ this.adjustColumnWidth(i, columns[i].width);
}
},
- adjustColumnWidth: function(column, width) {
- // TODO: implement adjustColumnWidth!!!
- },
getColumns: function() {
return this._columns;
},
@@ -544,11 +539,6 @@
task.timer = setTimeout(function() {
this.taskStartTime = (new Date()).getTime();
- // 1. get previous range
- if(!this.currRange) {
- this.currRange = $R(-this.rowsCount,-1);
- }
-
var range = $R(task.from, task.to);
// if we have intersepted ranges than rearrange rows
@@ -571,15 +561,13 @@
this.templNormal.moveToY(pos);
}
else {
- var i, row, rownew;
+ var i, row, rownew, cloned;
this.countToLoad = 0;
- var frozenTbl = this.templFrozen.getElement().tBodies[0];
- var normalTbl = this.templNormal.getElement().tBodies[0];
+ var frozenTbl = this.templFrozen.getElement();
+ var normalTbl = this.templNormal.getElement();
if(range.start > this.currRange.start
&& range.start < this.currRange.end) {
- // TODO: get rows from this.currRange.start to range.start
- // and move them to end of table
- // then move table to correct position
+
this.countToLoad = range.start - this.currRange.start;
this.startRow = frozenTbl.rows[0].index;
@@ -588,14 +576,16 @@
for(i=0; i<this.countToLoad; i++) {
row = frozenTbl.rows[0];
- frozenTbl.deleteRow(row);
+ cloned = row.cloneNode(true);
+ frozenTbl.deleteRow(row.rowIndex);
rownew = frozenTbl.insertRow(this.rowsCount-1);
- rownew.parentNode.replaceChild(row,rownew);
+ rownew.parentNode.replaceChild(cloned,rownew);
row = normalTbl.rows[0];
- normalTbl.deleteRow(row);
+ cloned = row.cloneNode(true);
+ normalTbl.deleteRow(row.rowIndex);
rownew = normalTbl.insertRow(this.rowsCount-1);
- rownew.parentNode.replaceChild(row,rownew);
+ rownew.parentNode.replaceChild(cloned,rownew);
}
this.templFrozen.moveToY(visibleRowPos);
@@ -629,59 +619,49 @@
*/
}
else {
- // TODO: get rows from range.end to this.currRange.end
- // and move them to begin of table
- // then move table to correct position
+ this.countToLoad = this.currRange.start - range.start;
+
+ // store visible row pos to restore after rows reerrange
+ var visibleRowPos = this.templFrozen.getY() - this.countToLoad *
this.defaultRowHeight;
+ var frows = [], nrows = [];
+ for(i=this.rowsCount-1; i>=this.rowsCount - this.countToLoad; i--) {
+ row = frozenTbl.rows[i];
+ cloned = row.cloneNode(true);
+ frows.push(cloned);
+ frozenTbl.deleteRow(row.rowIndex);
+
+ row = normalTbl.rows[i];
+ cloned = row.cloneNode(true);
+ nrows.push(cloned);
+ normalTbl.deleteRow(row.rowIndex);
+ }
+
+ for(i=0; i<frows.length; i++) {
+ row = frows[i];
+ rownew = frozenTbl.insertRow(0);
+ rownew.parentNode.replaceChild(row, rownew);
+
+ row = nrows[i];
+ rownew = normalTbl.insertRow(0);
+ rownew.parentNode.replaceChild(row, rownew);
+ }
+
+ this.templFrozen.moveToY(visibleRowPos);
+ this.templNormal.moveToY(visibleRowPos);
+ this.startRow = frozenTbl.rows[0].index;
}
}
-
- /*
- // 1. hide invisible rows
- this.dataViewHash = [];
- var newDataView = [];
- var count = this.dataView.length;
- for(var i=0; i<count; i++) {
- var row = this.dataView[i];
- if(!range.include(row.rowindex)) {
- this.deleteRow(row);
- }
- else {
- this.dataViewHash[row.rowindex] = this.dataView[i];
- newDataView.push(row);
- }
- }
- this.dataView = newDataView;
-
- // 2. show empty rows
- var rowsToLoad = [];
- var rowsToLoadIdx = [];
- var row, i;
- for(i=task.from; i<=task.to; i++) {
- if(!this.dataViewHash[i]) {
- row = this.getRow();
- row.setRowIndex(i);
- row.showEmpty();
- this.dataView.push(row);
- this.dataViewHash[i] = row;
- rowsToLoadIdx.push(i);
- rowsToLoad.push(row.getCellsToUpdate());
- }
- }
this.taskStartLoadingTime = (new Date()).getTime();
+
// 4. start data loading
- this.grid.dataModel.loadRows({
- indexes: rowsToLoadIdx,
- ids: rowsToLoad});
- */
+ if(this.countToLoad > 0) {
+ this.grid.dataModel.loadRows({
+ index: this.startIndex,
+ count: this.countToLoad,
+ startRow: this.startRow});
+ }
- this.taskStartLoadingTime = (new Date()).getTime();
- // 4. start data loading
- this.grid.dataModel.loadRows({
- index: this.startIndex,
- count: this.countToLoad,
- startRow: this.startRow});
-
clearTimeout(task.timer);
task.timer = null;
task.from = 0;
@@ -706,5 +686,36 @@
// this.rowsCount
//this.templFrozen.moveToY(pos);
//this.templNormal.moveToY(pos);
- }
+ },
+ adjustColumnWidth: function(column, width) {
+ var w = width, ch;
+ var frozenColumns = this.templFrozen.getElement().rows[0].cells.length;
+ var realColumn = column;
+ var table = null;
+ if(column < frozenColumns) {
+ table = this.templFrozen.getElement();
+ }
+ else {
+ table = this.templNormal.getElement();
+ realColumn -= frozenColumns;
+ }
+
+ for(var i=0; i<this.rowsCount; i++) {
+ var childs = table.rows[i].cells[realColumn].childNodes;
+ for (var j=0; j<childs.length; j++) {
+ ch = childs[j];
+ if(ch.tagName && ch.tagName.toLowerCase() == "span") {
+
+ w = width;
+ if(ClientUILib.isGecko) {
+ this.helpObj.element = ch.parentNode;
+ w -= this.helpObj.getBorderWidth("lr") +
this.helpObj.getPadding("lr");
+ }
+ this.helpObj.element = $(ch);
+ this.helpObj.setWidth(w);
+ break;
+ }
+ }
+ }
+ }
});