Turbo Table with Checkbox - PrimeNG

0

Hello, I'm using TypeScript, Angular 5, PrimeNG and Java for ERP system development. My front has a screen so that the user can choose the days of operation of the establishment. This screen has a turbo table and one of the columns is a checkbox informing if that day is checked or not (open or closed, in practice). But here begins the problem ... I made the turbo table configuration as specified in the documentation but all the checkboxes return marked when loading the data or after some changes that I made for tests the checkboxes do not appear at first but if I click on the line it appears but the checkbox only appears after clicking on your row / column. I would like that if someone can give a light, when loading the data of the back end the checkboxes come with the values marked or not, depending on the data loaded. Even if I check or uncheck a checkbox the values are being changed correctly, but their initial display is not correct ... Here are some data to help:

HTML - Only the table

<p-table [value]="dias" [responsive]="true">
    <ng-template pTemplate="header" let-columns>
        <tr>
            <th class="col-codigo" scope="col">Aberto?</th>
            <th class="col-codigo" scope="col">Código</th>
            <th scope="col">Dia Semana</th>
            <th scope="col">Hora Abertura</th>
            <th scope="col">Hora Fechamento</th>
        </tr>
    </ng-template>
    <ng-template pTemplate="body" let-dia>
        <tr>
            <td>
                  <p-checkbox [(ngModel)]="dia.opt_Funcionamento" [value]="dia.opt_Funcionamento"
                    binary="false" name="funcionamento" (onclick)="!dia.opt_Funcionamento"></p-checkbox>
                    </td>
          <td scope="row">
            {{dia.cd_Funcionamento}}
          </td>
          <td scope="row">
            {{dia.dia}}
          </td>
          <td pEditableColumn scope="row">
              <p-cellEditor>
                  <ng-template pTemplate="input">
                      <p-calendar [(ngModel)]="dia.hr_Abertura" [timeOnly]="true" name="horaAbertura" [showSeconds]="true" dataType="string"></p-calendar>
                  </ng-template>
                  <ng-template pTemplate="output">
                      {{dia.hr_Abertura}}
                  </ng-template>
              </p-cellEditor>
          </td>
          <td pEditableColumn scope="row">
              <p-cellEditor>
                  <ng-template pTemplate="input">
                      <p-calendar [(ngModel)]="dia.hr_Fechamento" [timeOnly]="true" name="horaFechamento" [showSeconds]="true" dataType="string"></p-calendar>
                  </ng-template>
                  <ng-template pTemplate="output">
                      {{dia.hr_Fechamento}}
                  </ng-template>
              </p-cellEditor>
          </td>
      </tr>
    </ng-template>
  </p-table>

Component.ts

  export class FuncionamentoEstabelecimentoCadastroComponent {
  @Input () displayValue: string;
  funcionamentoEstabelecimento = new FuncionamentoEstabelecimento();
  dias: FuncionamentoEstabelecimento[];
  aberto = false;
  diaSelecionado: FuncionamentoEstabelecimento;

  constructor(
    ...
  ) { }

  ngOnInit() {
    this.tituloPagina.setTitle('Dias de funcionamento do estabelecimento');
    const codigoFuncionamento = this.rota.snapshot.params['codigo'];
    this.carregaDiasFuncionamento();
}

carregaDiasFuncionamento() {
    this.funcionamentoService.carregaDiasFuncionamento()
      .then(funcionamentoDados => {
        this.dias = funcionamentoDados;
      })
      .catch(erro => this.errorHandler.handle(erro));
  }

Model

export class FuncionamentoEstabelecimento {
  cd_Funcionamento: number;
  dia: string;
  opt_Funcionamento = false;
  hr_Abertura: Time;
  hr_Fechamento: Time;

}

EDIT: I was able to solve the problem. I used the span for the solution. Following:

<td style="text-align: center" scope="row">
                <span *ngIf="rowData.opt_Funcionamento">
                    <p-selectButton [options]="aberto" [(ngModel)]="rowData.opt_Funcionamento"
                      (onOptionClick)="!rowData.opt_Funcionamento" name="diaAberto"
                      pTooltip="Aberto" tooltipPosition="top"></p-selectButton>
                </span>
                <span *ngIf="!rowData.opt_Funcionamento">
                    <p-selectButton [options]="aberto" [(ngModel)]="rowData.opt_Funcionamento"
                    (onOptionClick)="rowData.opt_Funcionamento" name="diaFechado"
                    pTooltip="Fechado" tooltipPosition="top"></p-selectButton>
                </span>
 </td>
    
asked by anonymous 10.08.2018 / 08:08

0 answers