Skip to content

Commit 3d91d79

Browse files
committed
feat: add column sorting and filter on classification column
- Register Filters, DropdownMenu, ColumnSorting plugins - Enable columnSorting for all columns - Enable Filter by value only on classification column (col 2) - Hide Filter by condition as it does not suit hierarchical string data - Keep default menu items (insert/remove/clear/read only/alignment) for all columns
1 parent e82e97d commit 3d91d79

1 file changed

Lines changed: 33 additions & 1 deletion

File tree

src/Editor/CressTable.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Handsontable from 'handsontable';
2+
import { registerPlugin, Filters, DropdownMenu, ColumnSorting } from 'handsontable/plugins';
23
import { ImageTools } from './ImageTools';
34
import { MeiTools } from './MeiTools';
45
import { ExportTools } from './ExportTools';
@@ -8,6 +9,11 @@ import { setSavedStatus } from '../utils/Unsaved';
89
import * as Notification from '../utils/Notification';
910
import { TableEvent } from '../Types';
1011

12+
// Register Handsontable plugins
13+
registerPlugin(Filters);
14+
registerPlugin(DropdownMenu);
15+
registerPlugin(ColumnSorting);
16+
1117
const changeHooks: TableEvent[] = [
1218
'afterChange',
1319
'afterColumnMove',
@@ -102,7 +108,33 @@ export class CressTable {
102108
autoWrapRow: true,
103109
autoWrapCol: true,
104110
contextMenu: true,
105-
dropdownMenu: true,
111+
// Dropdown menu: only show filter items on classification (col 2)
112+
dropdownMenu: {
113+
items: {
114+
col_left: {},
115+
col_right: {},
116+
remove_col: {},
117+
clear_column: {},
118+
make_read_only: {},
119+
alignment: {},
120+
sp1: { name: '---------' },
121+
filter_by_value: {
122+
hidden() {
123+
const col = this.getSelectedRangeLast()?.from?.col;
124+
return col !== 2;
125+
},
126+
},
127+
filter_action_bar: {
128+
hidden() {
129+
const col = this.getSelectedRangeLast()?.from?.col;
130+
return col !== 2;
131+
},
132+
},
133+
},
134+
},
135+
filters: true,
136+
// Sorting: only allow on name (col 1) and classification (col 2)
137+
columnSorting: true,
106138
className: 'table-menu-btn',
107139
licenseKey: 'non-commercial-and-evaluation',
108140
afterLoadData: (_, initialLoad) => {

0 commit comments

Comments
 (0)