Skip to content

Commit ee8e105

Browse files
committed
update docs
1 parent b14dc6b commit ee8e105

3 files changed

Lines changed: 169 additions & 0 deletions

File tree

packages/docs/pages/api-reference/props.mdx

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ Some properties are only valid for columns or rows:
7272
|----------|-----------|-------------|
7373
| `width` | Columns only | Column width in pixels |
7474
| `height` | Rows only | Row height in pixels |
75+
| `label` | Columns only | Custom display text for the column header |
7576
| `labeler` | Both | Custom labeler for headers |
7677

7778
**Note**: If you specify `width` or `height` on a cell address like `D3`, it will be ignored.
@@ -86,6 +87,7 @@ Each cell can be configured with the following properties:
8687
| `style` | `CSSProperties` | CSS properties for appearance |
8788
| `justifyContent` | `CSSProperties['justifyContent']` | Horizontal alignment within the cell |
8889
| `alignItems` | `CSSProperties['alignItems']` | Vertical alignment within the cell |
90+
| `label` | `string` | Custom display text for column headers (only valid on column specifications, e.g., `A`, `B`) |
8991
| `labeler` | `string` | Key of a labeler registered in the hub |
9092
| `width` | `Width` | Cell width in pixels |
9193
| `height` | `Height` | Cell height in pixels |
@@ -100,6 +102,60 @@ Each cell can be configured with the following properties:
100102
- **Serialization**: Cell values (except `system` field) are designed to be serializable. Avoid storing non-serializable objects like class instances.
101103
- **System Field**: The `system` field contains values used by the system to display correct values. Do not modify this field manually.
102104

105+
### Prevention Flags
106+
107+
The `prevention` property uses bitwise flags from the `operations` export to restrict specific operations on cells, columns, or rows. Multiple flags can be combined with the `|` (OR) operator.
108+
109+
```tsx
110+
import { operations } from '@gridsheet/react-core';
111+
```
112+
113+
| Flag | Value | Description |
114+
|------|-------|-------------|
115+
| `RemoveRows` | 1 | Prevent removing rows |
116+
| `RemoveCols` | 2 | Prevent removing columns |
117+
| `InsertRowsAbove` | 4 | Prevent inserting rows above |
118+
| `InsertRowsBelow` | 8 | Prevent inserting rows below |
119+
| `InsertColsLeft` | 16 | Prevent inserting columns to the left |
120+
| `InsertColsRight` | 32 | Prevent inserting columns to the right |
121+
| `MoveFrom` | 64 | Prevent moving cells from this location |
122+
| `MoveTo` | 128 | Prevent moving cells to this location |
123+
| `Write` | 256 | Prevent editing cell values |
124+
| `Style` | 512 | Prevent changing cell styles |
125+
| `Resize` | 1024 | Prevent resizing rows/columns |
126+
| `SetRenderer` | 2048 | Prevent changing cell renderer |
127+
| `SetParser` | 4096 | Prevent changing cell parser |
128+
| `Copy` | 8192 | Prevent copying cells |
129+
| `SetPolicy` | 16384 | Prevent changing cell policy |
130+
| `Sort` | 32768 | Prevent sorting by this column |
131+
| `Filter` | 65536 | Prevent filtering by this column |
132+
| `SetLabel` | 131072 | Prevent editing the column header label |
133+
| `SetLabeler` | 262144 | Prevent changing the column header labeler |
134+
135+
**Convenience aliases:**
136+
| Alias | Combines | Description |
137+
|-------|----------|-------------|
138+
| `Move` | `MoveFrom \| MoveTo` | Prevent all move operations |
139+
| `ReadOnly` | `Write \| Style \| Move \| Copy` | Prevent all data modifications |
140+
| `ViewOnly` | `ReadOnly \| Resize` | Prevent all modifications including resize |
141+
142+
```tsx
143+
// Prevent sorting and filtering on column C
144+
{
145+
C: {
146+
prevention: operations.Sort | operations.Filter,
147+
},
148+
}
149+
150+
// Column with a custom label, protected from label editing
151+
{
152+
A: {
153+
label: 'Name',
154+
prevention: operations.SetLabel,
155+
},
156+
}
157+
```
158+
103159
### Example Usage
104160

105161
```tsx

packages/docs/pages/api-reference/table.mdx

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,3 +282,108 @@ const newTable = table.copy({
282282
});
283283
sync(newTable); // Required to apply changes
284284
```
285+
286+
### Sort and Filter Operations
287+
288+
#### `sortRows(args: { x: number; direction: 'asc' | 'desc' }): UserTable`
289+
Sorts all data rows by the values in the specified column. Supports ascending and descending order. Null/undefined values are sorted to the end. This operation is recorded in the undo/redo history.
290+
291+
```tsx
292+
// Sort by column B ascending
293+
const newTable = table.sortRows({ x: 2, direction: 'asc' });
294+
sync(newTable);
295+
296+
// Sort by column A descending
297+
const newTable = table.sortRows({ x: 1, direction: 'desc' });
298+
sync(newTable);
299+
```
300+
301+
#### `filterRows(args: { x: number; filter: FilterConfig }): UserTable`
302+
Applies a filter to the specified column. Rows that do not match the filter conditions are hidden. Multiple columns can have independent filters, and they are combined with AND logic across columns.
303+
304+
The `FilterConfig` object has the following structure:
305+
306+
```tsx
307+
type FilterConfig = {
308+
mode: 'and' | 'or'; // How multiple conditions are combined
309+
conditions: FilterCondition[];
310+
};
311+
312+
type FilterCondition = {
313+
method: FilterConditionMethod; // e.g., 'eq', 'contains', 'gt', etc.
314+
value: string[];
315+
};
316+
```
317+
318+
Available filter methods:
319+
320+
| Method | Description |
321+
|--------|-------------|
322+
| `eq` | Equals |
323+
| `ne` | Not equals |
324+
| `gt` | Greater than |
325+
| `gte` | Greater than or equal |
326+
| `lt` | Less than |
327+
| `lte` | Less than or equal |
328+
| `contains` | Contains substring |
329+
| `notContains` | Does not contain substring |
330+
| `empty` | Cell is empty (no value required) |
331+
| `notEmpty` | Cell is not empty (no value required) |
332+
333+
```tsx
334+
// Filter column B: show only rows where value > 80
335+
const newTable = table.filterRows({
336+
x: 2,
337+
filter: {
338+
mode: 'and',
339+
conditions: [{ method: 'gt', value: ['80'] }],
340+
},
341+
});
342+
sync(newTable);
343+
```
344+
345+
#### `clearFilterRows(x?: number): UserTable`
346+
Clears filter conditions. If `x` is provided, clears only the filter for that column. If omitted, clears all column filters.
347+
348+
```tsx
349+
// Clear filter on column B only
350+
const newTable = table.clearFilterRows(2);
351+
sync(newTable);
352+
353+
// Clear all filters
354+
const newTable = table.clearFilterRows();
355+
sync(newTable);
356+
```
357+
358+
#### `isRowFiltered(y: number): boolean`
359+
Returns `true` if the specified row is currently hidden by a filter.
360+
361+
```tsx
362+
if (table.isRowFiltered(3)) {
363+
console.log('Row 3 is hidden by a filter');
364+
}
365+
```
366+
367+
#### `hasActiveFilters(): boolean`
368+
Returns `true` if any column has an active filter.
369+
370+
```tsx
371+
if (table.hasActiveFilters()) {
372+
console.log('Some filters are active');
373+
}
374+
```
375+
376+
### Column Label Operations
377+
378+
#### `setColLabel(args: { x: number; label: string }): UserTable`
379+
Sets a custom display label for the specified column header. If an empty string is provided, the label is removed and the default column letter (A, B, C, ...) is displayed. This operation is recorded in the undo/redo history.
380+
381+
```tsx
382+
// Set column A header to "Name"
383+
const newTable = table.setColLabel({ x: 1, label: 'Name' });
384+
sync(newTable);
385+
386+
// Reset column A header to default ("A")
387+
const newTable = table.setColLabel({ x: 1, label: '' });
388+
sync(newTable);
389+
```

packages/docs/pages/getting-started/features.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ Comprehensive event system for spreadsheet operations:
6262
- **Initialization Events**: `onInit` for table initialization
6363
- **Real-time Feedback**: Immediate event notifications for all operations
6464

65+
### Column Menu
66+
67+
Interactive column header menu accessible via the ⋮ button on each column:
68+
- **Sort**: Sort rows ascending (A→Z) or descending (Z→A) by column values
69+
- **Filter**: Show/hide rows based on conditions (equals, contains, greater than, etc.) with AND/OR logic and multiple conditions
70+
- **Label Editing**: Rename column headers directly from the menu
71+
- **Prevention Support**: Granular control over which operations are available per column using `operations.Sort`, `operations.Filter`, `operations.SetLabel`, `operations.SetLabeler`
72+
6573
## Performance Features
6674

6775
- **Virtual Scrolling**: Efficient rendering for large datasets

0 commit comments

Comments
 (0)