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;
30 cellTemplate: TemplateRef<any>;
33 isDragTarget: boolean;
35 isMultiSortable: boolean;
36 disableTooltip: boolean;
37 comparator: (valueA: any, valueB: any) => number;
39 // True if the column was automatically generated.
42 flesher: (obj: any, col: GridColumn, item: any) => any;
44 getCellContext(row: any) {
48 userContext: this.cellContext
53 export class GridColumnSet {
54 columns: GridColumn[];
56 indexColumn: GridColumn;
58 isMultiSortable: boolean;
59 stockVisible: string[];
61 defaultHiddenFields: string[];
62 defaultVisibleFields: string[];
64 constructor(idl: IdlService, idlClass?: string) {
67 this.stockVisible = [];
68 this.idlClass = idlClass;
71 add(col: GridColumn) {
73 this.applyColumnDefaults(col);
75 if (!this.insertColumn(col)) {
76 // Column was rejected as a duplicate.
80 if (col.isIndex) { this.indexColumn = col; }
82 // track which fields are visible on page load.
84 this.stockVisible.push(col.name);
87 this.applyColumnSortability(col);
90 // Returns true if the new column was inserted, false otherwise.
91 // Declared columns take precedence over auto-generated columns
92 // when collisions occur.
93 // Declared columns are inserted in front of auto columns.
94 insertColumn(col: GridColumn): boolean {
97 if (this.getColByName(col.name)) {
98 // New auto-generated column conflicts with existing
102 // No collisions. Add to the end of the list
103 this.columns.push(col);
108 // Adding a declared column.
111 for (let idx = 0; idx < this.columns.length; idx++) {
112 const testCol = this.columns[idx];
113 if (testCol.name === col.name) { // match found
114 if (testCol.isAuto) {
115 // new column takes precedence, remove the existing column.
116 this.columns.splice(idx, 1);
119 // New column does not take precedence. Avoid
126 // Delcared columns are inserted just before the first auto-column
127 for (let idx = 0; idx < this.columns.length; idx++) {
128 const testCol = this.columns[idx];
129 if (testCol.isAuto) {
131 this.columns.unshift(col);
133 this.columns.splice(idx - 1, 0, col);
139 // No insertion point found. Toss the new column on the end.
140 this.columns.push(col);
144 getColByName(name: string): GridColumn {
145 return this.columns.filter(c => c.name === name)[0];
148 idlInfoFromDotpath(dotpath: string): any {
149 if (!dotpath || !this.idlClass) { return null; }
153 let idlClass = this.idl.classes[this.idlClass];
155 const pathParts = dotpath.split(/\./);
157 for (let i = 0; i < pathParts.length; i++) {
158 const part = pathParts[i];
159 idlParent = idlField;
160 idlField = idlClass.field_map[part];
163 if (idlField['class'] && (
164 idlField.datatype === 'link' ||
165 idlField.datatype === 'org_unit')) {
166 idlClass = this.idl.classes[idlField['class']];
174 idlParent: idlParent,
182 this.columns.forEach(col => {
186 col.visible = this.stockVisible.includes(col.name);
190 applyColumnDefaults(col: GridColumn) {
192 if (!col.idlFieldDef && col.path) {
193 const idlInfo = this.idlInfoFromDotpath(col.path);
195 col.idlFieldDef = idlInfo.idlField;
196 col.idlClass = idlInfo.idlClass.name;
198 col.label = col.idlFieldDef.label || col.idlFieldDef.name;
199 col.datatype = col.idlFieldDef.datatype;
204 if (!col.name) { col.name = col.path; }
205 if (!col.flex) { col.flex = 2; }
206 if (!col.align) { col.align = 'left'; }
207 if (!col.label) { col.label = col.name; }
208 if (!col.datatype) { col.datatype = 'text'; }
210 col.visible = !col.hidden;
213 applyColumnSortability(col: GridColumn) {
214 // column sortability defaults to the sortability of the column set.
215 if (col.isSortable === undefined && this.isSortable) {
216 col.isSortable = true;
219 if (col.isMultiSortable === undefined && this.isMultiSortable) {
220 col.isMultiSortable = true;
223 if (col.isMultiSortable) {
224 col.isSortable = true;
228 displayColumns(): GridColumn[] {
229 return this.columns.filter(c => c.visible);
232 insertBefore(source: GridColumn, target: GridColumn) {
235 this.columns.forEach((col, idx) => {
236 if (col.name === target.name) { targetIdx = idx; }});
238 this.columns.forEach((col, idx) => {
239 if (col.name === source.name) { sourceIdx = idx; }});
241 if (sourceIdx >= 0) {
242 this.columns.splice(sourceIdx, 1);
245 this.columns.splice(targetIdx, 0, source);
248 // Move visible columns to the front of the list.
249 moveVisibleToFront() {
250 const newCols = this.displayColumns();
251 this.columns.forEach(col => {
252 if (!col.visible) { newCols.push(col); }});
253 this.columns = newCols;
256 moveColumn(col: GridColumn, diff: number) {
257 let srcIdx, targetIdx;
259 this.columns.forEach((c, i) => {
260 if (c.name === col.name) { srcIdx = i; }
263 targetIdx = srcIdx + diff;
266 } else if (targetIdx >= this.columns.length) {
267 // Target index follows the last visible column.
269 this.columns.forEach((c, idx) => {
270 if (c.visible) { lastVisible = idx; }
273 // When moving a column (down) causes one or more
274 // visible columns to shuffle forward, our column
275 // moves into the slot of the last visible column.
276 // Otherwise, put it into the slot directly following
277 // the last visible column.
278 targetIdx = srcIdx <= lastVisible ? lastVisible : lastVisible + 1;
281 // Splice column out of old position, insert at new position.
282 this.columns.splice(srcIdx, 1);
283 this.columns.splice(targetIdx, 0, col);
286 compileSaveObject(): GridColumnPersistConf[] {
287 // only store information about visible columns.
288 // scrunch the data down to just the needed info.
289 return this.displayColumns().map(col => {
290 const c: GridColumnPersistConf = {name : col.name};
291 if (col.align !== 'left') { c.align = col.align; }
292 if (col.flex !== 2) { c.flex = Number(col.flex); }
293 if (Number(col.sort)) { c.sort = Number(c.sort); }
298 applyColumnSettings(conf: GridColumnPersistConf[]) {
300 if (!conf || conf.length === 0) {
301 // No configuration is available, but we have a list of
302 // fields to show or hide by default
304 if (this.defaultVisibleFields) {
305 this.columns.forEach(col => {
306 if (this.defaultVisibleFields.includes(col.name)) {
313 } else if (this.defaultHiddenFields) {
314 this.defaultHiddenFields.forEach(name => {
315 const col = this.getColByName(name);
327 conf.forEach(colConf => {
328 const col = this.getColByName(colConf.name);
329 if (!col) { return; } // no such column in this grid.
332 if (colConf.align) { col.align = colConf.align; }
333 if (colConf.flex) { col.flex = Number(colConf.flex); }
334 if (colConf.sort) { col.sort = Number(colConf.sort); }
336 // Add to new columns array, avoid dupes.
337 if (newCols.filter(c => c.name === col.name).length === 0) {
342 // columns which are not expressed within the saved
343 // configuration are marked as non-visible and
344 // appended to the end of the new list of columns.
345 this.columns.forEach(c => {
346 if (conf.filter(cf => cf.name === c.name).length === 0) {
352 this.columns = newCols;
357 export class GridRowSelector {
358 indexes: {[string: string]: boolean};
364 // Returns true if all of the requested indexes exist in the selector.
365 contains(index: string | string[]): boolean {
366 const indexes = [].concat(index);
367 for (let i = 0; i < indexes.length; i++) { // early exit
368 if (!this.indexes[indexes[i]]) {
375 select(index: string | string[]) {
376 const indexes = [].concat(index);
377 indexes.forEach(i => this.indexes[i] = true);
380 deselect(index: string | string[]) {
381 const indexes = [].concat(index);
382 indexes.forEach(i => delete this.indexes[i]);
385 // Returns the list of selected index values.
386 // in some contexts (template checkboxes) the value for an index is
387 // set to false to deselect instead of having it removed (via deselect()).
389 return Object.keys(this.indexes).filter(
390 ind => Boolean(this.indexes[ind]));
394 return this.selected().length === 0;
402 export interface GridRowFlairEntry {
403 icon: string; // name of material icon
404 title?: string; // tooltip string
407 export class GridColumnPersistConf {
414 export class GridPersistConf {
417 columns: GridColumnPersistConf[];
420 export class GridContext {
425 isMultiSortable: boolean;
426 useLocalSort: boolean;
428 disableMultiSelect: boolean;
429 disableSelect: boolean;
430 dataSource: GridDataSource;
431 columnSet: GridColumnSet;
432 rowSelector: GridRowSelector;
433 toolbarButtons: GridToolbarButton[];
434 toolbarCheckboxes: GridToolbarCheckbox[];
435 toolbarActions: GridToolbarAction[];
436 lastSelectedIndex: any;
437 pageChanges: Subscription;
438 rowFlairIsEnabled: boolean;
439 rowFlairCallback: (row: any) => GridRowFlairEntry;
440 rowClassCallback: (row: any) => string;
441 cellClassCallback: (row: any, col: GridColumn) => string;
442 defaultVisibleFields: string[];
443 defaultHiddenFields: string[];
444 overflowCells: boolean;
445 showLinkSelectors: boolean;
446 disablePaging: boolean;
448 // Allow calling code to know when the select-all-rows-in-page
449 // action has occurred.
450 selectRowsInPageEmitter: EventEmitter<void>;
452 // Services injected by our grid component
455 store: ServerStoreService;
456 format: FormatService;
461 store: ServerStoreService,
462 format: FormatService) {
467 this.format = format;
468 this.pager = new Pager();
469 this.rowSelector = new GridRowSelector();
470 this.toolbarButtons = [];
471 this.toolbarCheckboxes = [];
472 this.toolbarActions = [];
476 this.selectRowsInPageEmitter = new EventEmitter<void>();
477 this.columnSet = new GridColumnSet(this.idl, this.idlClass);
478 this.columnSet.isSortable = this.isSortable === true;
479 this.columnSet.isMultiSortable = this.isMultiSortable === true;
480 this.columnSet.defaultHiddenFields = this.defaultHiddenFields;
481 this.columnSet.defaultVisibleFields = this.defaultVisibleFields;
482 if (!this.pager.limit) {
483 this.pager.limit = this.disablePaging ? MAX_ALL_ROW_COUNT : 10;
485 this.generateColumns();
488 // Load initial settings and data.
490 this.applyGridConfig()
491 .then(ok => this.dataSource.requestPage(this.pager))
492 .then(ok => this.listenToPager());
499 applyGridConfig(): Promise<void> {
500 return this.getGridConfig(this.persistKey)
504 columns = conf.columns;
506 this.pager.limit = conf.limit;
510 // This is called regardless of the presence of saved
511 // settings so defaults can be applied.
512 this.columnSet.applyColumnSettings(columns);
517 // Give the UI time to settle before reloading grid data.
518 // This can help when data retrieval depends on a value
519 // getting modified by an angular digest cycle.
522 this.dataSource.reset();
523 this.dataSource.requestPage(this.pager);
527 // Sort the existing data source instead of requesting sorted
528 // data from the client. Reset pager to page 1. As with reload(),
529 // give the client a chance to setting before redisplaying.
533 this.sortLocalData();
534 this.dataSource.requestPage(this.pager);
538 // Subscribe or unsubscribe to page-change events from the pager.
540 if (this.pageChanges) { return; }
541 this.pageChanges = this.pager.onChange$.subscribe(
542 val => this.dataSource.requestPage(this.pager));
546 if (!this.pageChanges) { return; }
547 this.pageChanges.unsubscribe();
548 this.pageChanges = null;
551 // Sort data in the data source array
554 const sortDefs = this.dataSource.sort.map(sort => {
555 const column = this.columnSet.getColByName(sort.name);
563 if (!def.col.comparator) {
564 switch (def.col.datatype) {
568 def.col.comparator = (a, b) => {
571 if (a < b) { return -1; }
572 if (a > b) { return 1; }
577 def.col.comparator = (a, b) => {
578 if (a < b) { return -1; }
579 if (a > b) { return 1; }
588 this.dataSource.data.sort((rowA, rowB) => {
590 for (let idx = 0; idx < sortDefs.length; idx++) {
591 const sortDef = sortDefs[idx];
593 const valueA = this.getRowColumnValue(rowA, sortDef.col);
594 const valueB = this.getRowColumnValue(rowB, sortDef.col);
596 if (valueA === '' && valueB === '') { continue; }
597 if (valueA === '' && valueB !== '') { return 1; }
598 if (valueA !== '' && valueB === '') { return -1; }
600 const diff = sortDef.col.comparator(valueA, valueB);
601 if (diff === 0) { continue; }
603 return sortDef.dir === 'DESC' ? -diff : diff;
606 return 0; // No differences found.
610 getRowIndex(row: any): any {
611 const col = this.columnSet.indexColumn;
613 throw new Error('grid index column required');
615 return this.getRowColumnValue(row, col);
618 // Returns position in the data source array of the row with
619 // the provided index.
620 getRowPosition(index: any): number {
621 // for-loop for early exit
622 for (let idx = 0; idx < this.dataSource.data.length; idx++) {
623 const row = this.dataSource.data[idx];
624 if (row !== undefined && index === this.getRowIndex(row)) {
630 // Return the row with the provided index.
631 getRowByIndex(index: any): any {
632 for (let idx = 0; idx < this.dataSource.data.length; idx++) {
633 const row = this.dataSource.data[idx];
634 if (row !== undefined && index === this.getRowIndex(row)) {
640 // Returns all selected rows, regardless of whether they are
641 // currently visible in the grid display.
642 getSelectedRows(): any[] {
644 this.rowSelector.selected().forEach(index => {
645 const row = this.getRowByIndex(index);
653 getRowColumnValue(row: any, col: GridColumn): string {
657 val = this.nestedItemFieldValue(row, col);
658 } else if (col.name in row) {
659 val = this.getObjectFieldValue(row, col.name);
662 if (col.datatype === 'bool') {
663 // Avoid string-ifying bools so we can use an <eg-bool/>
664 // in the grid template.
668 return this.format.transform({
670 idlClass: col.idlClass,
671 idlField: col.idlFieldDef ? col.idlFieldDef.name : col.name,
672 datatype: col.datatype,
673 datePlusTime: Boolean(col.datePlusTime)
677 getObjectFieldValue(obj: any, name: string): any {
678 if (typeof obj[name] === 'function') {
685 nestedItemFieldValue(obj: any, col: GridColumn): string {
689 const original = obj;
690 const steps = col.path.split('.');
692 for (let i = 0; i < steps.length; i++) {
693 const step = steps[i];
695 if (obj === null || obj === undefined || typeof obj !== 'object') {
696 // We have run out of data to step through before
697 // reaching the end of the path. Conclude fleshing via
698 // callback if provided then exit.
699 if (col.flesher && obj !== undefined) {
700 return col.flesher(obj, col, original);
705 const class_ = obj.classname;
706 if (class_ && (idlClassDef = this.idl.classes[class_])) {
707 idlField = idlClassDef.field_map[step];
710 obj = this.getObjectFieldValue(obj, step);
713 // We found a nested IDL object which may or may not have
714 // been configured as a top-level column. Flesh the column
715 // metadata with our newly found IDL info.
718 col.datatype = idlField.datatype;
720 if (!col.idlFieldDef) {
721 idlField = col.idlFieldDef;
724 col.idlClass = idlClassDef.name;
727 col.label = idlField.label || idlField.name;
735 getColumnTextContent(row: any, col: GridColumn): string {
736 if (col.cellTemplate) {
738 // Extract the text content from the rendered template.
740 return this.getRowColumnValue(row, col);
744 selectOneRow(index: any) {
745 this.rowSelector.clear();
746 this.rowSelector.select(index);
747 this.lastSelectedIndex = index;
750 selectMultipleRows(indexes: any[]) {
751 this.rowSelector.clear();
752 this.rowSelector.select(indexes);
753 this.lastSelectedIndex = indexes[indexes.length - 1];
756 // selects or deselects an item, without affecting the others.
757 // returns true if the item is selected; false if de-selected.
758 toggleSelectOneRow(index: any) {
759 if (this.rowSelector.contains(index)) {
760 this.rowSelector.deselect(index);
764 this.rowSelector.select(index);
768 selectRowByPos(pos: number) {
769 const row = this.dataSource.data[pos];
771 this.selectOneRow(this.getRowIndex(row));
775 selectPreviousRow() {
776 if (!this.lastSelectedIndex) { return; }
777 const pos = this.getRowPosition(this.lastSelectedIndex);
778 if (pos === this.pager.offset) {
779 this.toPrevPage().then(ok => this.selectLastRow(), err => {});
781 this.selectRowByPos(pos - 1);
786 if (!this.lastSelectedIndex) { return; }
787 const pos = this.getRowPosition(this.lastSelectedIndex);
788 if (pos === (this.pager.offset + this.pager.limit - 1)) {
789 this.toNextPage().then(ok => this.selectFirstRow(), err => {});
791 this.selectRowByPos(pos + 1);
796 // Select the previous row in addition to any currently selected row.
797 // However, if the previous row is already selected, assume the user
798 // has reversed direction and now wants to de-select the last selected row.
799 selectMultiRowsPrevious() {
800 if (!this.lastSelectedIndex) { return; }
801 const pos = this.getRowPosition(this.lastSelectedIndex);
802 const selectedIndexes = this.rowSelector.selected();
804 const promise = // load the previous page of data if needed
805 (pos === this.pager.offset) ? this.toPrevPage() : Promise.resolve();
809 const row = this.dataSource.data[pos - 1];
810 const newIndex = this.getRowIndex(row);
811 if (selectedIndexes.filter(i => i === newIndex).length > 0) {
812 // Prev row is already selected. User is reversing direction.
813 this.rowSelector.deselect(this.lastSelectedIndex);
814 this.lastSelectedIndex = newIndex;
816 this.selectMultipleRows(selectedIndexes.concat(newIndex));
824 // Select the next row in addition to any currently selected row.
825 // However, if the next row is already selected, assume the user
826 // has reversed direction and wants to de-select the last selected row.
827 selectMultiRowsNext() {
828 if (!this.lastSelectedIndex) { return; }
829 const pos = this.getRowPosition(this.lastSelectedIndex);
830 const selectedIndexes = this.rowSelector.selected();
832 const promise = // load the next page of data if needed
833 (pos === (this.pager.offset + this.pager.limit - 1)) ?
834 this.toNextPage() : Promise.resolve();
838 const row = this.dataSource.data[pos + 1];
839 const newIndex = this.getRowIndex(row);
840 if (selectedIndexes.filter(i => i === newIndex).length > 0) {
841 // Next row is already selected. User is reversing direction.
842 this.rowSelector.deselect(this.lastSelectedIndex);
843 this.lastSelectedIndex = newIndex;
845 this.selectMultipleRows(selectedIndexes.concat(newIndex));
852 getFirstRowInPage(): any {
853 return this.dataSource.data[this.pager.offset];
856 getLastRowInPage(): any {
857 return this.dataSource.data[this.pager.offset + this.pager.limit - 1];
861 this.selectOneRow(this.getRowIndex(this.getFirstRowInPage()));
865 this.selectOneRow(this.getRowIndex(this.getLastRowInPage()));
869 const rows = this.dataSource.getPageOfRows(this.pager);
870 const indexes = rows.map(r => this.getRowIndex(r));
871 this.rowSelector.select(indexes);
872 this.selectRowsInPageEmitter.emit();
875 toPrevPage(): Promise<any> {
876 if (this.pager.isFirstPage()) {
877 return Promise.reject('on first');
879 // temp ignore pager events since we're calling requestPage manually.
881 this.pager.decrement();
882 this.listenToPager();
883 return this.dataSource.requestPage(this.pager);
886 toNextPage(): Promise<any> {
887 if (this.pager.isLastPage()) {
888 return Promise.reject('on last');
890 // temp ignore pager events since we're calling requestPage manually.
892 this.pager.increment();
893 this.listenToPager();
894 return this.dataSource.requestPage(this.pager);
897 getAllRows(): Promise<any> {
898 const pager = new Pager();
900 pager.limit = MAX_ALL_ROW_COUNT;
901 return this.dataSource.requestPage(pager);
904 // Returns a key/value pair object of visible column data as text.
905 getRowAsFlatText(row: any): any {
907 this.columnSet.displayColumns().forEach(col => {
909 this.getColumnTextContent(row, col);
914 getAllRowsAsText(): Observable<any> {
915 return Observable.create(observer => {
916 this.getAllRows().then(ok => {
917 this.dataSource.data.forEach(row => {
918 observer.next(this.getRowAsFlatText(row));
925 gridToCsv(): Promise<string> {
928 const columns = this.columnSet.displayColumns();
931 columns.forEach(col => {
932 csvStr += this.valueToCsv(col.label),
936 csvStr = csvStr.replace(/,$/, '\n');
938 return new Promise(resolve => {
939 this.getAllRowsAsText().subscribe(
941 columns.forEach(col => {
942 csvStr += this.valueToCsv(row[col.name]);
945 csvStr = csvStr.replace(/,$/, '\n');
948 () => resolve(csvStr)
954 // prepares a string for inclusion within a CSV document
955 // by escaping commas and quotes and removing newlines.
956 valueToCsv(str: string): string {
958 if (!str) { return ''; }
959 str = str.replace(/\n/g, '');
960 if (str.match(/\,/) || str.match(/"/)) {
961 str = str.replace(/"/g, '""');
962 str = '"' + str + '"';
968 if (!this.columnSet.idlClass) { return; }
970 const pkeyField = this.idl.classes[this.columnSet.idlClass].pkey;
972 // generate columns for all non-virtual fields on the IDL class
973 this.idl.classes[this.columnSet.idlClass].fields
974 .filter(field => !field.virtual)
976 const col = new GridColumn();
977 col.name = field.name;
978 col.label = field.label || field.name;
979 col.idlFieldDef = field;
980 col.idlClass = this.columnSet.idlClass;
981 col.datatype = field.datatype;
982 col.isIndex = (field.name === pkeyField);
985 if (this.showLinkSelectors) {
986 const selector = this.idl.getLinkSelector(
987 this.columnSet.idlClass, field.name);
989 col.path = field.name + '.' + selector;
993 this.columnSet.add(col);
997 saveGridConfig(): Promise<any> {
998 if (!this.persistKey) {
999 throw new Error('Grid persistKey required to save columns');
1001 const conf = new GridPersistConf();
1003 conf.limit = this.pager.limit;
1004 conf.columns = this.columnSet.compileSaveObject();
1006 return this.store.setItem('eg.grid.' + this.persistKey, conf);
1009 // TODO: saveGridConfigAsOrgSetting(...)
1011 getGridConfig(persistKey: string): Promise<GridPersistConf> {
1012 if (!persistKey) { return Promise.resolve(null); }
1013 return this.store.getItem('eg.grid.' + persistKey);
1018 // Actions apply to specific rows
1019 export class GridToolbarAction {
1021 onClick: EventEmitter<any []>;
1022 action: (rows: any[]) => any; // DEPRECATED
1024 isGroup: boolean; // used for group placeholder entries
1025 disableOnRows: (rows: any[]) => boolean;
1028 // Buttons are global actions
1029 export class GridToolbarButton {
1031 onClick: EventEmitter<any []>;
1032 action: () => any; // DEPRECATED
1036 export class GridToolbarCheckbox {
1039 onChange: EventEmitter<boolean>;
1042 export class GridDataSource {
1046 allRowsRetrieved: boolean;
1047 requestingData: boolean;
1048 getRows: (pager: Pager, sort: any[]) => Observable<any>;
1057 this.allRowsRetrieved = false;
1060 // called from the template -- no data fetching
1061 getPageOfRows(pager: Pager): any[] {
1063 return this.data.slice(
1064 pager.offset, pager.limit + pager.offset
1065 ).filter(row => row !== undefined);
1070 // called on initial component load and user action (e.g. paging, sorting).
1071 requestPage(pager: Pager): Promise<any> {
1074 this.getPageOfRows(pager).length === pager.limit
1075 // already have all data
1076 || this.allRowsRetrieved
1077 // have no way to get more data.
1080 return Promise.resolve();
1083 // If we have to call out for data, set inFetch
1084 this.requestingData = true;
1086 return new Promise((resolve, reject) => {
1087 let idx = pager.offset;
1088 return this.getRows(pager, this.sort).subscribe(
1090 this.data[idx++] = row;
1091 this.requestingData = false;
1094 console.error(`grid getRows() error ${err}`);
1098 this.checkAllRetrieved(pager, idx);
1099 this.requestingData = false;
1106 // See if the last getRows() call resulted in the final set of data.
1107 checkAllRetrieved(pager: Pager, idx: number) {
1108 if (this.allRowsRetrieved) { return; }
1110 if (idx === 0 || idx < (pager.limit + pager.offset)) {
1111 // last query returned nothing or less than one page.
1112 // confirm we have all of the preceding pages.
1113 if (!this.data.includes(undefined)) {
1114 this.allRowsRetrieved = true;
1115 pager.resultCount = this.data.length;