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 ) { ...@@ -3721,6 +3721,7 @@ function parserFormula( formula, parent, _ws ) {
this.ca = false; this.ca = false;
this.isDirty = false; this.isDirty = false;
this.isCalculate = false; this.isCalculate = false;
this.isTable = false;
this.parent = parent; this.parent = parent;
} }
parserFormula.prototype.getWs = function() { parserFormula.prototype.getWs = function() {
...@@ -3735,6 +3736,9 @@ function parserFormula( formula, parent, _ws ) { ...@@ -3735,6 +3736,9 @@ function parserFormula( formula, parent, _ws ) {
parserFormula.prototype.setIsDirty = function(isDirty) { parserFormula.prototype.setIsDirty = function(isDirty) {
this.isDirty = isDirty; this.isDirty = isDirty;
}; };
parserFormula.prototype.setIsTable = function(isTable){
this.isTable = isTable;
};
parserFormula.prototype.notify = function(data) { parserFormula.prototype.notify = function(data) {
var eventData = {notifyData: data, assemble: null, isRebuild: false, formula: this}; var eventData = {notifyData: data, assemble: null, isRebuild: false, formula: this};
if (this.parent && this.parent.onFormulaEvent) { if (this.parent && this.parent.onFormulaEvent) {
...@@ -5060,8 +5064,9 @@ parserFormula.prototype.assembleLocale = function(locale, digitDelim) { ...@@ -5060,8 +5064,9 @@ parserFormula.prototype.assembleLocale = function(locale, digitDelim) {
}; };
parserFormula.prototype.buildDependencies = function() { parserFormula.prototype.buildDependencies = function() {
var ref, nTo, wsR; var ref, wsR;
var isTable = this.isTable;
var bbox;
if (this.ca) { if (this.ca) {
this.wb.dependencyFormulas.startListeningVolatile(this); this.wb.dependencyFormulas.startListeningVolatile(this);
} }
...@@ -5088,14 +5093,30 @@ parserFormula.prototype.assembleLocale = function(locale, digitDelim) { ...@@ -5088,14 +5093,30 @@ parserFormula.prototype.assembleLocale = function(locale, digitDelim) {
this.wb.dependencyFormulas.startListeningDefName(ref.value, this, ref.ws.getId()); this.wb.dependencyFormulas.startListeningDefName(ref.value, this, ref.ws.getId());
} else if ((cElementType.cell === ref.type || cElementType.cell3D === ref.type || } else if ((cElementType.cell === ref.type || cElementType.cell3D === ref.type ||
cElementType.cellsRange === ref.type) && ref.isValid()) { 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()) { } else if (cElementType.cellsRange3D === ref.type && ref.isValid()) {
wsR = ref.range(ref.wsRange()); wsR = ref.range(ref.wsRange());
for (var j = 0; j < wsR.length; j++) { for (var j = 0; j < wsR.length; j++) {
var range = wsR[j]; var range = wsR[j];
if (range) { if (range) {
var wsId = range.getWorksheet().getId(); 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) { ...@@ -5104,6 +5125,8 @@ parserFormula.prototype.assembleLocale = function(locale, digitDelim) {
parserFormula.prototype.removeDependencies = function() { parserFormula.prototype.removeDependencies = function() {
var ref; var ref;
var wsR; var wsR;
var isTable = this.isTable;
var bbox;
if (this.ca) { if (this.ca) {
this.wb.dependencyFormulas.endListeningVolatile(this); this.wb.dependencyFormulas.endListeningVolatile(this);
} }
...@@ -5130,14 +5153,26 @@ parserFormula.prototype.assembleLocale = function(locale, digitDelim) { ...@@ -5130,14 +5153,26 @@ parserFormula.prototype.assembleLocale = function(locale, digitDelim) {
this.wb.dependencyFormulas.endListeningDefName(ref.value, this, ref.ws.getId()); this.wb.dependencyFormulas.endListeningDefName(ref.value, this, ref.ws.getId());
} else if ((cElementType.cell === ref.type || cElementType.cell3D === ref.type || } else if ((cElementType.cell === ref.type || cElementType.cell3D === ref.type ||
cElementType.cellsRange === ref.type) && ref.isValid()) { 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()) { } else if (cElementType.cellsRange3D === ref.type && ref.isValid()) {
wsR = ref.range(ref.wsRange()); wsR = ref.range(ref.wsRange());
for (var j = 0; j < wsR.length; j++) { for (var j = 0; j < wsR.length; j++) {
var range = wsR[j]; var range = wsR[j];
if (range) { if (range) {
var wsId = range.getWorksheet().getId(); 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){ ...@@ -201,6 +201,7 @@ function getRangeType(oBBox){
this.ref = ref; this.ref = ref;
//all ref should be 3d, so worksheet can be anyone //all ref should be 3d, so worksheet can be anyone
this.parsedRef = new parserFormula(ref, this, AscCommonExcel.g_DefNameWorksheet); this.parsedRef = new parserFormula(ref, this, AscCommonExcel.g_DefNameWorksheet);
this.parsedRef.setIsTable(true);
if (opt_forceBuild) { if (opt_forceBuild) {
this.parsedRef.parse(); this.parsedRef.parse();
this.parsedRef.buildDependencies(); this.parsedRef.buildDependencies();
...@@ -721,13 +722,14 @@ function getRangeType(oBBox){ ...@@ -721,13 +722,14 @@ function getRangeType(oBBox){
defName.setRef(defNameRef); defName.setRef(defNameRef);
} }
}, },
changeTableRef: function(tableName, newRef) { changeTableRef: function(table) {
var defName = this.getDefNameByName(tableName, null); var defName = this.getDefNameByName(table.DisplayName, null);
if (defName) { if (defName) {
this.buildDependency(); this.buildDependency();
var oldUndoName = defName.getUndoDefName(); var oldUndoName = defName.getUndoDefName();
var newUndoName = 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(); History.TurnOff();
this.editDefinesNames(oldUndoName, newUndoName); this.editDefinesNames(oldUndoName, newUndoName);
var notifyData = {type: AscCommon.c_oNotifyType.ChangeDefName, from: oldUndoName, to: newUndoName}; var notifyData = {type: AscCommon.c_oNotifyType.ChangeDefName, from: oldUndoName, to: newUndoName};
...@@ -1379,8 +1381,8 @@ Workbook.prototype.init=function(tableCustomFunc, bNoBuildDep, bSnapshot){ ...@@ -1379,8 +1381,8 @@ Workbook.prototype.init=function(tableCustomFunc, bNoBuildDep, bSnapshot){
var self = this; var self = this;
this.wsHandlers = new AscCommonExcel.asc_CHandlersList( /*handlers*/{ this.wsHandlers = new AscCommonExcel.asc_CHandlersList( /*handlers*/{
"changeRefTablePart" : function ( displayName, ref ) { "changeRefTablePart" : function (table) {
self.dependencyFormulas.changeTableRef( displayName, ref ); self.dependencyFormulas.changeTableRef(table);
}, },
"changeColumnTablePart": function ( tableName ) { "changeColumnTablePart": function ( tableName ) {
self.dependencyFormulas.rebuildTable( tableName ); self.dependencyFormulas.rebuildTable( tableName );
......
...@@ -5254,7 +5254,7 @@ TablePart.prototype.moveRef = function(col, row) { ...@@ -5254,7 +5254,7 @@ TablePart.prototype.moveRef = function(col, row) {
this.Ref = ref; this.Ref = ref;
//event //event
this.handlers.trigger("changeRefTablePart", this.DisplayName, this.getRangeWithoutHeaderFooter()); this.handlers.trigger("changeRefTablePart", this);
if(this.AutoFilter) if(this.AutoFilter)
this.AutoFilter.moveRef(col, row); this.AutoFilter.moveRef(col, row);
...@@ -5269,7 +5269,7 @@ TablePart.prototype.changeRef = function(col, row, bIsFirst) { ...@@ -5269,7 +5269,7 @@ TablePart.prototype.changeRef = function(col, row, bIsFirst) {
this.Ref = ref; this.Ref = ref;
//event //event
this.handlers.trigger("changeRefTablePart", this.DisplayName, this.getRangeWithoutHeaderFooter()); this.handlers.trigger("changeRefTablePart", this);
if(this.AutoFilter) if(this.AutoFilter)
this.AutoFilter.changeRef(col, row, bIsFirst); this.AutoFilter.changeRef(col, row, bIsFirst);
...@@ -5316,7 +5316,7 @@ TablePart.prototype.changeRefOnRange = function(range, autoFilters, generateNewT ...@@ -5316,7 +5316,7 @@ TablePart.prototype.changeRefOnRange = function(range, autoFilters, generateNewT
} }
this.Ref = Asc.Range(range.c1, range.r1, range.c2, range.r2); this.Ref = Asc.Range(range.c1, range.r1, range.c2, range.r2);
//event //event
this.handlers.trigger("changeRefTablePart", this.DisplayName, this.getRangeWithoutHeaderFooter()); this.handlers.trigger("changeRefTablePart", this);
if(this.AutoFilter) if(this.AutoFilter)
this.AutoFilter.changeRefOnRange(range); this.AutoFilter.changeRefOnRange(range);
......
...@@ -997,8 +997,7 @@ ...@@ -997,8 +997,7 @@
this._setStyleTables(cloneData.newFilterRef); this._setStyleTables(cloneData.newFilterRef);
//event //event
//todo worksheet.handlers.trigger("changeRefTablePart", cloneData.oldFilter);
worksheet.handlers.trigger("changeRefTablePart", cloneData.oldFilter.DisplayName, cloneData.oldFilter.Ref);
break; 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