Commit 3bdbb9bd authored by konovalovsergey's avatar konovalovsergey

the problem with recalculation formulas are dependent on the table total row

parent 363d8ef7
......@@ -3721,6 +3721,7 @@ function parserFormula( formula, parent, _ws ) {
this.ca = false;
this.isDirty = false;
this.isCalculate = false;
this.isTable = false;
this.parent = parent;
}
parserFormula.prototype.getWs = function() {
......@@ -3734,6 +3735,9 @@ function parserFormula( formula, parent, _ws ) {
};
parserFormula.prototype.setIsDirty = function(isDirty) {
this.isDirty = isDirty;
};
parserFormula.prototype.setIsTable = function(isTable){
this.isTable = isTable;
};
parserFormula.prototype.notify = function(data) {
var eventData = {notifyData: data, assemble: null, isRebuild: false, formula: this};
......@@ -5060,8 +5064,9 @@ parserFormula.prototype.assembleLocale = function(locale, digitDelim) {
};
parserFormula.prototype.buildDependencies = function() {
var ref, nTo, wsR;
var ref, wsR;
var isTable = this.isTable;
var bbox;
if (this.ca) {
this.wb.dependencyFormulas.startListeningVolatile(this);
}
......@@ -5088,14 +5093,30 @@ parserFormula.prototype.assembleLocale = function(locale, digitDelim) {
this.wb.dependencyFormulas.startListeningDefName(ref.value, this, ref.ws.getId());
} else if ((cElementType.cell === ref.type || cElementType.cell3D === ref.type ||
cElementType.cellsRange === ref.type) && ref.isValid()) {
this.wb.dependencyFormulas.startListeningRange(ref.getWsId(), ref.getRange().getBBox0(), this);
bbox = ref.getRange().getBBox0();
if(isTable){
//extend table formula with header/total. This allows us not to follow their change,
//but sometimes leads to recalculate of the table although changed cells near table (it's not a problem)
bbox = bbox.clone();
bbox.setOffsetFirst({offsetRow: -1, offsetCol: 0});
bbox.setOffsetLast({offsetRow: 1, offsetCol: 0});
}
this.wb.dependencyFormulas.startListeningRange(ref.getWsId(), bbox, this);
} else if (cElementType.cellsRange3D === ref.type && ref.isValid()) {
wsR = ref.range(ref.wsRange());
for (var j = 0; j < wsR.length; j++) {
var range = wsR[j];
if (range) {
var wsId = range.getWorksheet().getId();
this.wb.dependencyFormulas.startListeningRange(wsId, range.getBBox0(), this);
bbox = range.getBBox0();
if(isTable){
//extend table formula with header/total. This allows us not to follow their change,
//but sometimes leads to recalculate of the table although changed cells near table (it's not a problem)
bbox = bbox.clone();
bbox.setOffsetFirst({offsetRow: -1, offsetCol: 0});
bbox.setOffsetLast({offsetRow: 1, offsetCol: 0});
}
this.wb.dependencyFormulas.startListeningRange(wsId, bbox, this);
}
}
}
......@@ -5104,6 +5125,8 @@ parserFormula.prototype.assembleLocale = function(locale, digitDelim) {
parserFormula.prototype.removeDependencies = function() {
var ref;
var wsR;
var isTable = this.isTable;
var bbox;
if (this.ca) {
this.wb.dependencyFormulas.endListeningVolatile(this);
}
......@@ -5130,14 +5153,26 @@ parserFormula.prototype.assembleLocale = function(locale, digitDelim) {
this.wb.dependencyFormulas.endListeningDefName(ref.value, this, ref.ws.getId());
} else if ((cElementType.cell === ref.type || cElementType.cell3D === ref.type ||
cElementType.cellsRange === ref.type) && ref.isValid()) {
this.wb.dependencyFormulas.endListeningRange(ref.getWsId(), ref.getRange().getBBox0(), this);
bbox = ref.getRange().getBBox0();
if(isTable){
bbox = bbox.clone();
bbox.setOffsetFirst({offsetRow: -1, offsetCol: 0});
bbox.setOffsetLast({offsetRow: 1, offsetCol: 0});
}
this.wb.dependencyFormulas.endListeningRange(ref.getWsId(), bbox, this);
} else if (cElementType.cellsRange3D === ref.type && ref.isValid()) {
wsR = ref.range(ref.wsRange());
for (var j = 0; j < wsR.length; j++) {
var range = wsR[j];
if (range) {
var wsId = range.getWorksheet().getId();
this.wb.dependencyFormulas.endListeningRange(wsId, range.getBBox0(), this);
bbox = range.getBBox0();
if(isTable){
bbox = bbox.clone();
bbox.setOffsetFirst({offsetRow: -1, offsetCol: 0});
bbox.setOffsetLast({offsetRow: 1, offsetCol: 0});
}
this.wb.dependencyFormulas.endListeningRange(wsId, bbox, this);
}
}
}
......
......@@ -201,6 +201,7 @@ function getRangeType(oBBox){
this.ref = ref;
//all ref should be 3d, so worksheet can be anyone
this.parsedRef = new parserFormula(ref, this, AscCommonExcel.g_DefNameWorksheet);
this.parsedRef.setIsTable(true);
if (opt_forceBuild) {
this.parsedRef.parse();
this.parsedRef.buildDependencies();
......@@ -721,13 +722,14 @@ function getRangeType(oBBox){
defName.setRef(defNameRef);
}
},
changeTableRef: function(tableName, newRef) {
var defName = this.getDefNameByName(tableName, null);
changeTableRef: function(table) {
var defName = this.getDefNameByName(table.DisplayName, null);
if (defName) {
this.buildDependency();
var oldUndoName = defName.getUndoDefName();
var newUndoName = defName.getUndoDefName();
newUndoName.ref = defName.ref.split('!')[0] + '!' + newRef.getAbsName();
var ref = table.getRangeWithoutHeaderFooter();
newUndoName.ref = defName.ref.split('!')[0] + '!' + ref.getAbsName();
History.TurnOff();
this.editDefinesNames(oldUndoName, newUndoName);
var notifyData = {type: AscCommon.c_oNotifyType.ChangeDefName, from: oldUndoName, to: newUndoName};
......@@ -1379,8 +1381,8 @@ Workbook.prototype.init=function(tableCustomFunc, bNoBuildDep, bSnapshot){
var self = this;
this.wsHandlers = new AscCommonExcel.asc_CHandlersList( /*handlers*/{
"changeRefTablePart" : function ( displayName, ref ) {
self.dependencyFormulas.changeTableRef( displayName, ref );
"changeRefTablePart" : function (table) {
self.dependencyFormulas.changeTableRef(table);
},
"changeColumnTablePart": function ( tableName ) {
self.dependencyFormulas.rebuildTable( tableName );
......
......@@ -5254,7 +5254,7 @@ TablePart.prototype.moveRef = function(col, row) {
this.Ref = ref;
//event
this.handlers.trigger("changeRefTablePart", this.DisplayName, this.getRangeWithoutHeaderFooter());
this.handlers.trigger("changeRefTablePart", this);
if(this.AutoFilter)
this.AutoFilter.moveRef(col, row);
......@@ -5269,7 +5269,7 @@ TablePart.prototype.changeRef = function(col, row, bIsFirst) {
this.Ref = ref;
//event
this.handlers.trigger("changeRefTablePart", this.DisplayName, this.getRangeWithoutHeaderFooter());
this.handlers.trigger("changeRefTablePart", this);
if(this.AutoFilter)
this.AutoFilter.changeRef(col, row, bIsFirst);
......@@ -5316,7 +5316,7 @@ TablePart.prototype.changeRefOnRange = function(range, autoFilters, generateNewT
}
this.Ref = Asc.Range(range.c1, range.r1, range.c2, range.r2);
//event
this.handlers.trigger("changeRefTablePart", this.DisplayName, this.getRangeWithoutHeaderFooter());
this.handlers.trigger("changeRefTablePart", this);
if(this.AutoFilter)
this.AutoFilter.changeRefOnRange(range);
......
......@@ -997,8 +997,7 @@
this._setStyleTables(cloneData.newFilterRef);
//event
//todo
worksheet.handlers.trigger("changeRefTablePart", cloneData.oldFilter.DisplayName, cloneData.oldFilter.Ref);
worksheet.handlers.trigger("changeRefTablePart", cloneData.oldFilter);
break;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment