Commit 75fc3337 authored by GoshaZotov's avatar GoshaZotov Committed by Alexander.Trofimov

add api function asc_reapplyAutoFilter

parent 753d59b4
No related merge requests found
......@@ -557,6 +557,11 @@ var editor;
var ws = this.wb.getWorksheet();
ws.applyAutoFilterByType(autoFilterObject);
};
spreadsheet_api.prototype.asc_reapplyAutoFilter = function(displayName) {
var ws = this.wb.getWorksheet();
ws.asc_reapplyAutoFilter(displayName);
};
spreadsheet_api.prototype.asc_sortColFilter = function(type, cellId, displayName, color) {
var ws = this.wb.getWorksheet();
......@@ -3337,6 +3342,7 @@ var editor;
prot["asc_changeAutoFilter"] = prot.asc_changeAutoFilter;
prot["asc_applyAutoFilter"] = prot.asc_applyAutoFilter;
prot["asc_applyAutoFilterByType"] = prot.asc_applyAutoFilterByType;
prot["asc_reapplyAutoFilter"] = prot.asc_reapplyAutoFilter;
prot["asc_sortColFilter"] = prot.asc_sortColFilter;
prot["asc_getAddFormatTableOptions"] = prot.asc_getAddFormatTableOptions;
prot["asc_clearFilter"] = prot.asc_clearFilter;
......
......@@ -606,6 +606,81 @@
return {minChangeRow: minChangeRow, rangeOldFilter: rangeOldFilter};
},
reapplyAutoFilter: function (tableName, ar)
{
var worksheet = this.worksheet;
var bUndoChanges = worksheet.workbook.bUndoChanges;
var bRedoChanges = worksheet.workbook.bRedoChanges;
//**get filter**
var filter = this._getFilterByDisplayName(displayName);
var autoFilter = filter && filter.getType() === g_nFiltersType.tablePart ? filter.AutoFilter : filter;
var colId = this._getColIdColumnByRange(filter, ar);
var index = this._getIndexByColId(autoFilter, colId);
if(filterObj.filter === null)
return;
History.Create_NewPoint();
History.StartTransaction();
//open/close rows
if(!bUndoChanges && !bRedoChanges)
{
var hiddenObj = {start: filter.Ref.r1 + 1, h: null};
var startRow = autoFilter && autoFilter.Ref ? autoFilter.Ref.r1 + 1 : filter.Ref.r1 + 1;
var endRow = autoFilter && autoFilter.Ref ? autoFilter.Ref.r2 : filter.Ref.r2;
for(var i = startRow; i <= endRow; i++)
{
var isHidden = false;
if(autoFilter.FilterColumns && autoFilter.FilterColumns.length)
isHidden = this._hiddenAnotherFilter(autoFilter.FilterColumns, colId, i, autoFilter.Ref.c1);
if(!isHidden)
{
var cell = worksheet.getCell3(i, colId + autoFilter.Ref.c1);
var isDateTimeFormat = cell.getNumFormat().isDateTimeFormat();
var currentValue = isDateTimeFormat ? cell.getValueWithoutFormat() : cell.getValueWithFormat();
var isSetHidden = newFilterColumn.isHideValue(currentValue, isDateTimeFormat, null, cell);
if(isSetHidden !== worksheet.getRowHidden(i) && minChangeRow === null)
minChangeRow = i;
//скрываем строки
if(hiddenObj.h === null)
{
hiddenObj.h = isSetHidden;
hiddenObj.start = i;
}
else if(hiddenObj.h !== isSetHidden)
{
worksheet.setRowHidden(hiddenObj.h, hiddenObj.start, i - 1);
hiddenObj.h = isSetHidden;
hiddenObj.start = i;
}
if(i === endRow)
{
worksheet.setRowHidden(hiddenObj.h, hiddenObj.start, i);
}
}
else if(hiddenObj.h !== null)
{
worksheet.setRowHidden(hiddenObj.h, hiddenObj.start, i - 1);
hiddenObj.h = null
}
}
}
this._resetTablePartStyle();
History.EndTransaction();
},
checkRemoveTableParts: function(delRange, tableRange)
{
var result = true, firstRowRange;
......@@ -2535,6 +2610,21 @@
return res;
},
_getColIdColumnByRange: function(filter, range)
{
var res = null;
var autoFilter = filter && filter.getType() === g_nFiltersType.tablePart ? filter.AutoFilter : filter;
if(autoFilter && autoFilter.FilterColumns && autoFilter.FilterColumns.length)
{
var colId = range.colStart - autoFilter.Ref.c1;
res = this._getTrueColId(filter, colId);
}
return res;
},
_getIndexByColId: function(autoFilter, colId)
{
var res = null;
......
......@@ -12009,6 +12009,28 @@
this._isLockedAll( onChangeAutoFilterCallback );
};
WorksheetView.prototype.reapplyAutoFilter = function ( tableName ) {
var t = this;
var ar = t.activeRange.clone( true );
var onChangeAutoFilterCallback = function ( isSuccess ) {
if ( false === isSuccess ) {
return;
}
t.model.autoFilters.reapplyAutoFilter( tableName, ar );
if(null !== rangeOldFilter && !t.model.workbook.bUndoChanges && !t.model.workbook.bRedoChanges)
{
t._onUpdateFormatTable(rangeOldFilter, false, true);
}
if ( null !== rowChange ) {
t.objectRender.updateSizeDrawingObjects( {target: c_oTargetType.RowResize, row: rowChange} );
}
};
this._isLockedAll( onChangeAutoFilterCallback );
};
WorksheetView.prototype.applyAutoFilterByType = function ( autoFilterObject ) {
var t = this;
var ar = t.activeRange.clone( true );
......
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