Extjs date column format

2019-06-07 02:11发布

问题:

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)

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.

回答1:

{
    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
    }
}


回答2:

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.

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



回答3:

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