From fc2f20104473ba1a350b72b3c1d20f79896fdb2a Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Tue, 12 Jan 2021 15:43:23 -0500 Subject: [PATCH] LP1911238 Angular grid shift-click support Clicking on a row, then shift+clicking on another row now selects both the second row and all rows between the first and second in Angular grids. Signed-off-by: Bill Erickson Signed-off-by: Terran McCanna Signed-off-by: Jane Sandberg --- .../eg2/src/app/share/grid/grid-body.component.ts | 2 +- Open-ILS/src/eg2/src/app/share/grid/grid.ts | 25 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/Open-ILS/src/eg2/src/app/share/grid/grid-body.component.ts b/Open-ILS/src/eg2/src/app/share/grid/grid-body.component.ts index 3869ea4000..14c6b4c7f4 100644 --- a/Open-ILS/src/eg2/src/app/share/grid/grid-body.component.ts +++ b/Open-ILS/src/eg2/src/app/share/grid/grid-body.component.ts @@ -94,7 +94,7 @@ export class GridBodyComponent implements OnInit { this.context.toggleSelectOneRow(index); } else if ($event.shiftKey) { - // TODO shift range click + this.context.selectRowRange(index); } else { this.context.selectOneRow(index); diff --git a/Open-ILS/src/eg2/src/app/share/grid/grid.ts b/Open-ILS/src/eg2/src/app/share/grid/grid.ts index 72c09478b9..447d9e68f9 100644 --- a/Open-ILS/src/eg2/src/app/share/grid/grid.ts +++ b/Open-ILS/src/eg2/src/app/share/grid/grid.ts @@ -931,6 +931,31 @@ export class GridContext { ); } + // Select all rows between the previously selected row and + // the provided row, including the provided row. + // This is additive only -- rows are never de-selected. + selectRowRange(index: any) { + + if (!this.lastSelectedIndex) { + this.selectOneRow(index); + return; + } + + const next = this.getRowPosition(index); + const prev = this.getRowPosition(this.lastSelectedIndex); + const start = Math.min(prev, next); + const end = Math.max(prev, next); + + for (let idx = start; idx <= end; idx++) { + const row = this.dataSource.data[idx]; + if (row) { + this.rowSelector.select(this.getRowIndex(row)); + } + } + + this.lastSelectedIndex = index; + } + // shift-down-arrow // Select the next row in addition to any currently selected row. // However, if the next row is already selected, assume the user -- 2.11.0