LP1821382 Grid showDeclaredFieldsOnly option; sort repair.
authorBill Erickson <berickxx@gmail.com>
Fri, 29 Mar 2019 16:47:27 +0000 (16:47 +0000)
committerDan Wells <dbw2@calvin.edu>
Wed, 29 May 2019 19:30:51 +0000 (15:30 -0400)
Adds a @Input() showDeclaredFieldsOnly option which tells the grid to
avoid showing auto-generated columns by default and only show those
declared in the markup.

Also repairs a grid column sorting/insert bug where declared columns
would be displayed in the wrong order when mixed with auto columns.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Dan Wells <dbw2@calvin.edu>
Open-ILS/src/eg2/src/app/share/grid/grid.component.ts
Open-ILS/src/eg2/src/app/share/grid/grid.ts

index e1f988f..2b28d2d 100644 (file)
@@ -76,6 +76,10 @@ export class GridComponent implements OnInit, AfterViewInit, OnDestroy {
     // the selected fields will be hidden.
     @Input() hideFields: string;
 
+    // When true, only display columns that are declared in the markup
+    // and leave all auto-generated fields hidden.
+    @Input() showDeclaredFieldsOnly: boolean;
+
     // Allow the caller to jump directly to a specific page of
     // grid data.
     @Input() pageOffset: number;
@@ -133,6 +137,7 @@ export class GridComponent implements OnInit, AfterViewInit, OnDestroy {
         this.context.showLinkSelectors = this.showLinkSelectors === true;
         this.context.disableMultiSelect = this.disableMultiSelect === true;
         this.context.rowFlairIsEnabled = this.rowFlairIsEnabled  === true;
+        this.context.showDeclaredFieldsOnly = this.showDeclaredFieldsOnly;
         this.context.rowFlairCallback = this.rowFlairCallback;
         this.context.disablePaging = this.disablePaging === true;
         if (this.showFields) {
index fc50f59..b133d1a 100644 (file)
@@ -130,7 +130,7 @@ export class GridColumnSet {
                 if (idx === 0) {
                     this.columns.unshift(col);
                 } else {
-                    this.columns.splice(idx - 1, 0, col);
+                    this.columns.splice(idx, 0, col);
                 }
                 return true;
             }
@@ -444,6 +444,7 @@ export class GridContext {
     overflowCells: boolean;
     showLinkSelectors: boolean;
     disablePaging: boolean;
+    showDeclaredFieldsOnly: boolean;
 
     // Allow calling code to know when the select-all-rows-in-page
     // action has occurred.
@@ -990,6 +991,10 @@ export class GridContext {
                 }
             }
 
+            if (this.showDeclaredFieldsOnly) {
+                col.hidden = true;
+            }
+
             this.columnSet.add(col);
         });
     }