【问题标题】:jqgrid and datepicker control giving error for new recordsjqgrid 和 datepicker 控件为新记录提供错误
【发布时间】:2013-08-23 20:33:54
【问题描述】:

我通过 jqgrid 与从 ajax 返回的 json 绑定。 json 具有以下格式的日期

11/1/2013 12:00:00 AM

在 colmodel 中我指定了以下内容

{ name: 'datecol', index: 'SignDate', width: '200', jsonmap: 'cell.SignDate', editable: true, sorttype: 'date',
                    editable: true, formatter: 'date', formatoptions: {
                        srcformat: 'm-d-Y H:i:s',
                        newformat: 'Y-M-d'
                    },
editoptions: { dataInit: initDateEdit },
initDateEdit = function(elem) {
                setTimeout(function() {
                    $(elem).datepicker({
                        formatter: 'date', formatoptions: {
                            srcformat: 'm-d-Y H:i:s',
                            newformat: 'yy-M-d'
                        }
                        autoSize: true,
                        showOn: 'button', // it dosn't work in searching dialog
                        changeYear: true,
                        changeMonth: true,
                        showButtonPanel: true,
                        showWeek: true
                    });
                    //$(elem).focus();
                },100);
            }

这会在网格中正确显示日期

2013-Nov-01

但是当我点击添加新记录时,弹出窗口来了,当我选择日期并点击提交时,在网格中,新记录正在显示

NaN-undefined-NaN

在日期列中。这里有什么问题?

当我使用与此链接中给出的相同代码时 http://www.ok-soft-gmbh.com/jqGrid/LocalFormEditing.htm

编辑工作正常,但是当我添加新行时,日期为 NaN-undefined-NaN

请帮忙。

【问题讨论】:

    标签: jquery-ui jqgrid jquery-ui-datepicker


    【解决方案1】:

    我认为您描述的问题的原因是您使用的 jQuery UI Datepicker 的参数错误。您使用不存在的datepicker 的formatter 和formatoptions 参数。取而代之的是,您应该使用dateFormat 格式描述的here 选项。

    已更新:您描述的问题的主要原因是您使用的日期格式错误。重要的是要了解formatoptions 的srcformat 和newformat 应该有PHP date format,但是jQuery UI Datepicker 支持例如描述here 的另一种格式。输入数据11/1/2013 12:00:00 AM 包含日期和时间。另一方面,jQuery UI Datepicker 仅支持日期。因为您使用newformat: 'yy-M-d',所以我想您只想忽略日期的时间部分。在这种情况下,我建议您使用

    formatter: 'date',
    formatoptions: {
        srcformat: 'm/d/Y',
        newformat: 'Y-m-d'
    }
    

    而不是

    formatter: 'date',
    formatoptions: {
        srcformat: 'm-d-Y H:i:s',
        newformat: 'Y-m-d'
    }
    

    您当前使用的。下一个问题是 jQuery UI Datepicker 的 dateFormat 选项。您必须使用与srcformat 对应的格式,但使用正确的格式(描述为here)。对于srcformat: 'm/d/Y',您应该使用dateFormat: 'm/d/yy',而不是您在jsfiddle demo 中使用的dateFormat: 'yy-m-dd'。

    The modified demo 现在可以正常工作了。

    【讨论】:

    • 谢谢奥列格。我已将代码更改如下。我的 col 模型是可编辑的:true,格式化程序:'date',formatoptions:{ srcformat:'m/d/YH:i:s',newformat:'dMY'},datefmt:'dM-Y',editoptions:{ dataInit : initDateEdit }, searchoptions: { dataInit: initDateSearch } } 并且在 initDateEdit 函数中,我删除了格式化程序选项并给出了 dateFormat: 'dd-M-yy' ,如您的示例中所示。但我仍然得到错误。
    • 只有当我添加新报告并选择日期并点击提交时才会出现错误。在添加对话框中,它显示了正确的日期,但是当我提交时,它在 jqgrid 中显示了这个错误。
    • 有人请帮忙。我发现这是与 jquery 相关的内容。这是我需要包含的文件的正确顺序吗? jquery-ui-1.8.2.custom.css ui.jqgrid.css jquery-1.9.1.min.js jquery-ui-1.9.2.custom.min.js grid.locale-en.js jquery.jqGrid.js jquery.fmatter.js 我错过了任何文件吗?请帮忙。
    • @user1447718:你有重现问题的演示吗?请在演示中使用grid.locale-en.js 和jquery.jqGrid.src.js。有任何后端并不重要。可以使用 Fiddler、Firebug 或任何其他工具来捕获 HTTP 流量并查看哪些数据(正确的日期或NaN-undefined-NaN 被发送)。也可以使用serializeEditData 来跟踪发布到服务器的数据。我的问题是我无法重现您描述的问题。
    • 感谢奥列格的回复。我不确定如何将我的代码放入提琴手​​,但会发现。我用你用过的库替换了这些库,它工作正常。所以在你的示例中,如果你用最新版本的 jquery、jqueryui 和 jqgrid 替换库,那么你将能够看到问题,我相信。如果你不这样做,那么这将是我的问题的解决方案。
    猜你喜欢
    • 2021-02-21
    • 2021-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-03
    相关资源
    最近更新 更多