Skip to content

Commit

Permalink
Add a sort button to column header (#18561)
Browse files Browse the repository at this point in the history
* add new sort button

* remove extraneous call

* wip

* store prev sort button

* remove reset to unfiltered state after sorting a column

* Revert "remove reset to unfiltered state after sorting a column"

This reverts commit 1d3b70d.

* add third state for sort button, resetting data to original order

* fix sort/filter scenarios

* fix build

* pr comments & cleanup

* cleanup

* update comment
  • Loading branch information
cssuh authored Mar 10, 2025
1 parent d48830d commit e77bb30
Show file tree
Hide file tree
Showing 18 changed files with 272 additions and 61 deletions.
Binary file removed src/reactviews/media/sort-asc.gif
Binary file not shown.
Binary file removed src/reactviews/media/sort-asc.png
Binary file not shown.
Binary file removed src/reactviews/media/sort-desc.gif
Binary file not shown.
Binary file removed src/reactviews/media/sort-desc.png
Binary file not shown.
3 changes: 3 additions & 0 deletions src/reactviews/media/sort.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 2 additions & 7 deletions src/reactviews/media/sort_asc.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 2 additions & 7 deletions src/reactviews/media/sort_asc_inverse.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 2 additions & 7 deletions src/reactviews/media/sort_desc.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 2 additions & 7 deletions src/reactviews/media/sort_desc_inverse.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/reactviews/media/sort_inverse.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions src/reactviews/media/table.css
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,33 @@
flex: 0 0 auto;
}

.slick-header-sort-button,
.slick-header-sortdesc-button,
.slick-header-sortasc-button {
background-position: center center;
background-repeat: no-repeat;
cursor: pointer;
display: inline-block;
width: 16px;
flex: 0 0 auto;
margin-right: 2px;
background-color: transparent;
border: 0;
padding: 0;
}

.slick-header-sort-button {
background-image: url("sort_inverse.svg");
}

.slick-header-sortdesc-button {
background-image: url("sort_desc_inverse.svg");
}

.slick-header-sortasc-button {
background-image: url("sort_asc_inverse.svg");
}

.slick-header-menubutton {
background-position: center center;
background-repeat: no-repeat;
Expand Down
4 changes: 4 additions & 0 deletions src/reactviews/pages/QueryResult/table/asyncDataView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,10 @@ export class AsyncDataProvider<T extends Slick.SlickData>
throw new Error("Method not implemented.");
}

resetSort(): void {
throw new Error("Method not implemented.");
}

public getLength(): number {
return this.dataRows.getLength();
}
Expand Down
5 changes: 5 additions & 0 deletions src/reactviews/pages/QueryResult/table/dataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ export interface IDisposableDataProvider<T extends Slick.SlickData>
*/
sort(args: Slick.OnSortEventArgs<T>): Promise<void>;

/**
* Resets the sort
*/
resetSort(): void;

/**
* Event fired when the filters changed
*/
Expand Down
4 changes: 4 additions & 0 deletions src/reactviews/pages/QueryResult/table/hybridDataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ export class HybridDataProvider<T extends Slick.SlickData>
void this.provider.sort(options);
}

public async resetSort() {
void this.provider.resetSort();
}

private get thresholdReached(): boolean {
return (
this._options.inMemoryDataCountThreshold !== undefined &&
Expand Down
6 changes: 6 additions & 0 deletions src/reactviews/pages/QueryResult/table/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*--------------------------------------------------------------------------------------------*/

import { IDisposableDataProvider } from "./dataProvider";
import { SortDirection } from "./plugins/headerFilter.plugin";

export interface ITableMouseEvent {
anchor: HTMLElement | { x: number; y: number };
Expand Down Expand Up @@ -80,6 +81,11 @@ export interface FilterableColumn<T extends Slick.SlickData>
sorted?: SortProperties;
}

export interface ColumnSortState<T extends Slick.SlickData> {
column: Slick.Column<T>;
sortDirection: SortDirection;
}

export interface ITableKeyboardEvent {
cell?: { row: number; cell: number };
event: KeyboardEvent;
Expand Down
Loading

0 comments on commit e77bb30

Please sign in to comment.