ExtJs(4.2):在 DateColumn 中显示日期时间时保留时间
ExtJs(4.2): Persist Time While Displaying Date time in DateColumn
我有 datecolumn
个 grid
。
我正在以下列格式从后端获取值:Y-m-d H:i:s
。我必须将其显示为 d.m.Y
。在发回时,我必须再次将其发送为 Y-m-d H:i:s
。
我的代码如下:
型号
{
name: 'REA_LIT_URSPR',
type: 'date',
dateFormat:'Y-m-d H:i:s.0'
}
查看
{
xtype: 'datecolumn',
format:'d.m.Y',
text: 'Ursp. LT',
align: 'center',
flex:1,
dataIndex: 'REA_LIT_URSPR',
editor: {
xtype: 'datefield',
format:'d.m.Y',
editable: false
}
}
现在的问题是,如果我得到这个值 2016-04-05 23:15:03.0
,它会正确显示。但是一旦我点击它进行编辑(并在不选择新日期的情况下取消它),我就失去了时间 23:15:03.0
并且它被更改为 00:00:00.0
。
这次我想坚持,以防用户单击单元格更改日期但改变主意并单击其他地方而不更改日期。
我正在使用 Ext.grid.plugin.CellEditing
使网格可编辑。
谁能告诉我我做错了什么或者我怎样才能实现我的目标?
{
xtype: 'datecolumn',
format:'Y-m-d g:i:s A',
text: 'Ursp. LT',
align: 'center',
flex:1,
dataIndex: 'REA_LIT_URSPR',
editor: {
xtype: 'datefield',
format:'Y-m-d g:i:s A',
editable: false
}
}
好的,问题出在列日期格式上,可能您丢失了一部分日期,因为 g:i:s 未从日期列中保存。
我没有尝试过该代码,但如果它不起作用,请尝试使用这些文档创建新的日期格式http://docs.sencha.com/extjs/5.1/5.1.1-apidocs/#!/api/Ext.Date-method-parse(与 extjs 4 相同)
抱歉第一次回答,只是问题不明确
ExtJS CellEditing 插件不支持 "canceling" 用户编辑 - 无论何时您单击该字段然后离开,都会验证该字段,如果没有失败,则为 "edited".这在 RowEditing 中有所不同,其中显示了一个取消按钮,该按钮将取消编辑并在不验证输入的情况下触发 canceledit
事件。
因此您必须在 CellEditing 插件上使用 beforeedit
and validateedit
事件。如何使用它们在 ExtJS 文档中有很好的描述,它记录了如何同时访问日期字段、记录和存储。示例代码:
beforeedit:function( editor, context, eOpts ) {
editor.oldTime = context.record.data.REA_LIT_URSPR;// Save old value.
},
validateedit:function ( editor, context, eOpts ) {
if(editor.context.value == editor.oldTime) // Compare Values and decide
context.cancel = true; // whether to save it or not
}
我有 datecolumn
个 grid
。
我正在以下列格式从后端获取值:Y-m-d H:i:s
。我必须将其显示为 d.m.Y
。在发回时,我必须再次将其发送为 Y-m-d H:i:s
。
我的代码如下:
型号
{
name: 'REA_LIT_URSPR',
type: 'date',
dateFormat:'Y-m-d H:i:s.0'
}
查看
{
xtype: 'datecolumn',
format:'d.m.Y',
text: 'Ursp. LT',
align: 'center',
flex:1,
dataIndex: 'REA_LIT_URSPR',
editor: {
xtype: 'datefield',
format:'d.m.Y',
editable: false
}
}
现在的问题是,如果我得到这个值 2016-04-05 23:15:03.0
,它会正确显示。但是一旦我点击它进行编辑(并在不选择新日期的情况下取消它),我就失去了时间 23:15:03.0
并且它被更改为 00:00:00.0
。
这次我想坚持,以防用户单击单元格更改日期但改变主意并单击其他地方而不更改日期。
我正在使用 Ext.grid.plugin.CellEditing
使网格可编辑。
谁能告诉我我做错了什么或者我怎样才能实现我的目标?
{
xtype: 'datecolumn',
format:'Y-m-d g:i:s A',
text: 'Ursp. LT',
align: 'center',
flex:1,
dataIndex: 'REA_LIT_URSPR',
editor: {
xtype: 'datefield',
format:'Y-m-d g:i:s A',
editable: false
}
}
好的,问题出在列日期格式上,可能您丢失了一部分日期,因为 g:i:s 未从日期列中保存。
我没有尝试过该代码,但如果它不起作用,请尝试使用这些文档创建新的日期格式http://docs.sencha.com/extjs/5.1/5.1.1-apidocs/#!/api/Ext.Date-method-parse(与 extjs 4 相同)
抱歉第一次回答,只是问题不明确
ExtJS CellEditing 插件不支持 "canceling" 用户编辑 - 无论何时您单击该字段然后离开,都会验证该字段,如果没有失败,则为 "edited".这在 RowEditing 中有所不同,其中显示了一个取消按钮,该按钮将取消编辑并在不验证输入的情况下触发 canceledit
事件。
因此您必须在 CellEditing 插件上使用 beforeedit
and validateedit
事件。如何使用它们在 ExtJS 文档中有很好的描述,它记录了如何同时访问日期字段、记录和存储。示例代码:
beforeedit:function( editor, context, eOpts ) {
editor.oldTime = context.record.data.REA_LIT_URSPR;// Save old value.
},
validateedit:function ( editor, context, eOpts ) {
if(editor.context.value == editor.oldTime) // Compare Values and decide
context.cancel = true; // whether to save it or not
}