<span *ngIf="!column.cellTemplate"
ngbTooltip="{{context.getRowColumnValue(row, column)}}"
+ class="{{cellClassCallback(row, column)}}"
triggers="mouseenter:mouseleave">
{{context.getRowColumnValue(row, column)}}
</span>
<span *ngIf="column.cellTemplate"
+ class="{{cellClassCallback(row, column)}}"
[ngbTooltip]="column.cellTemplate"
#tooltip="ngbTooltip"
(mouseenter)="tooltip.open(column.getCellContext(row))"
@Input() context: GridContext;
@Input() row: any;
@Input() column: GridColumn;
+ @Input() cellClassCallback: (row: any, col: GridColumn) => string;
constructor() {}
- ngOnInit() {}
+ ngOnInit() {
+ if (!this.cellClassCallback) {
+ this.cellClassCallback = (row: any, col: GridColumn) => '';
+ }
+ }
}
tabindex=1 so the grid body can capture keyboard events.
-->
<div class="eg-grid-body" tabindex="1" (keydown)="onGridKeyDown($event)">
- <div class="eg-grid-row eg-grid-body-row"
+ <div class="eg-grid-row eg-grid-body-row {{rowClassCallback(row)}}"
[ngClass]="{'selected': context.rowSelector.contains(context.getRowIndex(row))}"
*ngFor="let row of context.dataSource.getPageOfRows(context.pager); let idx = index">
(click)="onRowClick($event, row, idx)"
*ngFor="let col of context.columnSet.displayColumns()">
- <eg-grid-body-cell [context]="context" [row]="row" [column]="col">
+ <eg-grid-body-cell [context]="context" [row]="row" [column]="col"
+ [cellClassCallback]="cellClassCallback">
</eg-grid-body-cell>
</div>
</div>
export class GridBodyComponent implements OnInit {
@Input() context: GridContext;
+ @Input() rowClassCallback: (row: any) => string;
+ @Input() cellClassCallback: (row: any, col: GridColumn) => string;
constructor(@Host() private grid: GridComponent) {
}
- ngOnInit() {}
+ ngOnInit() {
+ if (!this.rowClassCallback) {
+ this.rowClassCallback = (row: any) => '';
+ }
+ }
// Not using @HostListener because it only works globally.
onGridKeyDown(evt: KeyboardEvent) {
</div>
</div>
- <eg-grid-body [context]="context"></eg-grid-body>
+ <eg-grid-body [context]="context"
+ [rowClassCallback]="rowClassCallback"
+ [cellClassCallback]="cellClassCallback">
+ </eg-grid-body>
</div>
import {FormatService} from '@eg/share/util/format.service';
import {GridContext, GridColumn, GridDataSource} from './grid';
+/**
+ * Main grid entry point.
+ */
+
@Component({
selector: 'eg-grid',
templateUrl: './grid.component.html',
styleUrls: ['grid.component.css'],
- // share grid css globally once imported.
+ // share grid css globally once imported so all grid component CSS
+ // can live in grid.component.css and to avoid multiple copies of
+ // the CSS when multiple grids are displayed.
encapsulation: ViewEncapsulation.None
})
@Input() multiSortable: boolean;
@Input() persistKey: string;
@Input() disableMultiSelect: boolean;
+ @Input() rowClassCallback: (row: any) => string;
+ @Input() cellClassCallback: (row: any, col: GridColumn) => string;
context: GridContext;
HELLO {{userContext.hello}}
<button>{{row.id()}}</button>
</ng-template>
-<eg-grid #cbtGrid idlClass="cbt" [dataSource]="btSource" [sortable]="true">
+<eg-grid #cbtGrid idlClass="cbt"
+ [dataSource]="btSource"
+ [rowClassCallback]="btGridRowClassCallback"
+ [cellClassCallback]="btGridCellClassCallback"
+ [sortable]="true">
<eg-grid-column name="test" [cellTemplate]="cellTmpl"
[cellContext]="btGridTestContext" [sortable]="false">
</eg-grid-column>
import 'rxjs/add/observable/timer';
import {map} from 'rxjs/operators/map';
import {take} from 'rxjs/operators/take';
-import {GridDataSource} from '@eg/share/grid/grid';
+import {GridDataSource, GridColumn} 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';
};
}
+ btGridRowClassCallback(row: any): string {
+ if (row.id() === 1) {
+ return 'text-uppercase font-weight-bold text-danger';
+ }
+ }
+
+ // apply to all 'name' columns regardless of row
+ btGridCellClassCallback(row: any, col: GridColumn): string {
+ if (col.name === 'name') {
+ return 'text-uppercase font-weight-bold text-success';
+ }
+ }
+
doPrint() {
this.printer.print({
template: this.printTemplate,