javascript Extjs 日期列格式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18584530/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Extjs date column format
提问by kuldarim
i have date column with datefield editor. The problem is that while im editing column it displays the normal value for example 2013-02-05
, but when close editing it displays something like Sat Jul 12 2014 00:00:00 GMT+0300 (FLE Standard Time)
我有带日期字段编辑器的日期列。问题是,当我编辑列时,它会显示正常值2013-02-05
,但是当关闭编辑时,它会显示类似的东西Sat Jul 12 2014 00:00:00 GMT+0300 (FLE Standard Time)
My code:
我的代码:
{
xtype : 'datecolumn',
dataIndex : 'depreciationStartPeriod',
header : 'Depreciation start period',
sortable : true,
id : 'depreciationStartPeriod',
width : 134,
editor : {
xtype : 'datefield',
format: 'Y-m-d H:i:s'
}
}
store field:
商店领域:
{
name : 'depreciationStartPeriod',
type : 'String',
dateFormat: 'c'
}
what the reasons could be?
原因可能是什么?
UPDATE
更新
in store it is also saved with wrong format for some reason, that's why it is being displayed in such format, but i don`t now the reason of that.
在商店中,由于某种原因,它也以错误的格式保存,这就是它以这种格式显示的原因,但我现在不知道这是什么原因。
回答by user2417329
{
xtype : 'datecolumn',
dataIndex : 'depreciationStartPeriod',
header : 'Depreciation start period',
sortable : true,
id : 'depreciationStartPeriod',
width : 134,
format: 'Y-m-d H:i:s', // <------- this way
editor : {
xtype : 'datefield',
format: 'Y-m-d H:i:s',
submitFormat: 'c' // <-------------- this way
}
}
回答by kevhender
You need to have your store field as a date
type, not a string
. Because it is currently a string, ExtJS is converting it directly from datefield.getValue().toString()
, which is what is giving it that full format your are getting.
您需要将 store 字段作为date
类型,而不是string
. 因为它目前是一个字符串,ExtJS 直接将它从 转换datefield.getValue().toString()
,这就是给它你所得到的完整格式。
Also note that even if you wanted to use a string
for type
, the word should be entirely lowercase (you currently have String
). Check out this link for the valid type
params you can use: http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.data.Field-cfg-type
另请注意,即使您想使用string
for type
,该词也应该完全小写(您目前拥有String
)。查看此链接以获取type
您可以使用的有效参数:http: //docs.sencha.com/extjs/4.2.1/#!/api/Ext.data.Field-cfg-type
回答by user2246577
try giving type in store as Ext.data.Types.DATE i had similar problem by changin the type to Ext.data.Types.DATE solved it
尝试在商店中提供类型为 Ext.data.Types.DATE 我通过将类型更改为 Ext.data.Types.DATE 解决了类似的问题