在ng-template中使用kendo-grid-column的format属性?

时间:2018-08-23 11:17:40

标签: javascript angular kendo-ui kendo-grid kendo-ui-angular2

kendo-grid-column具有出色的列属性'format'。还有it works perfectly.

<kendo-grid [data]="gridData">
    <kendo-grid-column field="UnitPrice" title="Unit Price" format="{0:n0}">
        <ng-template kendoGridCellTemplate format="{0:n0}" let-dataItem>
            <a href="#" class="badge badge-info">{{ dataItem?.UnitPrice }}</a>      
        </ng-template>
     </kendo-grid-column>
     <kendo-grid-column field="UnitPrice" title="Unit Price" format="{0:n0}">         
     </kendo-grid-column>
</kendo-grid>

我需要添加锚标记并使用format的{​​{1}}属性。因此,我将kendo-grid-column添加到了ng-template

kendo-grid-column

但是,<kendo-grid-column field="UnitPrice" title="Unit Price" format="{0:n0}"> <ng-template kendoGridCellTemplate format="{0:n0}" let-dataItem> <a href="#" class="badge badge-info">{{ dataItem?.UnitPrice }} </a> </ng-template> </kendo-grid-column> format="{0:n0}中不起作用:

ng-template

我已经创建了an example to show what I have

是否可以在<ng-template kendoGridCellTemplate format="{0:n0} let-dataItem> <a href="#" class="badge badge-info">{{ dataItem?.UnitPrice }} </a> </ng-template> 中使用format的{​​{1}}属性?

2 个答案:

答案 0 :(得分:1)

您应该使用Kendo数字格式设置功能,例如

transform: translate(-50%,-50%) rotate(-90deg);

或者只使用Kendo IntlService的方法:

  • formatNumber()
  • parseNumber()
  • format()

答案 1 :(得分:1)

使用internationalization pipe。我找到了答案here

<kendo-grid-column field="UnitPrice" title="Unit Price" format="{0:n0}">
    <ng-template kendoGridCellTemplate format="{0:n0}" let-dataItem>
        <a href="#" class="badge badge-info">{{ dataItem?.UnitPrice | kendoNumber: 'n0' }} </a>
    </ng-template>
</kendo-grid-column>