[英]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
. name1
和name2
在pt.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.