Skip to content

Commit

Permalink
breaking change: recovered before source sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
m2a2x committed Dec 18, 2024
1 parent ff67895 commit b61c5d8
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 24 deletions.
2 changes: 1 addition & 1 deletion packages/angular
2 changes: 1 addition & 1 deletion packages/svelte
2 changes: 1 addition & 1 deletion packages/vue2
2 changes: 1 addition & 1 deletion packages/vue3
23 changes: 17 additions & 6 deletions src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { AfterEditEvent, AllDimensionType, ApplyFocusEvent, BeforeCellRenderEven
import { GridPlugin } from "./plugins/base.plugin";
import { AutoSizeColumnConfig } from "./plugins/column.auto-size.plugin";
import { ColumnFilterConfig, FilterCaptions, FilterCollectionItem, LogicFunction, MultiFilterItem, ShowData } from "./plugins/filter/filter.types";
import { SortingConfig } from "./plugins/sorting/sorting.types";
import { SortingConfig, SortingOrder } from "./plugins";
import { GroupingOptions } from "./plugins/groupingRow/grouping.row.types";
import { VNode } from "@stencil/core";
import { FocusedData } from "./components/revoGrid/viewport.service";
Expand All @@ -24,7 +24,7 @@ export { AfterEditEvent, AllDimensionType, ApplyFocusEvent, BeforeCellRenderEven
export { GridPlugin } from "./plugins/base.plugin";
export { AutoSizeColumnConfig } from "./plugins/column.auto-size.plugin";
export { ColumnFilterConfig, FilterCaptions, FilterCollectionItem, LogicFunction, MultiFilterItem, ShowData } from "./plugins/filter/filter.types";
export { SortingConfig } from "./plugins/sorting/sorting.types";
export { SortingConfig, SortingOrder } from "./plugins";
export { GroupingOptions } from "./plugins/groupingRow/grouping.row.types";
export { VNode } from "@stencil/core";
export { FocusedData } from "./components/revoGrid/viewport.service";
Expand Down Expand Up @@ -791,12 +791,16 @@ declare global {
"beforerange": ChangedRange;
"afterfocus": FocusAfterRenderEvent;
"roworderchanged": { from: number; to: number };
"beforesortingapply": {
"beforesorting": {
column: ColumnRegular;
order: 'desc' | 'asc';
additive: boolean;
};
"beforesorting": {
"beforesourcesortingapply": {
type: DimensionRows;
sorting?: SortingOrder;
};
"beforesortingapply": {
column: ColumnRegular;
order: 'desc' | 'asc';
additive: boolean;
Expand Down Expand Up @@ -1471,15 +1475,15 @@ declare namespace LocalJSX {
*/
"onBeforerowdefinition"?: (event: RevoGridCustomEvent<{ vals: any; oldVals: any }>) => void;
/**
* By sorting.plugin.ts Before sorting event. Initial sorting triggered, if this event stops no other event called. Use e.preventDefault() to prevent sorting.
* By `sorting.plugin.ts` <br>Triggered immediately after header click. <br>First in sorting event sequence. Ff this event stops no other event called. <br>Use `e.preventDefault()` to prevent sorting.
*/
"onBeforesorting"?: (event: RevoGridCustomEvent<{
column: ColumnRegular;
order: 'desc' | 'asc';
additive: boolean;
}>) => void;
/**
* By sorting.plugin.ts Before sorting apply. Use e.preventDefault() to prevent sorting data change.
* By `sorting.plugin.ts` <br> After `beforesorting` <br>Triggered after column data updated with new sorting order. <br>Use `e.preventDefault()` to prevent sorting data change.
*/
"onBeforesortingapply"?: (event: RevoGridCustomEvent<{
column: ColumnRegular;
Expand All @@ -1492,6 +1496,13 @@ declare namespace LocalJSX {
"onBeforesourceset"?: (event: RevoGridCustomEvent<{
type: DimensionRows;
source: DataType[];
}>) => void;
/**
* By `sorting.plugin.ts` <br>Same as `beforesorting` but triggered after `beforeanysource` (when source is changed). <br>Use `e.preventDefault()` to prevent sorting data change.
*/
"onBeforesourcesortingapply"?: (event: RevoGridCustomEvent<{
type: DimensionRows;
sorting?: SortingOrder;
}>) => void;
/**
* Emitted before trimming values. Use e.preventDefault() to prevent the default behavior of trimming values. Modify the `trimmed` property if you want to filter the indexes for trimming.
Expand Down
31 changes: 21 additions & 10 deletions src/components/revoGrid/revo-grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ import { ColumnCollection, getColumnByProp, getColumns } from '../../utils/colum
import { WCAGPlugin } from '../../plugins/wcag';
import { ColumnFilterConfig, FilterCollectionItem } from '../../plugins/filter/filter.types';
import { PluginService } from './plugin.service';
import { SortingConfig } from 'src/plugins/sorting/sorting.types';
import { SortingConfig, SortingOrder } from '../../plugins';


/**
Expand Down Expand Up @@ -369,23 +369,34 @@ export class RevoGridComponent {
@Event() roworderchanged: EventEmitter<{ from: number; to: number }>;

/**
* By sorting.plugin.ts
* Before sorting apply.
* Use e.preventDefault() to prevent sorting data change.
* By `sorting.plugin.ts`
* <br>Triggered immediately after header click.
* <br>First in sorting event sequence. Ff this event stops no other event called.
* <br>Use `e.preventDefault()` to prevent sorting.
*/
@Event() beforesortingapply: EventEmitter<{
@Event() beforesorting: EventEmitter<{
column: ColumnRegular;
order: 'desc' | 'asc';
additive: boolean;
}>;

/**
* By sorting.plugin.ts
* Before sorting event.
* Initial sorting triggered, if this event stops no other event called.
* Use e.preventDefault() to prevent sorting.
* By `sorting.plugin.ts`
* <br>Same as `beforesorting` but triggered after `beforeanysource` (when source is changed).
* <br>Use `e.preventDefault()` to prevent sorting data change.
*/
@Event() beforesorting: EventEmitter<{
@Event() beforesourcesortingapply: EventEmitter<{
type: DimensionRows;
sorting?: SortingOrder;
}>;

/**
* By `sorting.plugin.ts`
* <br> After `beforesorting`
* <br>Triggered after column data updated with new sorting order.
* <br>Use `e.preventDefault()` to prevent sorting data change.
*/
@Event() beforesortingapply: EventEmitter<{
column: ColumnRegular;
order: 'desc' | 'asc';
additive: boolean;
Expand Down
7 changes: 5 additions & 2 deletions src/plugins/sorting/sorting.plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ import { getCellRaw, getColumnByProp } from '../../utils/column.utils';
import { rowTypes } from '@store';
import { sortIndexByItems } from './sorting.func';

export * from './sorting.types';

/**
* Lifecycle
* 1. @event `beforesorting` - Triggered when sorting just starts. Nothing has happened yet. This can be triggered from a column or from the source. If the type is from rows, the column will be undefined.
* 1.1. @event `beforesourcesortingapply` - Triggered before the sorting data is applied to the data source. You can prevent this event, and the data will not be sorted.
* 2. @method `updateColumnSorting` - Updates the column sorting icon on the grid and the column itself, but the data remains untouched.
* 3. @event `beforesortingapply` - Triggered before the sorting data is applied to the data source. You can prevent this event, and the data will not be sorted. This event is only called from a column sorting click.
* 4. @event `aftersortingapply` - Triggered after sorting has been applied and completed. This event occurs for both row and column sorting.
Expand Down Expand Up @@ -84,8 +87,8 @@ export class SortingPlugin extends BasePlugin {
}) => {
// if sorting was provided - sort data
if (!!this.sorting && this.sortingFunc) {
const beforeEvent = this.emit('beforesorting', { type });
if (beforeEvent.defaultPrevented) {
const event = this.emit('beforesourcesortingapply', { type, sorting: this.sorting });
if (event.defaultPrevented) {
return;
}
this.startSorting(this.sorting, this.sortingFunc);
Expand Down
6 changes: 4 additions & 2 deletions src/types/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ export type RevogridEvents = 'contentsizechanged'|
'beforerange'|
'afterfocus'|
'roworderchanged'|
'beforesortingapply'|
'beforesorting'|
'beforesourcesortingapply'|
'beforesortingapply'|
'rowdragstart'|
'headerclick'|
'beforecellfocus'|
Expand Down Expand Up @@ -113,8 +114,9 @@ export const REVOGRID_EVENTS = new Map<RevogridEvents, RevogridEvents>([
['beforerange', 'beforerange'],
['afterfocus', 'afterfocus'],
['roworderchanged', 'roworderchanged'],
['beforesortingapply', 'beforesortingapply'],
['beforesorting', 'beforesorting'],
['beforesourcesortingapply', 'beforesourcesortingapply'],
['beforesortingapply', 'beforesortingapply'],
['rowdragstart', 'rowdragstart'],
['headerclick', 'headerclick'],
['beforecellfocus', 'beforecellfocus'],
Expand Down

0 comments on commit b61c5d8

Please sign in to comment.