简体   繁体   English

动态更改 ngx-datatable-column 名称

[英]Change the ngx-datatable-column name dynamically

I'm using a component ngx-datatable angular version 9. I'm trying change the props name dynamically using a *ngIf command.我正在使用组件ngx-datatable angular 版本 9。我正在尝试使用 *ngIf 命令动态更改道具name

Problem: I want to using a attribute the list to show the right name.问题:我想使用列表的属性来显示正确的名称。

Code:代码:

    <ngx-datatable-column *ngIf="id == 0 "
      [cellClass]="'alinha-centralizado-global'"
      [headerClass]="'alinha-centralizado-global'"
      name="{{ 'name1' | translate }}"
      prop="fullName"
      [flexGrow]="2"
    >
   <ngx-datatable-column *ngIf="id == 1 "
      [cellClass]="'alinha-centralizado-global'"
      [headerClass]="'alinha-centralizado-global'"
      name="{{ 'name2' | translate }}"
      prop="fullName"
      [flexGrow]="2"
    > 
      <ng-template let-value="value" ngx-datatable-cell-template>
        <span title="{{ value }}">
          {{ value | fullName }}
        </span>
      </ng-template>
    </ngx-datatable-column>

The name1 and name2 are in the pt.json . name1name2pt.json中。 And the id is the [rows]="list" attribute. id[rows]="list"属性。 Of course doesn't work.当然不行。 Does anyone have any idea how to change the ngx-datatable-column props name dynamically?有谁知道如何动态更改ngx-datatable-column道具name

It's a beginner question.这是一个初学者的问题。 The correct way to do show the props's ngx-datatable-column name is to with in the .html file write like this:显示道具的ngx-datatable-column name的正确方法是在.html文件中这样写:

  <ngx-datatable-column 
      [cellClass]="'alinha-centralizado-global'"
      [headerClass]="'alinha-centralizado-global'"
      prop="fullName"
      [flexGrow]="2"
    >
      <ng-template ngx-datatable-header-template>
          <span>{{ getName() }}</span>
      </ng-template>
      <ng-template let-value="value" ngx-datatable-cell-template>
        <span title="{{ value }}">
          {{ value | fullName }}
        </span>
      </ng-templa`enter code here`te>
    </ngx-datatable-column>`enter code here`

And in the .ts file you create a method getName() with the condition to show name dinamicatilly..ts文件中,您创建了一个方法getName() ,条件是动态显示name

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

相关问题 如何在Angular中为ngx-datatable-column传递多个管道? - How to pass multiple pipes for ngx-datatable-column in Angular? 如何将锚标记添加到ngx-datatable-column - How to add anchor tag to ngx-datatable-column 在 ngx-datatable-column 中使用 ngFor 和 ng 模板 - usage of ngFor with ng template in ngx-datatable-column 默认显示排序图标 - ngx-datatable-column - Show sort icon by default - ngx-datatable-column 如何将外部变量传递给 ngx-datatable-column? - How to pass external variables to ngx-datatable-column? 如何将唯一的 HTML ID 属性添加到 ngx-datatable-column - How to add a unique HTML ID attribute to an ngx-datatable-column 如何通过 <ngx-datatable-column> 在另一个组件包裹的内部, <ngx-datatable> ? - How to pass an <ngx-datatable-column> inside a wrapped, by another component, <ngx-datatable>? 如何在 Angular 的 ngx-datatable / ngx-datatable-column 中使用排序? - How use sorting in ngx-datatable / ngx-datatable-column in Angular? Angular:如果模态(弹出窗口)中止,则ngx-datatable-column中的值不会更新 - Angular: not-to-update values in ngx-datatable-column if modal (popup) aborted 是否可以将输入属性 [columns] 与 ngx-datatable-column 指令一起使用? - Is it possible to use the input property [columns], together with the ngx-datatable-column directive?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM