Skip to content
This repository was archived by the owner on Jun 1, 2025. It is now read-only.

Commit 72ebed8

Browse files
committed
docs: add missing colspan/rowspan documentation
1 parent 79cafe2 commit 72ebed8

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

docs/TOC.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
* [Custom Tooltip](grid-functionalities/Custom-Tooltip-\(plugin\).md)
5151
* [Add, Update or Highlight a Datagrid Item](grid-functionalities/add-update-highlight.md)
5252
* [Dynamically Add CSS Classes to Item Rows](grid-functionalities/dynamic-item-metadata.md)
53+
* [Column & Row Spanning](grid-functionalities/column-row-spanning.md)
5354
* [Context Menu](grid-functionalities/Context-Menu.md)
5455
* [Custom Footer](grid-functionalities/Custom-Footer.md)
5556
* [Excel Copy Buffer Plugin](grid-functionalities/excel-copy-buffer.md)
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
### Description
2+
You can use Colspan and/or Rowspan by using the DataView Item Metadata Provider, however please note that row spanning is under a flag because of its small perf hit (`rowspan` requires an initial loop through of all row item metadata to map all row span).
3+
4+
> [!NOTE]
5+
> Please note that `colspan` and `rowspan` have multiple constraints that you must be aware,
6+
> any side effects will **not** keep anything in sync since metadata are based on grid row index based...
7+
> for example: Filtering/Sorting/Paging/ColumnReorder/ColumnHidding
8+
> These side effect will require user's own logic to deal with such things!
9+
10+
### Demo
11+
12+
#### Colspan / Rowspan
13+
[Employee Timesheets](https://ghiscoding.github.io/Angular-Slickgrid/#/rowspan-timesheets) / [Demo Component](https://github.com/ghiscoding/Angular-Slickgrid/blob/master/src/app/examples/grid43.component.ts)
14+
15+
[Large Dataset](https://ghiscoding.github.io/Angular-Slickgrid/#/rowspan-large) / [Demo Component](https://github.com/ghiscoding/Angular-Slickgrid/blob/master/src/app/examples/grid44.component.ts)
16+
17+
### Basic Usage
18+
19+
You can see a basic example below where we set static `metadata`, however you will must often use it with dynamic `metadata`, and it works in both cases. From the example below, the first object key is a number, `0` in our case, which represents the row index (again this can be dynamic). Then if we continue drilling down, we get a `columns` property which holds another object containing all the column indexes that will have a span (which can be individual `colspan`, `rowspan` or both of them at the same time).
20+
21+
What if we have a side effect that kicks in, for example a Sorting, Filtering, ...?
22+
Well, that is where you the developer will have to add your own logic to update this `metadata` with the expected code logic of what and how it's supposed to behave. Because as mentioned in the note above, the library is pretty dumb and does not know what is the expected behavior for any side effects and it **will not change any** of the `metadata` spans, you have to implement such logic yourself (for example, if we drag a column to another position then the `rowspan` will stay at the same exact column index which is most probably not what you want, you could subscribe to the `onColumnsChanged` to deal with this one). You can see the full list of Events that you can listen for changes and implement necessary callback to update your `metadata` accordingly (see [List of Available Events](https://ghiscoding.gitbook.io/angular-slickgrid/events/available-events) docs).
23+
24+
##### Component
25+
26+
```ts
27+
import type { Column, GridOption, ItemMetadata } from 'angular-slickgrid';
28+
29+
@Component({
30+
styleUrls: ['grid43.component.scss'],
31+
templateUrl: './grid43.component.html',
32+
encapsulation: ViewEncapsulation.None,
33+
})
34+
export class Grid43Component implements OnInit {
35+
gridOptions: GridOption;
36+
columnDefinitions: Column[];
37+
dataset: any[] = [];
38+
39+
// metadata can be dynamic too, it doesn't have to be preset
40+
metadata: ItemMetadata | Record<number, ItemMetadata> = {
41+
0: {
42+
columns: {
43+
1: { rowspan: 2 },
44+
2: { colspan: 2 },
45+
10: { colspan: 3, rowspan: 10 },
46+
13: { colspan: 2 },
47+
17: { colspan: 2, rowspan: 2 },
48+
},
49+
}
50+
};
51+
52+
ngOnInit(): void {
53+
// define the grid options & columns and then create the grid itself
54+
this.defineGrid();
55+
}
56+
57+
defineGrid() {
58+
this.columnDefinitions = [ /*...*/ ];
59+
60+
this.gridOptions = {
61+
enableCellNavigation: true,
62+
enableCellRowSpan: true, // required for rowspan to work
63+
dataView: {
64+
globalItemMetadataProvider: {
65+
getRowMetadata: (_item, row) => {
66+
return this.metadata[row];
67+
},
68+
},
69+
},
70+
rowTopOffsetRenderType: 'top', // rowspan doesn't render well with 'transform', default is 'top'
71+
};
72+
}
73+
}
74+
```

0 commit comments

Comments
 (0)