Skip to content

Make selectedRows an @Input #7717

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jul 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ All notable changes for each version of this project will be documented in this
- Added `closeOnEscape` - with it, the dialog can be allowed or prevented from closing when `Esc` is pressed.
- `IgxNavbar`:
- **Breaking Changes** - The `igx-action-icon` has been renamed to `igx-navbar-action`. It should get renamed in your components via `ng update`;
- `IgxGrid`, `IgxTreeGrid`, `IgxHierarchicalGrid`
- **Breaking Change** - The `selectedRows` method is now an `@Input` property. Setting it to an array of Row IDs will update the grid's selection state, any previous selection will be cleared. Setting it to an empty array will clear the selection entirely.
- `igxGrid`
- Added `onScroll` event, which is emitted when the grid is scrolled vertically or horizontally.
- Each grid now expose a default handling for boolean column types. The column will display `check` or `close` icon, instead of true/false by default.
Expand Down Expand Up @@ -46,6 +48,7 @@ The following example shows how you can use the Indigo theme:
}
```


### New Features
- `IgxGrid`, `IgxTreeGrid`, `IgxHierarchicalGrid`
- Introduced `showSummaryOnCollapse` grid property which allows you to control whether the summary row stays visible when the groupBy / parent row is collapsed.
Expand Down
36 changes: 23 additions & 13 deletions projects/igniteui-angular/src/lib/grids/grid-base.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ import {
InjectionToken,
Optional,
DoCheck,
Directive
Directive,
OnChanges,
SimpleChanges
} from '@angular/core';
import ResizeObserver from 'resize-observer-polyfill';
import 'igniteui-trial-watermark';
Expand Down Expand Up @@ -1093,6 +1095,26 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
filteringExpressionsTree: IFilteringExpressionsTree,
done: (values: any[]) => void) => void;

/**
* Gets/Sets the current selection state.
* @remarks
* Represents the selected rows' IDs (primary key or rowData)
* @example
* ```html
* <igx-grid [data]="localData" primaryKey="ID" rowSelection="multiple" [selectedRows]="[0, 1, 2]"><igx-grid>
* ```
*/
@Input()
public set selectedRows(rowIDs: any[]) {
rowIDs.length > 0
? this.selectRows(rowIDs, true)
: this.deselectAllRows();
}

public get selectedRows(): any[] {
return this.selectionService.getSelectedRows();
}

/**
* Emitted when `IgxGridCellComponent` is clicked.
* @remarks
Expand Down Expand Up @@ -5291,18 +5313,6 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
[...this.unpinnedDataView, ...this.pinnedDataView];
}

/**
* Get current selection state.
* @example
* Returns an array with selected rows' IDs (primaryKey or rowData)
* ```typescript
* const selectedRows = this.grid.selectedRows();
* ```
*/
public selectedRows(): any[] {
return this.selectionService.getSelectedRows();
}

/**
* Select specified rows by ID.
* @example
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -1022,20 +1022,20 @@ describe('IgxGrid - GroupBy #grid', () => {
grid.selectAllRows();
fix.detectChanges();

expect(grid.selectedRows().length).toEqual(8);
expect(grid.selectedRows.length).toEqual(8);
let rows = fix.debugElement.queryAll(By.css('.igx-grid__tr--selected'));
for (const r of rows) {
expect(r.componentInstance instanceof IgxGridRowComponent).toBe(true);
}

grid.deselectAllRows();
fix.detectChanges();
expect(grid.selectedRows().length).toEqual(0);
expect(grid.selectedRows.length).toEqual(0);

GridSelectionFunctions.clickHeaderRowCheckbox(fix);
fix.detectChanges();

expect(grid.selectedRows().length).toEqual(8);
expect(grid.selectedRows.length).toEqual(8);

rows = fix.debugElement.queryAll(By.css('.igx-grid__tr--selected'));
for (const r of rows) {
Expand Down Expand Up @@ -1600,7 +1600,7 @@ describe('IgxGrid - GroupBy #grid', () => {
GridSelectionFunctions.clickRowCheckbox(rows[0].element);
await wait(100);
grid.cdr.detectChanges();
expect(grid.selectedRows().length).toEqual(1);
expect(grid.selectedRows.length).toEqual(1);
GridSelectionFunctions.verifyRowSelected(rows[0]);

});
Expand Down
Loading