<div class="eg-grid-row eg-grid-body-row"
[ngClass]="{'eg-grid-row-selected': selector[idx]}"
- *ngFor="let row of currentPage(); let idx = index">
+ *ngFor="let row of dataSource.getPage(pager) | async; let idx = index">
<div class="eg-grid-cell eg-grid-checkbox-cell">
<input type='checkbox' [(ngModel)]="selector[idx]">
ngOnInit() {
}
-
- currentPage(): any[] {
- if (!this.dataSource.data) return [];
- return this.dataSource.data.slice(this.pager.offset, this.pager.limit);
- }
}
-//import {Observable} from 'rxjs/Rx';
+import {Observable} from 'rxjs/Rx';
+import {Pager} from '@eg/share/util/pager';
export class EgGridDataSource {
- data: any[] = [];
- sortSpec: any[] = [];
+ data: any[];
+ sortSpec: any[];
// Do we know how many items we have in total?
indeterminate: boolean
+ constructor() {
+ this.data = [];
+ this.sortSpec = [];
+ }
+
applySort() {
}
+
+ getPage(pager: Pager): Observable<Array<any>> {
+
+ if (!this.data) return Observable.from([]);
+
+ if (this.data[pager.offset] !== undefined) {
+ return Observable.of(
+ this.data.slice(pager.offset, pager.limit + pager.offset));
+ }
+ }
}
.eg-grid-body-cell {
}
+.eg-grid-toolbar {
+ display: flex;
+}
<div class="eg-grid">
- <!--
- <eg-grid-toolbar [columnSet]="columnSet"></eg-grid-toolbar>
- -->
+ <eg-grid-toolbar [pager]="pager"></eg-grid-toolbar>
<eg-grid-header [columnSet]="columnSet"></eg-grid-header>
<eg-grid-body
[columnSet]="columnSet"
import {EgGridColumnComponent} from './grid-column.component';
import {EgGridHeaderComponent} from './grid-header.component';
import {EgGridBodyComponent} from './grid-body.component';
+import {EgGridToolbarComponent} from './grid-toolbar.component';
@NgModule({
declarations: [
EgGridComponent,
EgGridColumnComponent,
EgGridHeaderComponent,
- EgGridBodyComponent
+ EgGridBodyComponent,
+ EgGridToolbarComponent
],
imports: [
CommonModule,
+import {EventEmitter} from '@angular/core';
/**
* Utility class for manage paged information.
offset: number = 0;
limit: number = null;
resultCount: number;
+ onChange$: EventEmitter<number>;
+
+ constructor() {
+ this.onChange$ = new EventEmitter<number>();
+ }
isFirstPage(): boolean {
return this.offset == 0;
setPage(page: number): void {
this.offset = (this.limit * (page - 1));
+ this.onChange$.emit(this.offset);
}
pageCount(): number {
<!-- grid stuff -->
-<eg-grid #cbtGrid idlClass="cbt" [dataSource]="billingTypes">
+<eg-grid #cbtGrid idlClass="cbt" [dataSource]="btSource">
</eg-grid>
<!--
import {Observable} from 'rxjs/Rx';
import {EgGridDataSource} from '@eg/share/grid/grid-data-source';
import {EgIdlService, EgIdlObject} from '@eg/core/idl.service';
+import {EgPcrudService} from '@eg/core/pcrud.service';
@Component({
templateUrl: 'sandbox.component.html'
gridDataSource: EgGridDataSource = new EgGridDataSource();
- billingTypes: EgGridDataSource = new EgGridDataSource();
+ btSource: EgGridDataSource = new EgGridDataSource();
testStr: string;
constructor(
private idl: EgIdlService,
+ private pcrud: EgPcrudService,
private strings: EgStringService,
private toast: EgToastService
) {}
{name: 'The Tick', state: 'TX'}
];
- let bt1 = this.idl.create('cbt');
- let bt2 = this.idl.create('cbt');
- bt1.id = 12;
- bt1.name = 'BT1';
- bt2.id = 47;
- bt1.name = 'BT2';
- this.billingTypes.data = [bt1, bt2];
+ this.pcrud.retrieveAll('cbt').subscribe(
+ bt => this.btSource.data.push(bt));
}
showProgress() {