EXTJS日期字段问题请帮忙

时间:2011-05-26 14:25:14

标签: json datagrid extjs callback datastore

我无法弄清楚这是怎么回事。我在我的回调中使用Extjs和AJAX与我的回调我的页面在ASP中调用数据库并返回此字段中的一些字段有一个日期,这个日期返回正确的日期例如:“date_creat_post”:“29 \ u002F04 \ u002F2011“ ......

现在,一旦我在数据网格的页面中看到我的输出,我就得到以下内容:


04/05/2013< ---->它在回调中返回的日期是04/05/2011

06/05/2012< ---->它在回调中返回的日期是06/05/2010

07/04/2012< ---->它在回调中返回的日期是07/04/2010


我看了所有扔掉我的代码,看看他们是否是我在这个日期加1年的地方。 但找不到它。我现在已经尝试了至少2天来解决这个问题。

这是我的代码:

    Ext.onReady(function(){

Ext.QuickTips.init();

// for this demo configure local and remote urls for demo purposes
var url = {
    local:  '',  // static data file
    remote: '../myurl.asp'
};

// configure whether filter query is encoded or not (initially)
var encode = true;

// configure whether filtering is performed locally or remotely (initially)
var local = false;

var PostStore = new Ext.data.JsonStore({
    // store configs
    autoDestroy: true,
    baseParams : {filter : '[{"type":"boolean","value":false,"field":"is_sent_post"}]'},// we start only with is_sent == false
    url:  url.remote,
    remoteSort: false,
    sortInfo: {
        field: 'date_creat_post',
        direction: 'DESC'
    },
    storeId: 'Post_Store',

    // reader configs
    idProperty: 'id_post',
    root: 'Post',
    totalProperty: 'totalcount',
    fields: [{
        name: 'id_post',
        type: 'number'
    }, {
        name: 'name_post',
        type: 'string'
    }, {
        name: 'date_creat_post',
        type: 'date'//,
        //dateFormat: 'Y-m-d H:i:s'
    }, {
        name: 'from_addr_post',
        type: 'string'
    }, {
        name: 'sender_name_post',
        type: 'string'
    }, {
        name: 'is_sent_post',
        type: 'boolean'
    }, {
        name: 'date_sending_post',
        type: 'date'//,
        //dateFormat: 'Y-m-d H:i:s'
    }, {
        name: 'html_post',
        type: 'string'
    }, {
        name: 'list_send_post',
        type: 'number'
    }],
    writer: new Ext.data.JsonWriter({
                                writeAllFields: true    
                                    }),
    autoSave: false,
    batch: true
});

var filters = new Ext.ux.grid.GridFilters({
    // encode and local configuration options defined previously for easier reuse
    encode: encode, // json encode the filter query
    local: local,   // defaults to false (remote filtering)
    filters: [{
        type: 'numeric',
        dataIndex: 'id_post'
    }, {
        type: 'string',
        dataIndex: 'name_post'
    }, {
        type: 'date',
        dataIndex: 'date_creat_post'
    }, {
        type: 'string',
        dataIndex: 'from_addr_post'
    }, {
        type: 'string',
        dataIndex: 'sender_name_post'
    }, {
        type: 'boolean',
        dataIndex: 'is_sent_post'
    }, {
        type: 'date',
        dataIndex: 'date_sending_post'
    }, {
        type: 'string',
        dataIndex: 'html_post'
    }, {
        type: 'numeric',
        dataIndex: 'list_send_post'
    }]
});    

// use a factory method to reduce code while demonstrating
// that the GridFilter plugin may be configured with or without
// the filter types (the filters may be specified on the column model
var createColModel = function (finish, start) {

    var columns = [{
        dataIndex: 'id_post',
        hidden:true,
        header: 'Id',
        // instead of specifying filter config just specify filterable=true
        // to use store's field's type property (if type property not
        // explicitly specified in store config it will be 'auto' which
        // GridFilters will assume to be 'StringFilter'
        filterable: true
        //,filter: {type: 'numeric'}
    }, {
        dataIndex: 'name_post',
        header: 'Subject',
        width: 150,
        id: 'postname',
        filter: {
            type: 'string'
            // specify disabled to disable the filter menu
            //, disabled: true
        }
    }, {
        dataIndex: 'date_creat_post',
        header: 'Date Created',
       renderer:  Ext.util.Format.dateRenderer('d/m/Y'),

        filter: {
            type: 'date'     // specify type here or in store fields config
        }            
    }, {
        dataIndex: 'from_addr_post',
        header: 'From Address',
        hidden:true,
        id: 'fromaddress',
        filter: {
            type: 'string'
            // specify disabled to disable the filter menu
            //, disabled: true
        }
    }, {
        dataIndex: 'sender_name_post',
        header: 'Sender Name',
        id: 'sendername',
        filter: {
            type: 'string'
            // specify disabled to disable the filter menu
            //, disabled: true
        }
    }, {
        dataIndex: 'is_sent_post',
        header: 'Status',
        filter: {
            type: 'boolean'  // specify type here or in store fields config
        },
        renderer: function(value) {
            var rtn = (value == 1) ? 'sent' : 'stand-by';
            return rtn
        }
    }, {
        dataIndex: 'date_sending_post',
        header: 'Sending Date',
        hidden:true,
        //renderer: Ext.util.Format.dateRenderer('d/m/Y'),
        filter: {
            type: 'date'     // specify type here or in store fields config
        }            
    }, {
        dataIndex: 'list_send_post',
        header: 'Opticians list',
        hidden:true,
        id: 'optlist',
        filter: {
            type: 'number'
            // specify disabled to disable the filter menu
            //, disabled: true
        }
    }];

    return new Ext.grid.ColumnModel({
        columns: columns.slice(start || 0, finish),
        defaults: {
            sortable: true
        }
    });
};
/*
//======================contextMenu triggered by right click========================================
*/

var doRowCtxMenu = function ( thisGrid, rowIndex,cellIndex, evtObj )
{
    //Ext.popup.msg('Done !', 'Right clicked !');   
    evtObj.stopEvent();
    var sm = thisGrid.getSelectionModel();
    var records = sm.getSelections(); // returns an array of Ext.data.Records

    try
    {
        //var r = records[0]; // get the 1st Ext.data.Record of the list
        thisGrid.rowCtxMenu = new Ext.menu.Menu({
            items: [{
            text    : '<span style="color:red;">Delete Selected Email ?</span>',
            handler : function ()   {
                                    deletePost(records,thisGrid);
                                    }
                    }]
        });
        thisGrid.rowCtxMenu.showAt(evtObj.getXY());
    }
    catch(err)
    {
        Ext.popup.msg('Warning !', 'You need to select a row first !'); 
    }
};
/*
//======================END contextMenu triggered by right click========================================
//======================Delete Post Fonction =================================================
*/
function deletePost(records,thisGrid)
{

    Ext.Msg.show({
        title   :'Warning !',
        msg     : 'You are about to delete 1 email !',
        buttons : Ext.Msg.YESNOCANCEL,
        fn      : function(btn){
                    if (btn=='yes')
                    { 
                        var store = thisGrid.getStore();
                        var s = thisGrid.getSelectionModel().getSelections();
                        for(var i = 0, r; r = s[i]; i++){
                            store.remove(r);
                        }
                        store.proxy.conn.url = '../myurl.asp';
                        store.save();
                        lastOptions = store.lastOptions;
                        /*Ext.apply(lastOptions.params, {
                        //myNewParam: true
                        });*/
                        store.load(lastOptions);
                    }
    },
        animEl  : 'elId'
    }); 
}
 /*
//======================End delete Function========================================
*/
var Postgrid = new Ext.grid.GridPanel({
    id:'post_grid',
    border: false,
    width: 462,
    height:250,
    store: PostStore,
    colModel: createColModel(8),
    loadMask: true,
    viewConfig:{
    emptyText:'No Post to display, change/clear your filters, refresh the grid or add a new Email!'
    },
    plugins: [filters],
     sm: new Ext.grid.RowSelectionModel({
                 singleSelect: true,
                 listeners: {
                 rowselect: function(sm, row, rec) {
                                    Ext.getCmp("post_form").getForm().loadRecord(rec);
                                    //Ext.getCmp("htmlEdit").setValue("sdcdsdcdscsdc");
                                                    }
                             }
    }), 
    //autoExpandColumn: 'company',
    listeners: {
        cellcontextmenu : doRowCtxMenu,
        render: {
            fn: function(){
                PostStore.load({
                    params: {
                        start: 0,
                        limit: 50
                    }
                });
            }
        }
    },
    bbar: new Ext.PagingToolbar({
        store: PostStore,
        pageSize: 50,
        plugins: [filters]
    })
});

// add some buttons to bottom toolbar just for demonstration purposes
Postgrid.getBottomToolbar().add([
    '->',
    {
        text: 'Clear Filter Data',
        handler: function () {
            Postgrid.filters.clearFilters();
        } 
    }   
]);
var panelGrid = new Ext.Panel({
            width : 462,
            height : 250,
            layout : 'fit',
            renderTo: 'post-grid',
            items: Postgrid
                        });

   });

我将在firebug json中给我回调:

    {"totalcount":3, "Post": [{"id_post": 83,"name_post": "ghfgh","date_creat_post": "29\u002F04\u002F2011","from_addr_post": "fgh@sdf.com","sender_name_post": "gfh","is_sent_post": false,"date_sending_post": "29\u002F04\u002F2011","html_post": "<p>dfgdgdgd<\u002Fp>","list_send_post": null},{"id_post": 61,"name_post": "thomas test","date_creat_post": "28\u002F07\u002F2010","from_addr_post": "","sender_name_post": "","is_sent_post": false,"date_sending_post": "28\u002F07\u002F2010","html_post": "<p>test test test ets<\u002Fp>","list_send_post": null},{"id_post": 59,"name_post": "kevin test","date_creat_post": "29\u002F06\u002F2010","from_addr_post": "kevin@art-systems.net","sender_name_post": "kevin@art-systems.net","is_sent_post": false,"date_sending_post": "29\u002F06\u002F2010","html_post": "<p>jkljljoi ioijiio ijiojio oijio joijoi<\u002Fp>\u000A<p>&nbsp;<\u002Fp>\u000A<p><span style=\u0022background-color: #ffffff;\u0022>igiuihhuhi<\u002Fspan><\u002Fp>","list_send_post": null}]}

在此先感谢我希望有关邪恶网络的人可以帮助我......

欢呼声。


所以在尝试了许多解决方案后,我来到这里有问题 最后是在我的msSQL数据库中进行格式化和插入的许多尝试之后的日期示例 这个问题是问题:13 \ 09 \ 2011(d / m / Y)成为这个09/01/2012(d / m / Y)所以由于某种原因,月份13被添加到月份所以说13个月不存在所以日期将发布到09/01/2012 ....

再次查看它的格式看起来不行,所以我将其更改为de(m / d / Y),现在我在(extjs)的日期字段上点击了13天时出现了sql错误。

“将varchar数据类型转换为日期时间数据类型会导致超出范围的值。”

并且现在还有人有任何想法????

1 个答案:

答案 0 :(得分:0)

您可以尝试创建自己的一个,根据需要解析日期,而不是使用内置的Ext.util.Format.dateRenderer

ataIndex: 'date_creat_post',
    header: 'Date Created',
   renderer:  daterenderer

然后是daterenderer的一个功能:

function dateRenderer(value, id, r) {
 var myDate = r.data['date_creat_post'];
 // do some things here to strip out the date and make it into a happy format
 var d = new Date(myDate);
 return d.format('d/m/Y');
}