snapshot of https://github.com/dream-num/univer.git (dev, 2026-09-16; blobs > 131072B omitted)
Some checks failed
📦 Build / build (push) Has been cancelled
🧪 CI Test / test shard (1/4) (push) Has been cancelled
🧪 CI Test / test shard (2/4) (push) Has been cancelled
🧪 CI Test / test shard (3/4) (push) Has been cancelled
🧪 CI Test / test shard (4/4) (push) Has been cancelled
🧪 CI Test / test (push) Has been cancelled
🧪 CI Test / eslint (push) Has been cancelled
🧪 CI Test / typecheck (push) Has been cancelled
🔫 Sync to Pro / dispatch-sync (push) Has been cancelled
🔮 Sync Mirror / sync (push) Has been cancelled
Some checks failed
📦 Build / build (push) Has been cancelled
🧪 CI Test / test shard (1/4) (push) Has been cancelled
🧪 CI Test / test shard (2/4) (push) Has been cancelled
🧪 CI Test / test shard (3/4) (push) Has been cancelled
🧪 CI Test / test shard (4/4) (push) Has been cancelled
🧪 CI Test / test (push) Has been cancelled
🧪 CI Test / eslint (push) Has been cancelled
🧪 CI Test / typecheck (push) Has been cancelled
🔫 Sync to Pro / dispatch-sync (push) Has been cancelled
🔮 Sync Mirror / sync (push) Has been cancelled
This commit is contained in:
77
packages/sheets-sort/src/facade/f-worksheet.ts
Normal file
77
packages/sheets-sort/src/facade/f-worksheet.ts
Normal file
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* Copyright 2023-present DreamNum Co., Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import type { IRange } from '@univerjs/core';
|
||||
import type { IOrderRule } from '@univerjs/sheets-sort';
|
||||
import { RANGE_TYPE } from '@univerjs/core';
|
||||
import { SortRangeCommand, SortType } from '@univerjs/sheets-sort';
|
||||
import { FWorksheet } from '@univerjs/sheets/facade';
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
export interface IFWorksheetSortMixin {
|
||||
/**
|
||||
* Sort the worksheet by the specified column.
|
||||
* @param {number} colIndex The column index to sort by.
|
||||
* @param {boolean} [asc=true] The sort order. `true` for ascending, `false` for descending. The column A index is 0.
|
||||
* @returns {FWorksheet} The worksheet itself for chaining.
|
||||
* @example
|
||||
* ```typescript
|
||||
* const fWorkbook = univerAPI.getActiveWorkbook();
|
||||
* const fWorksheet = fWorkbook.getSheetByName('Sheet1');
|
||||
* if (!fWorksheet) return;
|
||||
*
|
||||
* // Sorts the worksheet by the column A in ascending order.
|
||||
* fWorksheet.sort(0);
|
||||
*
|
||||
* // Sorts the worksheet by the column A in descending order.
|
||||
* fWorksheet.sort(0, false);
|
||||
* ```
|
||||
*/
|
||||
sort(colIndex: number, asc?: boolean): FWorksheet;
|
||||
}
|
||||
|
||||
export class FWorksheetSortMixin extends FWorksheet implements IFWorksheetSortMixin {
|
||||
override sort(colIndex: number, asc = true): FWorksheet {
|
||||
const orderRules: IOrderRule[] = [{
|
||||
colIndex,
|
||||
type: asc ? SortType.ASC : SortType.DESC,
|
||||
}];
|
||||
|
||||
const range: IRange = {
|
||||
startRow: 0,
|
||||
startColumn: 0,
|
||||
endRow: this._worksheet.getRowCount() - 1,
|
||||
endColumn: this._worksheet.getColumnCount() - 1,
|
||||
rangeType: RANGE_TYPE.ALL,
|
||||
};
|
||||
this._commandService.syncExecuteCommand(SortRangeCommand.id, {
|
||||
orderRules,
|
||||
range,
|
||||
hasTitle: false,
|
||||
unitId: this._workbook.getUnitId(),
|
||||
subUnitId: this._worksheet.getSheetId(),
|
||||
});
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
FWorksheet.extend(FWorksheetSortMixin);
|
||||
declare module '@univerjs/sheets/facade' {
|
||||
// eslint-disable-next-line ts/naming-convention
|
||||
interface FWorksheet extends IFWorksheetSortMixin {}
|
||||
}
|
||||
Reference in New Issue
Block a user