EXTJS 日期字段问题请帮忙

发布于 2024-11-09 18:08:12 字数 11536 浏览 0 评论 0原文

我很难弄清楚这是怎么发生的。我正在使用 Extjs 和 AJAX 以及 JsonStore 从我的回调中我的 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 年的地方。 但找不到它。我已经尝试了至少两天来解决这个问题。

这是我的代码:

    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": "[email protected]","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": "[email protected]","sender_name_post": "[email protected]","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),现在我收到了 sql 错误当我在 (extjs) 中的日期字段上点击 13 天时。

“将 varchar 数据类型转换为 datetime 数据类型导致值超出范围。”

等等现在有人有什么想法吗???

i'm having trouble trying to figure out how this is happening. i'm using Extjs and AJAX with JsonStore from my callback my page in ASP call the database and return some fields in this fields there is a Date and this date return the proper date ex.: "date_creat_post": "29\u002F04\u002F2011"...

Now once i look at my output from this in my page in a datagrid i'm getting the following:


04/05/2013 <----> the date it return in the callback is 04/05/2011

06/05/2012 <----> the date it return in the callback is 06/05/2010

07/04/2012 <----> the date it return in the callback is 07/04/2010


I looked all threw my code to see if they're is a place where i am adding 1 year to the date.
but can't find it. i have been trying now for at least 2 days to figure this out.

Here's my code:

    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
                        });

   });

i will give my callback in firebug json:

    {"totalcount":3, "Post": [{"id_post": 83,"name_post": "ghfgh","date_creat_post": "29\u002F04\u002F2011","from_addr_post": "[email protected]","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": "[email protected]","sender_name_post": "[email protected]","is_sent_post": false,"date_sending_post": "29\u002F06\u002F2010","html_post": "<p>jkljljoi ioijiio ijiojio oijio joijoi<\u002Fp>\u000A<p> <\u002Fp>\u000A<p><span style=\u0022background-color: #ffffff;\u0022>igiuihhuhi<\u002Fspan><\u002Fp>","list_send_post": null}]}

Thanks in advance i hope some on on the wicked web can help me....

cheers.


so after trying many solution giving to be i came to this has problem
finally the the date example after many attemps to format and inserting in my msSQL database
this problem is the problem : 13\09\2011 (d/m/Y) becomes this 09/01/2012 (d/m/Y) so for some reason the month 13 is being added to the month so say the 13 month doesn't exist so the date will go to 09/01/2012....

after looking again it's the format that doesn't seem ok so i changed it de (m/d/Y) and now im getting a sql error when i hit 13 day on my datefield in (extjs).

"The conversion of a varchar data type to a datetime data type resulted in an out-of-range value."

and on and on does anyone have any ideas now ????

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千纸鹤带着心事 2024-11-16 18:08:12

您可以尝试创建自己的一个来根据需要解析日期,而不是使用内置的 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');
}

Instead of using the built in Ext.util.Format.dateRenderer, you could try creating one of your own that parses the Date as desired.

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

And then a function for your 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');
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文