更改日期格式以在jqGrid中显示和编辑 [英] Changing date formats for display and edit in jqGrid

查看:141
本文介绍了更改日期格式以在jqGrid中显示和编辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我定义了以下列模型-

{
    name: 'from',
    index: 'from',
    formatter: 'date',
    formatoptions: {srcformat:'ISO8601Long', newformat:'d-M-y H:i'},
    editable: true,
    edittype: 'text',
    editoptions: {
        maxlengh: 16,
        dataInit: function(element) {
            $(element).datetimepicker({
                dateFormat: 'yy-mm-dd',
                timeFormat: 'hh:mm',
                separator: ' ',
                timezone: '000'
            });
        }
    }
}

当日期显示在网格中时,日期已正确格式化为"d-M-y H:i".当我尝试编辑记录时,表单中会以这种格式填充日期,但我希望将其设置为"Y-m-d H:i"进行编辑.如果我使用datetimepicker进行更改,则该值将更新为所需的格式,但是如果未编辑该值,则发布的值为"d-M-y H:i"格式.

The date is being correctly formatted as "d-M-y H:i" when displayed in the grid. When I try to edit a record the form is populated with the date in this format but I would like it to be 'Y-m-d H:i' for editing. If I make a change using the datetimepicker then the value is updated to the desired format but if the value is not edited the value posted is "d-M-y H:i" format.

在将日期写入表单字段之前如何更改日期格式?我可以访问jqGrid用于转换的格式化方法吗?可以在填充表单字段之前使用unformat选项进行转换吗?我尝试了各种组合,但无济于事.

How would I go about changing the format of the date before it is written to the form field? Can I access the formatting methods used by jqGrid for conversion? Can I use the unformat option to convert before the form field is populated? I have tried various combinations but to no avail.

推荐答案

这是为我工作的colModel.关键是删除我通常用于常规datepicker列的"date:true"编辑规则以及dateformat.同样,正确设置格式模型始终是PITA.我已将此设置为用户喜欢的设置,以及我的Oracle DB最适合的设置...这是反复试验,并使用此页面作为参考: http://php.net/manual/en/datetime.formats.date.php

This is the colModel that worked for me. The key was removing my "date: true" edit rule, and dateformat as well, that I normally have in place for regular datepicker columns. Also, getting the format model just right is always a PITA. I have this set to what my users like and what my Oracle DB works best with...this was trial and error and used this page as reference: http://php.net/manual/en/datetime.formats.date.php

{
name:"WMBEMSG_BEGIN_DATE", 
align:"center", 
index:"WMBEMSG_BEGIN_DATE", 
datefmt: 'mm/dd/Y HH:MM', 
editable: true, 
edittype: "text", 
editoptions: { dataInit: function(el) { $(el).datetimepicker({
    controlType: 'select',
    dateFormat: "m/d/yy",
                        timeFormat: "HH:mm"
  } ) }
   }, 
label:"Begin Date", 
width:50, 
sortable: true
}

此外,请确保在载入jquery和jquery UI之后,您的timepicker javascript包含在其中.

Also, be sure your timepicker javascript include is AFTER your jquery and jquery UI loads.

这篇关于更改日期格式以在jqGrid中显示和编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆