Skip to content

Commit df23257

Browse files
authored
feat: add Grouping to Grid State (#2101)
* feat: add Grouping to Grid State
1 parent c92a0bf commit df23257

File tree

26 files changed

+195
-23
lines changed

26 files changed

+195
-23
lines changed

demos/aurelia/src/examples/slickgrid/example18.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ export class Example18 {
246246
sortDescIconCssClass: 'mdi mdi-arrow-down',
247247
onGroupChanged: (_e, args) => this.onGroupChanged(args),
248248
onExtensionRegistered: (extension) => (this.draggableGroupingPlugin = extension),
249+
initialGroupBy: ['duration'],
249250
},
250251
darkMode: this._darkMode,
251252
enableTextExport: true,

demos/aurelia/test/cypress/e2e/example18.cy.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,24 @@ describe('Example 18 - Draggable Grouping & Aggregators', () => {
2222
.each(($child, index) => expect($child.text()).to.eq(fullTitles[index]));
2323
});
2424

25+
it('should initially be grouped by "Duration" when loading the grid', () => {
26+
cy.get(`[style="transform: translateY(${GRID_ROW_HEIGHT * 0}px);"] > .slick-cell:nth(0) .slick-group-title`).should(
27+
'contain',
28+
'Duration: 0'
29+
);
30+
cy.get(`[style="transform: translateY(${GRID_ROW_HEIGHT * 1}px);"] > .slick-cell:nth(2)`).should('contain', '0');
31+
});
32+
33+
it('should clear all groups with "Clear all Grouping" and no longer expect any grouping', () => {
34+
cy.get('[data-test="clear-grouping-btn"]').click();
35+
cy.get('#grid18').find('.slick-group-toggle-all').should('be.hidden');
36+
37+
cy.get('#grid18')
38+
.find('.slick-draggable-dropzone-placeholder')
39+
.should('be.visible')
40+
.should('have.text', 'Drop a column header here to group by the column');
41+
});
42+
2543
it('should have a draggable dropzone on top of the grid in the top-header section', () => {
2644
cy.get('#grid18').find('.slick-topheader-panel .slick-dropzone:visible').contains('Drop a column header here to group by the column');
2745
});

demos/react/src/examples/slickgrid/Example18.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,8 @@ const Example18: React.FC = () => {
240240
sortAscIconCssClass: 'mdi mdi-arrow-up',
241241
sortDescIconCssClass: 'mdi mdi-arrow-down',
242242
onGroupChanged: (_e, args) => onGroupChanged(args),
243-
onExtensionRegistered: (extension) => {
244-
setDraggableGroupingPlugin(extension);
245-
},
243+
onExtensionRegistered: (extension) => setDraggableGroupingPlugin(extension),
244+
initialGroupBy: ['duration'],
246245
},
247246
darkMode,
248247
enableTextExport: true,

demos/react/test/cypress/e2e/example18.cy.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,24 @@ describe('Example 18 - Draggable Grouping & Aggregators', () => {
2222
.each(($child, index) => expect($child.text()).to.eq(fullTitles[index]));
2323
});
2424

25+
it('should initially be grouped by "Duration" when loading the grid', () => {
26+
cy.get(`[style="transform: translateY(${GRID_ROW_HEIGHT * 0}px);"] > .slick-cell:nth(0) .slick-group-title`).should(
27+
'contain',
28+
'Duration: 0'
29+
);
30+
cy.get(`[style="transform: translateY(${GRID_ROW_HEIGHT * 1}px);"] > .slick-cell:nth(2)`).should('contain', '0');
31+
});
32+
33+
it('should clear all groups with "Clear all Grouping" and no longer expect any grouping', () => {
34+
cy.get('[data-test="clear-grouping-btn"]').click();
35+
cy.get('#grid18').find('.slick-group-toggle-all').should('be.hidden');
36+
37+
cy.get('#grid18')
38+
.find('.slick-draggable-dropzone-placeholder')
39+
.should('be.visible')
40+
.should('have.text', 'Drop a column header here to group by the column');
41+
});
42+
2543
it('should have a draggable dropzone on top of the grid in the top-header section', () => {
2644
cy.get('#grid18').find('.slick-topheader-panel .slick-dropzone:visible').contains('Drop a column header here to group by the column');
2745
});

demos/vanilla/src/examples/example03.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,11 @@ export default class Example03 {
383383
// groupIconCssClass: 'mdi mdi-drag-vertical',
384384
initialGroupBy: ['duration'],
385385
},
386+
// Grouping Grid Presets only works with DraggableGrouping plugin (not regular Grouping),
387+
// however, it's typically better to use `initialGroupBy: []`
388+
presets: {
389+
grouping: ['duration'],
390+
},
386391
enableCheckboxSelector: true,
387392
enableRowSelection: true,
388393
checkboxSelector: {

demos/vue/src/components/Example18.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ function defineGrid() {
238238
sortDescIconCssClass: 'mdi mdi-arrow-down',
239239
onGroupChanged: (_e, args) => onGroupChanged(args),
240240
onExtensionRegistered: (extension) => (draggableGroupingPlugin = extension),
241+
initialGroupBy: ['duration'],
241242
},
242243
darkMode: darkMode.value,
243244
enableTextExport: true,

demos/vue/test/cypress/e2e/example18.cy.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,24 @@ describe('Example 18 - Draggable Grouping & Aggregators', () => {
2222
.each(($child, index) => expect($child.text()).to.eq(fullTitles[index]));
2323
});
2424

25+
it('should initially be grouped by "Duration" when loading the grid', () => {
26+
cy.get(`[style="transform: translateY(${GRID_ROW_HEIGHT * 0}px);"] > .slick-cell:nth(0) .slick-group-title`).should(
27+
'contain',
28+
'Duration: 0'
29+
);
30+
cy.get(`[style="transform: translateY(${GRID_ROW_HEIGHT * 1}px);"] > .slick-cell:nth(2)`).should('contain', '0');
31+
});
32+
33+
it('should clear all groups with "Clear all Grouping" and no longer expect any grouping', () => {
34+
cy.get('[data-test="clear-grouping-btn"]').click();
35+
cy.get('#grid18').find('.slick-group-toggle-all').should('be.hidden');
36+
37+
cy.get('#grid18')
38+
.find('.slick-draggable-dropzone-placeholder')
39+
.should('be.visible')
40+
.should('have.text', 'Drop a column header here to group by the column');
41+
});
42+
2543
it('should have a draggable dropzone on top of the grid in the top-header section', () => {
2644
cy.get('#grid18').find('.slick-topheader-panel .slick-dropzone:visible').contains('Drop a column header here to group by the column');
2745
});

docs/grid-functionalities/grid-state-preset.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ export interface CurrentSorter {
8282
export interface GridState {
8383
columns?: CurrentColumn[] | null;
8484
filters?: CurrentFilter[] | null;
85+
grouping?: string[] | null;
8586
sorters?: CurrentSorter[] | null;
8687
pagination?: {
8788
pageNumber: number;
@@ -93,6 +94,9 @@ export interface GridState {
9394
}
9495
```
9596

97+
> [!NOTE]
98+
> You can get Grouping column Ids as Grid State but it is limited to Draggable Grouping **only** via Grid Presets and it will not work with regular Grouping.
99+
96100
#### Example
97101
For example, we can set `presets` on a grid like so:
98102

@@ -145,6 +149,7 @@ export class GridExample {
145149
pagination: { pageNumber: 2, pageSize: 20 }
146150
}
147151
};
152+
}
148153
}
149154
```
150155

@@ -185,7 +190,7 @@ export class GridExample {
185190
</div>
186191
```
187192
## How to Load Grid with certain Columns Preset (example hide certain Column(s) on load)
188-
You can show/hide or even change a column position via the `presets`, yes `presets` is that powerful. All you need to do is to pass all Columns that you want to show as part of the `columns` property of `presets`. Typically you already have the entire columns definition since you just defined it, so you can loop through it and just use `map` to list the `columns` according to the structure needed (see [preset structure](Grid-State-&-Preset#structure.md)). What you have to know is that whatever array you provide to `presets`, that will equal to what the user will see and also in which order the columns will show (the array order does matter in this case). If a Columns is omitted from that array, then it will be considered to be a hidden column (you can still show it through Grid Menu and/or Column Picker).
193+
You can show/hide or even change a column position via the `presets`, yes `presets` is that powerful. All you need to do is to pass all Columns that you want to show as part of the `columns` property of `presets`. Typically you already have the entire columns definition since you just defined it, so you can loop through it and just use `map` to list the `columns` according to the structure needed (see [preset structure](grid-state-preset#structure.md)). What you have to know is that whatever array you provide to `presets`, that will equal to what the user will see and also in which order the columns will show (the array order does matter in this case). If a Columns is omitted from that array, then it will be considered to be a hidden column (you can still show it through Grid Menu and/or Column Picker).
189194

190195
So let say that we want to hide the last Column on page load, we can just find the column by it's `id` that you want to hide and pass the new column definition to the `presets` (again make sure to follow the correct preset structure).
191196

frameworks/angular-slickgrid/docs/TOC.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
* [Export to Excel](grid-functionalities/Export-to-Excel.md)
5757
* [Export to File (csv/txt)](grid-functionalities/Export-to-Text-File.md)
5858
* [Grid Menu](grid-functionalities/Grid-Menu.md)
59-
* [Grid State & Presets](grid-functionalities/Grid-State-&-Preset.md)
59+
* [Grid State & Presets](grid-functionalities/grid-state-preset.md)
6060
* [Grouping & Aggregators](grid-functionalities/grouping-and-aggregators.md)
6161
* [Header & Footer Slots](grid-functionalities/header-footer-slots.md)
6262
* [Header Menu & Header Buttons](grid-functionalities/Header-Menu-&-Header-Buttons.md)

frameworks/angular-slickgrid/docs/column-functionalities/filters/select-filter.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ If you want to load the grid with certain default filter(s), you can use the fol
9191
- `searchTerms` (array of values)
9292
9393
#### Note
94-
Even though the option of `searchTerms` it is much better to use the more powerful `presets` grid options, please refer to the [Grid State & Presets](../../grid-functionalities/Grid-State-&-Preset#grid-presets) for more info.
94+
Even though the option of `searchTerms` it is much better to use the more powerful `presets` grid options, please refer to the [Grid State & Presets](../../grid-functionalities/grid-state-preset#grid-presets) for more info.
9595
9696
**NOTE**
97-
If you also have `presets` in the grid options, then your `searchTerms` will be ignored completely (even if it's a different column) since `presets` have higher priority over `searchTerms`. See [Grid State & Grid Presets](../../grid-functionalities/Grid-State-&-Preset.md) from more info.
97+
If you also have `presets` in the grid options, then your `searchTerms` will be ignored completely (even if it's a different column) since `presets` have higher priority over `searchTerms`. See [Grid State & Grid Presets](../../grid-functionalities/grid-state-preset.md) from more info.
9898
9999
#### Sample
100100
```ts
@@ -207,7 +207,7 @@ Note: the defaults for single & multiple select filters are different
207207
```ts
208208
// define you columns, in this demo Effort Driven will use a Select Filter
209209
this.columnDefinitions = [
210-
{
210+
{
211211
id: 'effort-driven', name: 'Effort Driven', field: 'effortDriven',
212212
formatter: Formatters.checkmarkMaterial,
213213
type: 'boolean',

0 commit comments

Comments
 (0)