LP1911238 Angular grid shift-click support
authorBill Erickson <berickxx@gmail.com>
Tue, 12 Jan 2021 20:43:23 +0000 (15:43 -0500)
committerJane Sandberg <sandbej@linnbenton.edu>
Tue, 18 May 2021 00:45:46 +0000 (17:45 -0700)
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 <berickxx@gmail.com>
Signed-off-by: Terran McCanna <tmccanna@georgialibraries.org>
Signed-off-by: Jane Sandberg <sandbej@linnbenton.edu>

Open-ILS/src/eg2/src/app/share/grid/grid-body.component.ts
Open-ILS/src/eg2/src/app/share/grid/grid.ts

index 3869ea4..14c6b4c 100644 (file)
@@ -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);
index 72c0947..447d9e6 100644 (file)
@@ -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