简体   繁体   English

在 angular 的 ngx 数据表中鼠标悬停时获取任何特定单元格的详细信息时出现问题

[英]Problem getting details for any particular cell on mouse hovering in ngx datatable in angular

I am using ngx datatable, importing my data from a json. I have added some more details to be shown in Column 'domain'.我正在使用 ngx 数据表,从 json 导入我的数据。我添加了一些更多详细信息以显示在“域”列中。 So while hovering to a particular cell of Column 'domain', i want to get more details about that cell only, but I am getting more details of all cells of that particular column.因此,当鼠标悬停在列“域”的特定单元格时,我只想获取有关该单元格的更多详细信息,但我正在获取该特定列的所有单元格的更多详细信息。

//HTML that I am using //我正在使用的HTML

<ngx-datatable-column name="App Domain" [flexGrow]="2" >
            <ng-template let-row="row" ngx-datatable-cell-template>
                <div (mouseover)="showText=(true)" (mouseout)="showText=(false)" >{{row?.domain}}</div>
                <div *ngIf="!showText"></div>
                <div *ngIf="showText">
                    {{row?.vp}}<br>
                    {{row?.cpu}}<br>
                    {{row?.vm}}<br>
                    {{row?.maxspeed}}</div>
            </ng-template>
        </ngx-datatable-column> 

//HTML datatable properties in my code //我的代码中的 HTML 数据表属性

<ngx-datatable class="material full screen" class="bootstrap" [rows]="rows" [columnMode]="'flex'" [headerHeight]="50" [footerHeight]="50" rowHeight="auto">

//component.ts //组件.ts

export class DashboardComponent implements OnInit {
  title = 'test-dashboard';
  rows=[ ]
  apiResponseData: any = [];
  apiData = []
  pingApiInterval = 300000; 
  showText: boolean;
  
constructor(private dashboardService: DashboardService) { this.showText = false; }

Tried various approaches, but I failed.尝试了各种方法,但我失败了。

The problem is that you are using the same variable showText for all rows.问题是您对所有行使用相同的变量showText

For getting the details of a particular cell you can use a variable ( showedIndex ) for storing the index of the row hovered and then check it for showing only his information.要获取特定单元格的详细信息,您可以使用变量 ( showedIndex ) 来存储悬停行的索引,然后检查它是否仅显示他的信息。

<ngx-datatable-column name="App Domain" [flexGrow]="2" >
            <ng-template let-row="row" let-rowIndex="rowIndex" ngx-datatable-cell-template>
                <div (mouseover)="showedIndex = rowIndex; showText=true" (mouseout)="showText=false" >{{row?.domain}}</div>
                <div *ngIf="!showText"></div>
                <div *ngIf="showText && rowIndex === showedIndex">
                    {{row?.vp}}<br>
                    {{row?.cpu}}<br>
                    {{row?.vm}}<br>
                    {{row?.maxspeed}}</div>
            </ng-template>
        </ngx-datatable-column> 

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

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