简体   繁体   English

*ngIf 显示 ngx-datatable 上的行按钮

[英]*ngIf show button for row on ngx-datatable

I have a populated table and by default on load, one of the columns has a hidden element by a show button.我有一个填充表,默认情况下加载时,其中一列有一个显示按钮的隐藏元素。 I'm looking to show the input per row, but currently when the button is clicked, the hidden button shows all of the fields.我希望显示每行的输入,但当前单击按钮时,隐藏按钮会显示所有字段。

HTML Table - HTML 表格 -

<ngx-datatable
   class="material"
   rowHeight="auto"
   [loadingIndicator]="tableLoading"
   [columnMode]="ColumnMode.force"
   [rows]="rows"
   [headerHeight]="50"
   [footerHeight]="50"
   [limit]="30"
   [selected]="selected"
   [selectionType]="SelectionType.checkbox"
   [selectAllRowsOnPage]="false"
   (select)="onSelect($event)"
   [sorts]="[{prop: 'lastName', dir: 'asc'}]"
 >

<ng-template ngx-datatable-cell-template let-rowIndex="rowIndex" let-row="row">

 <ng-select
    *ngIf="singleItem"
    [multiple]="true"
    placeholder="Select a single medication to send"
    appendTo="body"
    (change)="onChange($event)"
    [items]="row.medications.items"
    bindLabel="name"
    bindValue="id"
    [(ngModel)]="selectedMedications[row.id]">
 </ng-select>

<div *ngIf="!singleItem">
   <p class="btn btn-light" type="button" (click)="buttonSwitch([row.id])">
      Single item 
   </p>
</div>

TS - TS -

singleItem: boolean;

buttonSwitch(row) {
  console.log(row);
  this.singleItem = true;
}

Once the button switch is clicked, the input field for only the row should appear.单击按钮开关后,应仅显示该行的输入字段。

You need a singleItem or another named flag for each row.每行都需要一个singleItem或另一个命名标志。 Right now you have one for all entries, that's why when you click on the button, it changes all rows.现在你有一个所有条目,这就是为什么当你点击按钮时,它会改变所有的行。

On this buttonSwitch function, you're getting the row parameter and not using it.在此buttonSwitch函数中,您获取的是row参数而不是使用它。 You should have something like this:你应该有这样的东西:

buttonSwitch(row) {
  row.singleItem = true;
  // Or the
  // row.singleItem = !row.singleItem;
  // To switch the value, and not only set as true
}

Then your *ngIf would be like this: *ngIf="row.singleItem"那么你的*ngIf会是这样的: *ngIf="row.singleItem"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM