2 * Collection of grid related classses and interfaces.
4 import {TemplateRef, EventEmitter} from '@angular/core';
5 import {Observable, Subscription} from 'rxjs';
6 import {IdlService, IdlObject} from '@eg/core/idl.service';
7 import {OrgService} from '@eg/core/org.service';
8 import {ServerStoreService} from '@eg/core/server-store.service';
9 import {FormatService} from '@eg/core/format.service';
10 import {Pager} from '@eg/share/util/pager';
12 const MAX_ALL_ROW_COUNT = 10000;
14 export class GridColumn {
23 // IDL class of the object which contains this field.
24 // Not to be confused with the class of a linked object.
28 datePlusTime: boolean;
29 cellTemplate: TemplateRef<any>;
32 isDragTarget: boolean;
34 isMultiSortable: boolean;
35 disableTooltip: boolean;
36 comparator: (valueA: any, valueB: any) => number;
38 // True if the column was automatically generated.
41 flesher: (obj: any, col: GridColumn, item: any) => any;
43 getCellContext(row: any) {
47 userContext: this.cellContext
52 export class GridColumnSet {
53 columns: GridColumn[];
55 indexColumn: GridColumn;
57 isMultiSortable: boolean;
58 stockVisible: string[];
60 defaultHiddenFields: string[];
61 defaultVisibleFields: string[];
63 constructor(idl: IdlService, idlClass?: string) {
66 this.stockVisible = [];
67 this.idlClass = idlClass;
70 add(col: GridColumn) {
72 this.applyColumnDefaults(col);
74 if (!this.insertColumn(col)) {
75 // Column was rejected as a duplicate.
79 if (col.isIndex) { this.indexColumn = col; }
81 // track which fields are visible on page load.
83 this.stockVisible.push(col.name);
86 this.applyColumnSortability(col);
89 // Returns true if the new column was inserted, false otherwise.
90 // Declared columns take precedence over auto-generated columns
91 // when collisions occur.
92 // Declared columns are inserted in front of auto columns.
93 insertColumn(col: GridColumn): boolean {
96 if (this.getColByName(col.name)) {
97 // New auto-generated column conflicts with existing
101 // No collisions. Add to the end of the list
102 this.columns.push(col);
107 // Adding a declared column.
110 for (let idx = 0; idx < this.columns.length; idx++) {
111 const testCol = this.columns[idx];
112 if (testCol.name === col.name) { // match found
113 if (testCol.isAuto) {
114 // new column takes precedence, remove the existing column.
115 this.columns.splice(idx, 1);
118 // New column does not take precedence. Avoid
125 // Delcared columns are inserted just before the first auto-column
126 for (let idx = 0; idx < this.columns.length; idx++) {
127 const testCol = this.columns[idx];
128 if (testCol.isAuto) {
130 this.columns.unshift(col);
132 this.columns.splice(idx - 1, 0, col);
138 // No insertion point found. Toss the new column on the end.
139 this.columns.push(col);
143 getColByName(name: string): GridColumn {
144 return this.columns.filter(c => c.name === name)[0];
147 idlInfoFromDotpath(dotpath: string): any {
148 if (!dotpath || !this.idlClass) { return null; }
152 let idlClass = this.idl.classes[this.idlClass];
154 const pathParts = dotpath.split(/\./);
156 for (let i = 0; i < pathParts.length; i++) {
157 const part = pathParts[i];
158 idlParent = idlField;
159 idlField = idlClass.field_map[part];
162 if (idlField['class'] && (
163 idlField.datatype === 'link' ||
164 idlField.datatype === 'org_unit')) {
165 idlClass = this.idl.classes[idlField['class']];
173 idlParent: idlParent,
181 this.columns.forEach(col => {
185 col.visible = this.stockVisible.includes(col.name);
189 applyColumnDefaults(col: GridColumn) {
191 if (!col.idlFieldDef && col.path) {
192 const idlInfo = this.idlInfoFromDotpath(col.path);
194 col.idlFieldDef = idlInfo.idlField;
195 col.idlClass = idlInfo.idlClass.name;
197 col.label = col.idlFieldDef.label || col.idlFieldDef.name;
198 col.datatype = col.idlFieldDef.datatype;
203 if (!col.name) { col.name = col.path; }
204 if (!col.flex) { col.flex = 2; }
205 if (!col.align) { col.align = 'left'; }
206 if (!col.label) { col.label = col.name; }
207 if (!col.datatype) { col.datatype = 'text'; }
209 col.visible = !col.hidden;
212 applyColumnSortability(col: GridColumn) {
213 // column sortability defaults to the sortability of the column set.
214 if (col.isSortable === undefined && this.isSortable) {
215 col.isSortable = true;
218 if (col.isMultiSortable === undefined && this.isMultiSortable) {
219 col.isMultiSortable = true;
222 if (col.isMultiSortable) {
223 col.isSortable = true;
227 displayColumns(): GridColumn[] {
228 return this.columns.filter(c => c.visible);
231 insertBefore(source: GridColumn, target: GridColumn) {
234 this.columns.forEach((col, idx) => {
235 if (col.name === target.name) { targetIdx = idx; }});
237 this.columns.forEach((col, idx) => {
238 if (col.name === source.name) { sourceIdx = idx; }});
240 if (sourceIdx >= 0) {
241 this.columns.splice(sourceIdx, 1);
244 this.columns.splice(targetIdx, 0, source);
247 // Move visible columns to the front of the list.
248 moveVisibleToFront() {
249 const newCols = this.displayColumns();
250 this.columns.forEach(col => {
251 if (!col.visible) { newCols.push(col); }});
252 this.columns = newCols;
255 moveColumn(col: GridColumn, diff: number) {
256 let srcIdx, targetIdx;
258 this.columns.forEach((c, i) => {
259 if (c.name === col.name) { srcIdx = i; }
262 targetIdx = srcIdx + diff;
265 } else if (targetIdx >= this.columns.length) {
266 // Target index follows the last visible column.
268 this.columns.forEach((c, idx) => {
269 if (c.visible) { lastVisible = idx; }
272 // When moving a column (down) causes one or more
273 // visible columns to shuffle forward, our column
274 // moves into the slot of the last visible column.
275 // Otherwise, put it into the slot directly following
276 // the last visible column.
277 targetIdx = srcIdx <= lastVisible ? lastVisible : lastVisible + 1;
280 // Splice column out of old position, insert at new position.
281 this.columns.splice(srcIdx, 1);
282 this.columns.splice(targetIdx, 0, col);
285 compileSaveObject(): GridColumnPersistConf[] {
286 // only store information about visible columns.
287 // scrunch the data down to just the needed info.
288 return this.displayColumns().map(col => {
289 const c: GridColumnPersistConf = {name : col.name};
290 if (col.align !== 'left') { c.align = col.align; }
291 if (col.flex !== 2) { c.flex = Number(col.flex); }
292 if (Number(col.sort)) { c.sort = Number(c.sort); }
297 applyColumnSettings(conf: GridColumnPersistConf[]) {
299 if (!conf || conf.length === 0) {
300 // No configuration is available, but we have a list of
301 // fields to show or hide by default
303 if (this.defaultVisibleFields) {
304 this.columns.forEach(col => {
305 if (this.defaultVisibleFields.includes(col.name)) {
312 } else if (this.defaultHiddenFields) {
313 this.defaultHiddenFields.forEach(name => {
314 const col = this.getColByName(name);
326 conf.forEach(colConf => {
327 const col = this.getColByName(colConf.name);
328 if (!col) { return; } // no such column in this grid.
331 if (colConf.align) { col.align = colConf.align; }
332 if (colConf.flex) { col.flex = Number(colConf.flex); }
333 if (colConf.sort) { col.sort = Number(colConf.sort); }
335 // Add to new columns array, avoid dupes.
336 if (newCols.filter(c => c.name === col.name).length === 0) {
341 // columns which are not expressed within the saved
342 // configuration are marked as non-visible and
343 // appended to the end of the new list of columns.
344 this.columns.forEach(c => {
345 if (conf.filter(cf => cf.name === c.name).length === 0) {
351 this.columns = newCols;
356 export class GridRowSelector {
357 indexes: {[string: string]: boolean};
363 // Returns true if all of the requested indexes exist in the selector.
364 contains(index: string | string[]): boolean {
365 const indexes = [].concat(index);
366 for (let i = 0; i < indexes.length; i++) { // early exit
367 if (!this.indexes[indexes[i]]) {
374 select(index: string | string[]) {
375 const indexes = [].concat(index);
376 indexes.forEach(i => this.indexes[i] = true);
379 deselect(index: string | string[]) {
380 const indexes = [].concat(index);
381 indexes.forEach(i => delete this.indexes[i]);
384 // Returns the list of selected index values.
385 // in some contexts (template checkboxes) the value for an index is
386 // set to false to deselect instead of having it removed (via deselect()).
388 return Object.keys(this.indexes).filter(
389 ind => Boolean(this.indexes[ind]));
393 return this.selected().length === 0;
401 export interface GridRowFlairEntry {
402 icon: string; // name of material icon
403 title?: string; // tooltip string
406 export class GridColumnPersistConf {
413 export class GridPersistConf {
416 columns: GridColumnPersistConf[];
419 export class GridContext {
424 isMultiSortable: boolean;
425 useLocalSort: boolean;
427 disableMultiSelect: boolean;
428 disableSelect: boolean;
429 dataSource: GridDataSource;
430 columnSet: GridColumnSet;
431 rowSelector: GridRowSelector;
432 toolbarButtons: GridToolbarButton[];
433 toolbarCheckboxes: GridToolbarCheckbox[];
434 toolbarActions: GridToolbarAction[];
435 lastSelectedIndex: any;
436 pageChanges: Subscription;
437 rowFlairIsEnabled: boolean;
438 rowFlairCallback: (row: any) => GridRowFlairEntry;
439 rowClassCallback: (row: any) => string;
440 cellClassCallback: (row: any, col: GridColumn) => string;
441 defaultVisibleFields: string[];
442 defaultHiddenFields: string[];
443 overflowCells: boolean;
444 showLinkSelectors: boolean;
445 disablePaging: boolean;
447 // Allow calling code to know when the select-all-rows-in-page
448 // action has occurred.
449 selectRowsInPageEmitter: EventEmitter<void>;
451 // Services injected by our grid component
454 store: ServerStoreService;
455 format: FormatService;
460 store: ServerStoreService,
461 format: FormatService) {
466 this.format = format;
467 this.pager = new Pager();
468 this.rowSelector = new GridRowSelector();
469 this.toolbarButtons = [];
470 this.toolbarCheckboxes = [];
471 this.toolbarActions = [];
475 this.selectRowsInPageEmitter = new EventEmitter<void>();
476 this.columnSet = new GridColumnSet(this.idl, this.idlClass);
477 this.columnSet.isSortable = this.isSortable === true;
478 this.columnSet.isMultiSortable = this.isMultiSortable === true;
479 this.columnSet.defaultHiddenFields = this.defaultHiddenFields;
480 this.columnSet.defaultVisibleFields = this.defaultVisibleFields;
481 if (!this.pager.limit) {
482 this.pager.limit = this.disablePaging ? MAX_ALL_ROW_COUNT : 10;
484 this.generateColumns();
487 // Load initial settings and data.
489 this.applyGridConfig()
490 .then(ok => this.dataSource.requestPage(this.pager))
491 .then(ok => this.listenToPager());
498 applyGridConfig(): Promise<void> {
499 return this.getGridConfig(this.persistKey)
503 columns = conf.columns;
505 this.pager.limit = conf.limit;
509 // This is called regardless of the presence of saved
510 // settings so defaults can be applied.
511 this.columnSet.applyColumnSettings(columns);
516 // Give the UI time to settle before reloading grid data.
517 // This can help when data retrieval depends on a value
518 // getting modified by an angular digest cycle.
521 this.dataSource.reset();
522 this.dataSource.requestPage(this.pager);
526 // Sort the existing data source instead of requesting sorted
527 // data from the client. Reset pager to page 1. As with reload(),
528 // give the client a chance to setting before redisplaying.
532 this.sortLocalData();
533 this.dataSource.requestPage(this.pager);
537 // Subscribe or unsubscribe to page-change events from the pager.
539 if (this.pageChanges) { return; }
540 this.pageChanges = this.pager.onChange$.subscribe(
541 val => this.dataSource.requestPage(this.pager));
545 if (!this.pageChanges) { return; }
546 this.pageChanges.unsubscribe();
547 this.pageChanges = null;
550 // Sort data in the data source array
553 const sortDefs = this.dataSource.sort.map(sort => {
554 const column = this.columnSet.getColByName(sort.name);
562 if (!def.col.comparator) {
563 switch (def.col.datatype) {
567 def.col.comparator = (a, b) => {
570 if (a < b) { return -1; }
571 if (a > b) { return 1; }
576 def.col.comparator = (a, b) => {
577 if (a < b) { return -1; }
578 if (a > b) { return 1; }
587 this.dataSource.data.sort((rowA, rowB) => {
589 for (let idx = 0; idx < sortDefs.length; idx++) {
590 const sortDef = sortDefs[idx];
592 const valueA = this.getRowColumnValue(rowA, sortDef.col);
593 const valueB = this.getRowColumnValue(rowB, sortDef.col);
595 if (valueA === '' && valueB === '') { continue; }
596 if (valueA === '' && valueB !== '') { return 1; }
597 if (valueA !== '' && valueB === '') { return -1; }
599 const diff = sortDef.col.comparator(valueA, valueB);
600 if (diff === 0) { continue; }
602 return sortDef.dir === 'DESC' ? -diff : diff;
605 return 0; // No differences found.
609 getRowIndex(row: any): any {
610 const col = this.columnSet.indexColumn;
612 throw new Error('grid index column required');
614 return this.getRowColumnValue(row, col);
617 // Returns position in the data source array of the row with
618 // the provided index.
619 getRowPosition(index: any): number {
620 // for-loop for early exit
621 for (let idx = 0; idx < this.dataSource.data.length; idx++) {
622 const row = this.dataSource.data[idx];
623 if (row !== undefined && index === this.getRowIndex(row)) {
629 // Return the row with the provided index.
630 getRowByIndex(index: any): any {
631 for (let idx = 0; idx < this.dataSource.data.length; idx++) {
632 const row = this.dataSource.data[idx];
633 if (row !== undefined && index === this.getRowIndex(row)) {
639 // Returns all selected rows, regardless of whether they are
640 // currently visible in the grid display.
641 getSelectedRows(): any[] {
643 this.rowSelector.selected().forEach(index => {
644 const row = this.getRowByIndex(index);
652 getRowColumnValue(row: any, col: GridColumn): string {
656 val = this.nestedItemFieldValue(row, col);
657 } else if (col.name in row) {
658 val = this.getObjectFieldValue(row, col.name);
661 return this.format.transform({
663 idlClass: col.idlClass,
664 idlField: col.idlFieldDef ? col.idlFieldDef.name : col.name,
665 datatype: col.datatype,
666 datePlusTime: Boolean(col.datePlusTime)
670 getObjectFieldValue(obj: any, name: string): any {
671 if (typeof obj[name] === 'function') {
678 nestedItemFieldValue(obj: any, col: GridColumn): string {
682 const original = obj;
683 const steps = col.path.split('.');
685 for (let i = 0; i < steps.length; i++) {
686 const step = steps[i];
688 if (obj === null || obj === undefined || typeof obj !== 'object') {
689 // We have run out of data to step through before
690 // reaching the end of the path. Conclude fleshing via
691 // callback if provided then exit.
692 if (col.flesher && obj !== undefined) {
693 return col.flesher(obj, col, original);
698 const class_ = obj.classname;
699 if (class_ && (idlClassDef = this.idl.classes[class_])) {
700 idlField = idlClassDef.field_map[step];
703 obj = this.getObjectFieldValue(obj, step);
706 // We found a nested IDL object which may or may not have
707 // been configured as a top-level column. Flesh the column
708 // metadata with our newly found IDL info.
711 col.datatype = idlField.datatype;
713 if (!col.idlFieldDef) {
714 idlField = col.idlFieldDef;
717 col.idlClass = idlClassDef.name;
720 col.label = idlField.label || idlField.name;
728 getColumnTextContent(row: any, col: GridColumn): string {
729 if (col.cellTemplate) {
731 // Extract the text content from the rendered template.
733 return this.getRowColumnValue(row, col);
737 selectOneRow(index: any) {
738 this.rowSelector.clear();
739 this.rowSelector.select(index);
740 this.lastSelectedIndex = index;
743 selectMultipleRows(indexes: any[]) {
744 this.rowSelector.clear();
745 this.rowSelector.select(indexes);
746 this.lastSelectedIndex = indexes[indexes.length - 1];
749 // selects or deselects an item, without affecting the others.
750 // returns true if the item is selected; false if de-selected.
751 toggleSelectOneRow(index: any) {
752 if (this.rowSelector.contains(index)) {
753 this.rowSelector.deselect(index);
757 this.rowSelector.select(index);
761 selectRowByPos(pos: number) {
762 const row = this.dataSource.data[pos];
764 this.selectOneRow(this.getRowIndex(row));
768 selectPreviousRow() {
769 if (!this.lastSelectedIndex) { return; }
770 const pos = this.getRowPosition(this.lastSelectedIndex);
771 if (pos === this.pager.offset) {
772 this.toPrevPage().then(ok => this.selectLastRow(), err => {});
774 this.selectRowByPos(pos - 1);
779 if (!this.lastSelectedIndex) { return; }
780 const pos = this.getRowPosition(this.lastSelectedIndex);
781 if (pos === (this.pager.offset + this.pager.limit - 1)) {
782 this.toNextPage().then(ok => this.selectFirstRow(), err => {});
784 this.selectRowByPos(pos + 1);
789 // Select the previous row in addition to any currently selected row.
790 // However, if the previous row is already selected, assume the user
791 // has reversed direction and now wants to de-select the last selected row.
792 selectMultiRowsPrevious() {
793 if (!this.lastSelectedIndex) { return; }
794 const pos = this.getRowPosition(this.lastSelectedIndex);
795 const selectedIndexes = this.rowSelector.selected();
797 const promise = // load the previous page of data if needed
798 (pos === this.pager.offset) ? this.toPrevPage() : Promise.resolve();
802 const row = this.dataSource.data[pos - 1];
803 const newIndex = this.getRowIndex(row);
804 if (selectedIndexes.filter(i => i === newIndex).length > 0) {
805 // Prev row is already selected. User is reversing direction.
806 this.rowSelector.deselect(this.lastSelectedIndex);
807 this.lastSelectedIndex = newIndex;
809 this.selectMultipleRows(selectedIndexes.concat(newIndex));
817 // Select the next row in addition to any currently selected row.
818 // However, if the next row is already selected, assume the user
819 // has reversed direction and wants to de-select the last selected row.
820 selectMultiRowsNext() {
821 if (!this.lastSelectedIndex) { return; }
822 const pos = this.getRowPosition(this.lastSelectedIndex);
823 const selectedIndexes = this.rowSelector.selected();
825 const promise = // load the next page of data if needed
826 (pos === (this.pager.offset + this.pager.limit - 1)) ?
827 this.toNextPage() : Promise.resolve();
831 const row = this.dataSource.data[pos + 1];
832 const newIndex = this.getRowIndex(row);
833 if (selectedIndexes.filter(i => i === newIndex).length > 0) {
834 // Next row is already selected. User is reversing direction.
835 this.rowSelector.deselect(this.lastSelectedIndex);
836 this.lastSelectedIndex = newIndex;
838 this.selectMultipleRows(selectedIndexes.concat(newIndex));
845 getFirstRowInPage(): any {
846 return this.dataSource.data[this.pager.offset];
849 getLastRowInPage(): any {
850 return this.dataSource.data[this.pager.offset + this.pager.limit - 1];
854 this.selectOneRow(this.getRowIndex(this.getFirstRowInPage()));
858 this.selectOneRow(this.getRowIndex(this.getLastRowInPage()));
862 const rows = this.dataSource.getPageOfRows(this.pager);
863 const indexes = rows.map(r => this.getRowIndex(r));
864 this.rowSelector.select(indexes);
865 this.selectRowsInPageEmitter.emit();
868 toPrevPage(): Promise<any> {
869 if (this.pager.isFirstPage()) {
870 return Promise.reject('on first');
872 // temp ignore pager events since we're calling requestPage manually.
874 this.pager.decrement();
875 this.listenToPager();
876 return this.dataSource.requestPage(this.pager);
879 toNextPage(): Promise<any> {
880 if (this.pager.isLastPage()) {
881 return Promise.reject('on last');
883 // temp ignore pager events since we're calling requestPage manually.
885 this.pager.increment();
886 this.listenToPager();
887 return this.dataSource.requestPage(this.pager);
890 getAllRows(): Promise<any> {
891 const pager = new Pager();
893 pager.limit = MAX_ALL_ROW_COUNT;
894 return this.dataSource.requestPage(pager);
897 // Returns a key/value pair object of visible column data as text.
898 getRowAsFlatText(row: any): any {
900 this.columnSet.displayColumns().forEach(col => {
902 this.getColumnTextContent(row, col);
907 getAllRowsAsText(): Observable<any> {
908 return Observable.create(observer => {
909 this.getAllRows().then(ok => {
910 this.dataSource.data.forEach(row => {
911 observer.next(this.getRowAsFlatText(row));
918 gridToCsv(): Promise<string> {
921 const columns = this.columnSet.displayColumns();
924 columns.forEach(col => {
925 csvStr += this.valueToCsv(col.label),
929 csvStr = csvStr.replace(/,$/, '\n');
931 return new Promise(resolve => {
932 this.getAllRowsAsText().subscribe(
934 columns.forEach(col => {
935 csvStr += this.valueToCsv(row[col.name]);
938 csvStr = csvStr.replace(/,$/, '\n');
941 () => resolve(csvStr)
947 // prepares a string for inclusion within a CSV document
948 // by escaping commas and quotes and removing newlines.
949 valueToCsv(str: string): string {
951 if (!str) { return ''; }
952 str = str.replace(/\n/g, '');
953 if (str.match(/\,/) || str.match(/"/)) {
954 str = str.replace(/"/g, '""');
955 str = '"' + str + '"';
961 if (!this.columnSet.idlClass) { return; }
963 const pkeyField = this.idl.classes[this.columnSet.idlClass].pkey;
965 // generate columns for all non-virtual fields on the IDL class
966 this.idl.classes[this.columnSet.idlClass].fields
967 .filter(field => !field.virtual)
969 const col = new GridColumn();
970 col.name = field.name;
971 col.label = field.label || field.name;
972 col.idlFieldDef = field;
973 col.idlClass = this.columnSet.idlClass;
974 col.datatype = field.datatype;
975 col.isIndex = (field.name === pkeyField);
978 if (this.showLinkSelectors) {
979 const selector = this.idl.getLinkSelector(
980 this.columnSet.idlClass, field.name);
982 col.path = field.name + '.' + selector;
986 this.columnSet.add(col);
990 saveGridConfig(): Promise<any> {
991 if (!this.persistKey) {
992 throw new Error('Grid persistKey required to save columns');
994 const conf = new GridPersistConf();
996 conf.limit = this.pager.limit;
997 conf.columns = this.columnSet.compileSaveObject();
999 return this.store.setItem('eg.grid.' + this.persistKey, conf);
1002 // TODO: saveGridConfigAsOrgSetting(...)
1004 getGridConfig(persistKey: string): Promise<GridPersistConf> {
1005 if (!persistKey) { return Promise.resolve(null); }
1006 return this.store.getItem('eg.grid.' + persistKey);
1011 // Actions apply to specific rows
1012 export class GridToolbarAction {
1014 onClick: EventEmitter<any []>;
1015 action: (rows: any[]) => any; // DEPRECATED
1017 isGroup: boolean; // used for group placeholder entries
1018 disableOnRows: (rows: any[]) => boolean;
1021 // Buttons are global actions
1022 export class GridToolbarButton {
1024 onClick: EventEmitter<any []>;
1025 action: () => any; // DEPRECATED
1029 export class GridToolbarCheckbox {
1032 onChange: EventEmitter<boolean>;
1035 export class GridDataSource {
1039 allRowsRetrieved: boolean;
1040 requestingData: boolean;
1041 getRows: (pager: Pager, sort: any[]) => Observable<any>;
1050 this.allRowsRetrieved = false;
1053 // called from the template -- no data fetching
1054 getPageOfRows(pager: Pager): any[] {
1056 return this.data.slice(
1057 pager.offset, pager.limit + pager.offset
1058 ).filter(row => row !== undefined);
1063 // called on initial component load and user action (e.g. paging, sorting).
1064 requestPage(pager: Pager): Promise<any> {
1067 this.getPageOfRows(pager).length === pager.limit
1068 // already have all data
1069 || this.allRowsRetrieved
1070 // have no way to get more data.
1073 return Promise.resolve();
1076 // If we have to call out for data, set inFetch
1077 this.requestingData = true;
1079 return new Promise((resolve, reject) => {
1080 let idx = pager.offset;
1081 return this.getRows(pager, this.sort).subscribe(
1083 this.data[idx++] = row;
1084 this.requestingData = false;
1087 console.error(`grid getRows() error ${err}`);
1091 this.checkAllRetrieved(pager, idx);
1092 this.requestingData = false;
1099 // See if the last getRows() call resulted in the final set of data.
1100 checkAllRetrieved(pager: Pager, idx: number) {
1101 if (this.allRowsRetrieved) { return; }
1103 if (idx === 0 || idx < (pager.limit + pager.offset)) {
1104 // last query returned nothing or less than one page.
1105 // confirm we have all of the preceding pages.
1106 if (!this.data.includes(undefined)) {
1107 this.allRowsRetrieved = true;
1108 pager.resultCount = this.data.length;