LP#1835982: add GridCellTextGenerator to the btGrid in the sandbox
authorGalen Charlton <gmc@equinoxinitiative.org>
Fri, 3 Jan 2020 16:33:19 +0000 (11:33 -0500)
committerJane Sandberg <sandbej@linnbenton.edu>
Sat, 18 Jan 2020 18:39:32 +0000 (10:39 -0800)
This patch also adds a usage note: since the GridCellTextGenerator
only has access to the row object but a cellTemplate can be passed
arbitrary context in addition to the row, a GridCellTextGenerator
that needs that additional context to have the print content match
the displayed content may require that the caller stick it in the
row object.

Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Jane Sandberg <sandbej@linnbenton.edu>
Open-ILS/src/eg2/src/app/share/grid/grid.ts
Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html
Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.ts

index 93094c3..59baa63 100644 (file)
@@ -399,6 +399,13 @@ export class GridColumnSet {
 // each mapped column on a given row.  This is primarily useful for
 // generating print-friendly content for grid cells rendered via
 // cellTemplate.
+//
+// USAGE NOTE: Since a cellTemplate can be passed arbitrary context
+//             but a GridCellTextGenerator only gets the row object,
+//             if it's important to include content that's not available
+//             by default in the row object, you may want to stick
+//             it in the row object as an additional attribute.
+//
 export interface GridCellTextGenerator {
     [columnName: string]: (row: any) => string;
 }
index d456ae0..3b9609b 100644 (file)
   [rowFlairCallback]="btGridRowFlairCallback"
   [cellClassCallback]="btGridCellClassCallback"
   [stickyHeader]="true"
+  [cellTextGenerator]="btGridCellTextGenerator"
   [sortable]="true">
   <eg-grid-toolbar-action label="Action that needs a single row" i18n-label
     (onClick)="complimentEvergreen($event)" [disableOnRows]="notOneSelectedRow">
index 13cd009..c44a7f7 100644 (file)
@@ -5,7 +5,7 @@ import {ProgressDialogComponent} from '@eg/share/dialog/progress.component';
 import {ToastService} from '@eg/share/toast/toast.service';
 import {StringService} from '@eg/share/string/string.service';
 import {map, take} from 'rxjs/operators';
-import {GridDataSource, GridColumn, GridRowFlairEntry} from '@eg/share/grid/grid';
+import {GridDataSource, GridColumn, GridRowFlairEntry, GridCellTextGenerator} from '@eg/share/grid/grid';
 import {IdlService, IdlObject} from '@eg/core/idl.service';
 import {PcrudService} from '@eg/core/pcrud.service';
 import {OrgService} from '@eg/core/org.service';
@@ -62,6 +62,7 @@ export class SandboxComponent implements OnInit {
     cbAsyncSource: (term: string) => Observable<ComboboxEntry>;
 
     btSource: GridDataSource = new GridDataSource();
+    btGridCellTextGenerator: GridCellTextGenerator;
     acpSource: GridDataSource = new GridDataSource();
     eventsDataSource: GridDataSource = new GridDataSource();
     editSelected: (rows: IdlObject[]) => void;
@@ -201,6 +202,14 @@ export class SandboxComponent implements OnInit {
             }));
         };
 
+        // GridCellTextGenerator for the btGrid; note that this
+        // also demonstrates that a GridCellTextGenerator only has
+        // access to the row, and does not have access to any additional
+        // context that might be passed to a cellTemplate
+        this.btGridCellTextGenerator = {
+            test: row => 'HELLO universe ' + row.id()
+        };
+
         this.acpSource.getRows = (pager: Pager, sort: any[]) => {
             const orderBy: any = {acp: 'id'};
             if (sort.length) {