[英]Currency format for Kendo Grid in Angular with Globalization
I am using the kendo grid in Angular 4+. 我在Angular 4+中使用剑道网格。 I need all the cells in a column to have a localized currency displayed.
我需要一列中的所有单元格以显示本地化的货币。 Is this possible?
这可能吗?
...
<kendo-grid-column
field="unitPrice"
format="currency" // <- for clearity: I need to do something like this.
[title]="Unit Price">
</kendo-grid-column>
It appears the kendo requires you to declare the format as well as provide the locale, like so. 剑道似乎要求您声明格式并提供语言环境,就像这样。
kendo column 剑道专栏
<kendo-grid-column
field="unitPrice"
filter="numeric"
format="{0:c}"
[title]="'formsPlus.lineItemAttach.unitPrice' | translate"
[width]="100">
</kendo-grid-column>
your.module.ts your.module.ts
import { LOCALE_ID, NgModule } from "@angular/core"
...
@NgModule({
...
providers: [
{ provide: LOCALE_ID, useValue: "en-US" },
],
For some reason It would not work without providing the LOCALE_ID
. 由于某些原因,如果不提供
LOCALE_ID
,它将无法正常工作。
Side Note: You can change the language at startup by importing the locale into your module like so: 注意:您可以在启动时通过将语言环境导入模块来更改语言,如下所示:
import "@progress/kendo-angular-intl/locales/fr/all"
...
...
{ provide: LOCALE_ID, useValue: "fr" },
Yes sure, you can do it. 是的,可以。
Check the below code from Kendo UI Grid localization demo 从Kendo UI Grid本地化演示中检查以下代码
element.kendoGrid({
dataSource: dataSource,
pageable: {
refresh: true,
pageSizes: true,
buttonCount: 5
},
filterable: true,
sortable: true,
columnMenu: true,
toolbar: ["create"],
columns: [
"ProductName",
{ field: "UnitPrice", title: "Unit Price", format: "{0:c}", width: "120px" },
{ field: "UnitsInStock", title:"Units In Stock", width: "140px" },
{ field: "Discontinued", width: "140px" },
{ command: ["edit", "destroy"], title: "", width: "260px" }],
editable: "inline"
});
Observe that the field UnitPrice
is formatted based on the format
provided in the column
观察字段
UnitPrice
是根据column
提供的format
格式化的
{ field: "UnitPrice", title: "Unit Price", format: "{0:c}", width: "120px" }
For more reference, you can check Kendo Localization documentation 有关更多参考,可以查看Kendo本地化文档。
UPDATE: 更新:
For Angular 2+, there won't be much difference. 对于Angular 2+,不会有太大区别。
You can have your markup as below. 您可以如下所示进行标记。
<kendo-grid-column
field="unitPrice"
format="{0:c}" // or format="'{0:c}'"
[title]="Unit Price">
</kendo-grid-column>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.