Skip to content

Commit 21d1489

Browse files
committed
chore: make Example 19 grid editable
1 parent 69aae96 commit 21d1489

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

examples/vite-demo-vanilla-bundle/src/examples/example19.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ <h6 class="title is-6">
1919
<span class="icon mdi mdi-swap-vertical"></span>
2020
<span>Toggle Pagination</span>
2121
</button>
22+
<button class="button is-small" onclick.delegate="toggleGridEditReadonly()" data-test="toggle-readonly-btn">
23+
<span class="icon mdi mdi-table-edit"></span>
24+
<span>Toggle Edit/Readonly Grid</span>
25+
</button>
2226
<label class="ml-3">Range Selection</label>
2327
<span id="selectionRange"></span>
2428
</h6>

examples/vite-demo-vanilla-bundle/src/examples/example19.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { type Column, type GridOption, SlickEventHandler } from '@slickgrid-universal/common';
1+
import { type Column, type GridOption, SlickEventHandler, Editors } from '@slickgrid-universal/common';
22
import { Slicker, SlickVanillaGridBundle } from '@slickgrid-universal/vanilla-bundle';
33
import { ExampleGridOptions } from './example-grid-options';
44
import './example19.scss';
55

66
const NB_ITEMS = 100;
7+
78
export default class Example19 {
89
protected _eventHandler: SlickEventHandler;
910

@@ -13,6 +14,7 @@ export default class Example19 {
1314
gridContainerElm: HTMLDivElement;
1415
isWithPagination = true;
1516
sgb: SlickVanillaGridBundle;
17+
isGridEditable = true;
1618

1719
attached() {
1820
this._eventHandler = new SlickEventHandler();
@@ -52,7 +54,7 @@ export default class Example19 {
5254
id: 'selector',
5355
name: '',
5456
field: 'num',
55-
width: 30
57+
width: 30,
5658
}
5759
];
5860

@@ -62,9 +64,10 @@ export default class Example19 {
6264
name: i < 26
6365
? String.fromCharCode('A'.charCodeAt(0) + (i % 26))
6466
: String.fromCharCode('A'.charCodeAt(0) + (Math.floor(i / 26)) - 1) + String.fromCharCode('A'.charCodeAt(0) + (i % 26)),
65-
field: i as any,
67+
field: String(i),
6668
minWidth: 60,
6769
width: 60,
70+
editor: { model: Editors.text }
6871
});
6972
}
7073

@@ -74,6 +77,8 @@ export default class Example19 {
7477
},
7578
enableCellNavigation: true,
7679
enablePagination: true,
80+
autoEdit: true,
81+
editable: this.isGridEditable,
7782
pagination: {
7883
pageSizes: [5, 10, 15, 20, 25, 50, 75, 100],
7984
pageSize: 20
@@ -119,4 +124,11 @@ export default class Example19 {
119124
this.sgb.paginationService!.togglePaginationVisibility(this.isWithPagination);
120125
this.sgb.slickGrid!.setSelectedRows([]);
121126
}
127+
128+
toggleGridEditReadonly() {
129+
// then change a single grid options to make the grid non-editable (readonly)
130+
this.isGridEditable = !this.isGridEditable;
131+
this.sgb.gridOptions = { editable: this.isGridEditable };
132+
this.gridOptions = this.sgb.gridOptions;
133+
}
122134
}

test/cypress/e2e/example19.cy.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ describe('Example 19 - ExcelCopyBuffer with Cell Selection', () => {
2222
});
2323
});
2424

25+
it('should make grid readonly and not editable', () => {
26+
cy.get('[data-test="toggle-readonly-btn"]').click();
27+
});
28+
2529
describe('with Pagination of size 20', () => {
2630
it('should click on cell B14 then Ctrl+Shift+End with selection B14-CV19', () => {
2731
cy.getCell(14, 2, '', { parentSelector: '.grid19', rowHeight: GRID_ROW_HEIGHT })

0 commit comments

Comments
 (0)