проблема с отредактированными данными PrimeNg P-таблицы и изменение страницы с помощью нумерации страниц. Способ уведомить пользователя о необходимости сохранения данных? - PullRequest
0 голосов
/ 23 октября 2019
/*here is my pTable HTML code */
    <p-table #pcd [columns]="pcdTableColumns" [value]="pcdDictionaries" [lazy]="true" (onLazyLoad)="loadPcdDictionariesLazy($event)"
                [paginator]="true" [rows]="noOfRowsPcd" [ngClass]="{'ui-state-disabled': disablePaginator}" [multiSortMeta]="multiSortMeta" sortMode="multiple" [totalRecords]="pcdTotalRecords"
                [loading]="pcdLoading" [rowsPerPageOptions]="[25,50,75,100]"> <ng-template pTemplate="header" let-columns>
            <tr>
                <th *ngFor="let col of columns" [pSortableColumn]="col.field">{{col.header | translate}} <span> <p-sortIcon
                            [field]="col.field"></p-sortIcon>
                </span>
                </th>
                <th [pSortableColumn]="'userControl'">{{'Under Control' | translate}} <span> <p-sortIcon [field]="'userControl'"></p-sortIcon>
                </span>
                </th>
            </tr>
            </ng-template> <ng-template pTemplate="body" let-rowData let-columns="columns">
            <tr>
                <td *ngFor="let col of columns">
                    <div *ngIf="col.field === 'bcvUsage'">
                        <div *ngIf="rowData[col.field] === 1;else not_bcv_usage">Y</div>
                        <ng-template #not_bcv_usage>N</ng-template>
                    </div>
                    <div *ngIf="col.field !== 'bcvUsage'" style="word-wrap: break-word;">{{rowData[col.field]}}</div>

                </td>
                <td><p-inputSwitch [(ngModel)]="rowData.checked" (onChange)="onPcdDictionaryChange(rowData)"> </p-inputSwitch></td>
            </tr>
            </ng-template> </p-table>

/* here is my angular code for p-table lay-load */
      loadPcdDictionariesLazy(event: LazyLoadEvent) {
        if(this.IsSaveData){
          console.log("load table data");
          this.first = event.first;
          this.noOfRowsPcd = event.rows;
          if (event.multiSortMeta) {
            this.pcdSortField = event.multiSortMeta[0].field;
            this.pcdSortOrder = event.multiSortMeta[0].order;
          }
          this.displayPcdDictionary(false, event.first);
        } else {
          console.log("Show popup");
          this.confirmationService.confirm({
            message: 'Do you want to go without saving changes',
            header: 'Confirmation',
            icon: 'pi pi-exclamation-triangle',
            accept: () => {
              this.IsUserControl = false;
              this.IsSaveData = true;
              this.first = event.first;
              this.noOfRowsPcd = event.rows;
              if (event.multiSortMeta) {
                this.pcdSortField = event.multiSortMeta[0].field;
                this.pcdSortOrder = event.multiSortMeta[0].order;
              }
              this.displayPcdDictionary(false, event.first);
            },
            reject: () => {
              let pageIndex = event.first/event.rows + 1;
              this.IsUserControl = true;
              this.IsSaveData = false;
            }
          });
        }

/ разбиение на страницы или не загружать данные следующей страницы, пока данные не сохраняются на текущей странице ?? если вы меняете страницу, то без сохранения нужных мне данных отображается всплывающее окно. /

...