Turbo Table with Checkbox - Primeng

Asked

Viewed 461 times

1

Hello, I am 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 checkbox stating whether that day is marked or not (open or closed, in practice). But here begins the problem... I did the configuration of the turbo table as specified in the documentation but all checkboxes return marked when loading the data or after some changes I performed for testing the "checkboxes" do not appear at first but if I click on the row it appears but the checkbox only appears after clicking on your row/column. I would like, if someone can give a light, when loading the back-end data the "checkboxes" come with the values marked or not, depending on the loaded data. Even if I check or uncheck a checkbox the values are being changed correctly, but your initial display is not correct... Here are some data to help:

HTML - Table only

<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.

  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 managed to solve the problem. I used span for the solution. Follow:

<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>
  • Problem solved.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.