douglas
douglas

Reputation: 121

how to pass the id value of the grid to a button?

I am trying to pass the idEvento2 value of my grid to my button with the function descargartodo so that all the documents with the same id can be downloaded when pressing the button how could i do it?

html

<ng-container *ngIf="state$ | async as state">
  <lib-modal-container class="bootstrap-wrapper"
                       [modalTitle]="state.title"
                       [formType]="state.formType"
                       [loading]="state.loading"
                       (dismiss)="handleClose()">   
    <div class="m-r-12">
      <div class="fixed-bottom-buttons text-right">
        <button 
                matTooltip="descargar archivos"
                class="mini-icon-button"
                mat-flat-button
                color="primary"
                type="button"
                (click)="descargartodo()">
          <mat-icon> file_download</mat-icon>
          Decargar todo
        </button>
        <br />
        <br />
      </div>
      <lib-grid variant="list"
                emptyRowsMsg="No hay registros"
                [loading]="state.gridControlResumen.loading"
                [definition]="state.gridControlResumen.definition"
                [source]="state.gridControlResumen.source">   
        <ng-template libTemplate="tpl-accion"
                     let-data>
          <button matTooltip="Ver archivo"
                  class="mini-icon-button"
                  mat-icon-button
                  value="documento"
                  color="primary"
                  type="button"
                  (click)="handleClickVerArchivo($event,data.idEvento,data.documento)" >
            <mat-icon>visibility</mat-icon>
          </button>
        </ng-template>
      </lib-grid>
    </div>
  </lib-modal-container>
</ng-container>

typescript

descargartodo = (data) => {
    const { idEvento: idEvento } = this.store.selectSnapshot(FORM_RESUMEN_SOL_STATE_TOKEN); 
    this.solicitudesService.descargarSolAgendaWord(idEvento).subscribe(blob => {
      CORE_FUNCTIONS.downloadFile(blob, 'agenda.docx');
    })
    this.solicitudesService.descargarReporteInvitadosWord(idEvento).subscribe(blob => {
      CORE_FUNCTIONS.downloadFile(blob, 'invitados.docx');
    }); 
  }    
  handleClickVerArchivo = ($event, data, documento) => {
     const idEvento2 = data;
    if (documento == "Agenda") {
      try {
        this.solicitudesService.descargarSolAgendaWord(idEvento2).subscribe(blob => {
          CORE_FUNCTIONS.downloadFile(blob, 'agenda.docx');
        });
      } catch (e) { console.log("hubo un error") }
    }        
    }

I need pass the values from handleClickVerArchivo to descargartodo

enter image description here

Upvotes: 1

Views: 484

Answers (1)

Hamada
Hamada

Reputation: 1898

html

  <hello name="{{ name }}"></hello>
<p>
  Start editing to see some magic happen :)
</p>

<form novalidate #formIdToPass="ngForm" (ngSubmit)="handleClickVerArchivo(formIdToPass.value)">
    <label>ID</label>
    <input type="text" name="idToPass" ngModel>
    <input type="submit" value="send">
</form>

<p>
{{ descargartodo() }}
</p>

ts

import { Component, VERSION } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: [ './app.component.css' ]
})
export class AppComponent  {
  name = 'Angular ' + VERSION.major;
  idToPass: number;
  constructor(){
    this.idToPass = 0;
  }

 descargartodo() {
  if (this.idToPass > 0 ){
   let data = this.idToPass
    console.log(this.idToPass)
    return data;
}}  

  
  handleClickVerArchivo(data) { 
    console.log(data)  
     this.idToPass = data.idToPass
  }
}

demo in stackblitz

Upvotes: 1

Related Questions