|
| 1 | +# Edit Capability Control |
| 2 | + |
| 3 | +In `VTableSheet`, the editing capability is enabled by default. However, in some scenarios (such as preview mode or permission control), you may need to disable editing globally or for specific sheets. |
| 4 | + |
| 5 | +VTableSheet provides flexible configuration options to control the editing capability and keyboard shortcuts at both the global and sheet levels. |
| 6 | + |
| 7 | +## Configuration Options |
| 8 | + |
| 9 | +### editable |
| 10 | + |
| 11 | +- **Type**: `boolean` |
| 12 | +- **Default**: `true` (if not configured globally or on the sheet) |
| 13 | +- **Description**: Controls whether the table is editable. |
| 14 | + - When set to `false`, the table enters **Read-Only Mode**: |
| 15 | + - Double-click editing is disabled. |
| 16 | + - Editors are not registered. |
| 17 | + - Modification shortcuts (Cut, Paste, etc.) are disabled. |
| 18 | + - Context menu items related to modification (Insert/Delete rows, Merge cells, etc.) are hidden or disabled. |
| 19 | + - The Delete/Backspace key will not clear cell content (unless configured otherwise). |
| 20 | + - **Priority**: The configuration on a specific sheet (`ISheetDefine.editable`) takes precedence over the global configuration (`IVTableSheetOptions.editable`). |
| 21 | + |
| 22 | +### keyboardShortcutPolicy |
| 23 | + |
| 24 | +- **Type**: `SheetKeyboardShortcutPolicy` |
| 25 | +- **Description**: Defines the policy for keyboard shortcuts, allowing fine-grained control over specific actions. |
| 26 | +- **Properties**: |
| 27 | + - `copySelected` (boolean): Enable copy shortcut (Ctrl+C). Default `true`. |
| 28 | + - `cutSelected` (boolean): Enable cut shortcut (Ctrl+X). Default `true` (disabled in Read-Only mode). |
| 29 | + - `pasteValueToCell` (boolean): Enable paste shortcut (Ctrl+V). Default `true` (disabled in Read-Only mode). |
| 30 | + - `selectAllOnCtrlA` (boolean): Enable select all shortcut (Ctrl+A). Default `true`. |
| 31 | + - `deleteRange` (boolean): Enable clearing cell content with Delete/Backspace. Default `true` (disabled in Read-Only mode). |
| 32 | + - ... (other navigation shortcuts like `moveFocusCellOnTab`, `editCellOnEnter`, etc.) |
| 33 | + |
| 34 | +## Usage Examples |
| 35 | + |
| 36 | +### 1. Global Read-Only Mode |
| 37 | + |
| 38 | +You can set the entire workbook to read-only by configuring `editable: false` in the initialization options. |
| 39 | + |
| 40 | +```typescript |
| 41 | +import { VTableSheet } from '@visactor/vtable-sheet'; |
| 42 | + |
| 43 | +const sheet = new VTableSheet(container, { |
| 44 | + editable: false, // Global read-only |
| 45 | + sheets: [ |
| 46 | + { |
| 47 | + sheetKey: 'sheet1', |
| 48 | + data: data1 |
| 49 | + }, |
| 50 | + { |
| 51 | + sheetKey: 'sheet2', |
| 52 | + data: data2 |
| 53 | + } |
| 54 | + ] |
| 55 | +}); |
| 56 | +``` |
| 57 | + |
| 58 | +### 2. Mixed Mode (Global Read-Only with Specific Editable Sheets) |
| 59 | + |
| 60 | +You can set the global default to read-only, and enable editing for specific sheets. |
| 61 | + |
| 62 | +```typescript |
| 63 | +const sheet = new VTableSheet(container, { |
| 64 | + editable: false, // Default read-only |
| 65 | + sheets: [ |
| 66 | + { |
| 67 | + sheetKey: 'read_only_sheet', |
| 68 | + sheetTitle: 'Read Only', |
| 69 | + data: data1 |
| 70 | + // Inherits global editable: false |
| 71 | + }, |
| 72 | + { |
| 73 | + sheetKey: 'editable_sheet', |
| 74 | + sheetTitle: 'Editable', |
| 75 | + data: data2, |
| 76 | + editable: true // Override global setting |
| 77 | + } |
| 78 | + ] |
| 79 | +}); |
| 80 | +``` |
| 81 | + |
| 82 | +### 3. Custom Keyboard Shortcut Policy |
| 83 | + |
| 84 | +You can customize the keyboard behavior. For example, disable Cut and Paste but allow Copy, or disable clearing content with the Delete key. |
| 85 | + |
| 86 | +```typescript |
| 87 | +const sheet = new VTableSheet(container, { |
| 88 | + // Global policy: Allow copy, disable cut/paste |
| 89 | + keyboardShortcutPolicy: { |
| 90 | + copySelected: true, |
| 91 | + cutSelected: false, |
| 92 | + pasteValueToCell: false |
| 93 | + }, |
| 94 | + sheets: [ |
| 95 | + { |
| 96 | + sheetKey: 'sheet1', |
| 97 | + data: data1 |
| 98 | + }, |
| 99 | + { |
| 100 | + sheetKey: 'sheet2', |
| 101 | + data: data2, |
| 102 | + // Sheet-level policy: Allow delete range |
| 103 | + keyboardShortcutPolicy: { |
| 104 | + deleteRange: true |
| 105 | + } |
| 106 | + } |
| 107 | + ] |
| 108 | +}); |
| 109 | +``` |
0 commit comments