如何在ExtJS网格中指定单元格的格式?

hhh*_*112 2 javascript extjs

例如,我有以下网格:

Value | Currency
------|---------
12.32 | EUR
14.00 | JPY
Run Code Online (Sandbox Code Playgroud)

日元不使用小数,因此我想知道是否可以使用ExtJS为每个单元格指定小数位。在这种情况下,日元仅显示14,而不是14.00。

我看过数字列,但是从我看到的结果来看,没有为单元格指定格式的选项。

如何在ExtJS网格中指定单元格的格式?

Ben*_*ier 6

您可以使用列渲染器来做到这一点。您检查货币的价值,如果它是JPY,则显示不带小数的值:

http://docs.sencha.com/extjs/4.2.0/#!/api/Ext.grid.column.Column-cfg-renderer

    columns: [{
                text: "Value",
                flex : 1,
                dataIndex: 'value',
                renderer: function(value, metaData, record){
                      if (record.data.currency === 'JPY') {
                           return Ext.util.Format.number(value, '0');
                      } 
                      return value;
                }},
                {text: "currency", flex : 1, dataIndex: 'currency'}]
Run Code Online (Sandbox Code Playgroud)

这是一个工作中的小提琴:http : //jsfiddle.net/Xpe9V/1608/