<!-- contextMenu applied to cells instead of rows so the position
of the popover is close to the mouse. As of writing, no way
to position the popover at the mouse -->
- <td role="cell" class="eg-grid-cell eg-grid-body-cell eg-grid-col-{{col.name}} eg-grid-type-{{col.datatype}} {{context.cellClassCallback(row, col)}}"
+ <td role="cell" class="eg-grid-cell eg-grid-body-cell {{context.setClassNames(row, col)}}"
[ngClass]="{'eg-grid-cell-overflow': context.overflowCells}"
*ngFor="let col of context.columnSet.displayColumns()">
<div class="eg-grid-cell-contents" (dblclick)="onRowDblClick(row)"
</colgroup>
<colgroup class="eg-grid-col-data">
<col *ngFor="let col of context.columnSet.displayColumns()"
- class="eg-grid-col eg-grid-col-{{col.name}} eg-grid-type-{{col.datatype}} eg-grid-class-{{context.idlClass}} {{context.cellClassCallback(row, col)}}">
+ class="eg-grid-col {{context.setClassNames(row, col)}}">
</colgroup>
<thead class="eg-grid-header" #egGridStickyHeader [context]="context" [ngClass]="{'eg-grid-sticky-header' : context.stickyGridHeader}" role="rowgroup"> </thead>
if (this.pageSize) {
this.context.pager.limit = this.pageSize;
}
-
+
// TS doesn't seem to like: let foo = bar || () => '';
this.context.rowClassCallback =
this.rowClassCallback || function () { return ''; };
this.context.cellClassCallback =
- this.cellClassCallback ||
- function (row: any, col: GridColumn) {
- if (col.datatype === 'money') {
- // get raw value
- let val;
- if (col.path) {
- val = this.nestedItemFieldValue(row, col);
- } else if (col.name in row) {
- val = this.getObjectFieldValue(row, col.name);
- }
- if (Number(val) < 0) {
- return 'negative-money-amount';
- }
- }
- return '';
- }
+ this.cellClassCallback || function () { return ''; };
this.context.rowSelector.selectionChange.subscribe(
keys => this.rowSelectionChange.emit(keys)
columnHasTextGenerator(col: GridColumn): boolean {
return this.cellTextGenerator && col.name in this.cellTextGenerator;
}
+
+ setClassNames(row: any, col: GridColumn): string {
+ /* set initial classes from specific grids' callbacks */
+ const classes = [this.cellClassCallback(row, col)];
+
+ /* Base classes */
+ if (col.datatype)
+ classes.push('eg-grid-type-'+col.datatype);
+ if (col.name)
+ classes.push('eg-grid-col-'+col.name);
+ if (col.idlClass)
+ classes.push('eg-grid-class-'+col.idlClass);
+ if (col.path)
+ classes.push('eg-grid-path-'+col.path.replace('.', '-'));
+ if (this.overflowCells)
+ classes.push('eg-grid-cell-overflow');
+
+ /* Type-based formats */
+ if (col.datatype.endsWith('count'))
+ classes.push('numeric');
+
+ switch (col.datatype) {
+ case 'money':
+ // get raw value
+ let val;
+ if (col.path) {
+ val = this.nestedItemFieldValue(row, col);
+ } else if (col.name in row) {
+ val = this.getObjectFieldValue(row, col.name);
+ }
+ if (Number(val) < 0) {
+ classes.push('negative-money-amount');
+ }
+ // don't break
+ case 'id':
+ case 'number':
+ case 'money':
+ classes.push('numeric');
+ break;
+ case 'callnumber':
+ case 'barcode':
+ classes.push('alphanumeric');
+ }
+
+ return classes.join(' ');
+ }
}