[英]jqGrid Disable Date Picker Value for Inline Edit
I'm using jqGrid 4.4.4. 我正在使用jqGrid 4.4.4。 I have a date picker for a column and it returns today's date. 我有一列的日期选择器,它返回今天的日期。 I only need it to default to today's date for the add modal pop-up. 对于添加模式弹出窗口,我只需要将其默认为今天的日期即可。 However, when someone is editing a record inline, I need the date not to change to today's date when the user clicks into a record to edit inline. 但是,当某人正在编辑内联记录时,我需要该日期不要更改为用户单击记录以进行内联编辑时的今天的日期。
This is causing data integrity issues, because when a user edits an existing record, the date changes to today's date. 这导致数据完整性问题,因为当用户编辑现有记录时,日期更改为今天的日期。
How can I keep it the way it is for adding a new record through the modal, while preventing it from defaulting when inline editing? 如何在通过模态添加新记录的同时保持它的方式,同时防止在进行内联编辑时将其默认设置?
Here is the code with the datepicker in the edit options: 这是在编辑选项中带有日期选择器的代码:
{ key: false, name: 'CHK_DT_RCVD', width: '130px', index: 'CHK_DT_RCVD',
editable: true, formatter: 'date',
formatoptions: { newformat: 'm-d-Y' },
formoptions: {},
editrules: { custom: true, custom_func: validDateCheck },
editoptions:
{
dataInit: function (element)
{
$(element).datepicker({
id: 'entryDate_Datepicker',
dateFormat: 'mm-dd-yy',
maxDate: new Date(2020, 0, 1),
showOn: 'focus'
}).val(moment(new Date()).format('MM/DD/YYYY'));
}
}
},
First of all you should initialize datepicker
inside of setTimeout
. 首先,您应该在setTimeout
内初始化datepicker
。 The problem: the dataInit
could be (will be) called before element
be placed on the HTML page ( element
is disconnected DOM element). 问题:在dataInit
可能(会)调用之前 element
放在HTML页面(上element
是断开的DOM元素)。
Inside of setTimeout
you can travel over the parents of element
and to try to find out whether the element is inside of tr.jqgrow
or not. 在setTimeout
内部,您可以遍历element
的父级,并尝试找出该元素是否在tr.jqgrow
内部。 If $(element).closest("tr.jqgrow").length > 0
then the datepicker is inside of inline editing (or cell editing). 如果$(element).closest("tr.jqgrow").length > 0
则日期选择器位于内联编辑(或单元格编辑)内部。 You should not use .val(moment(new Date()).format('MM/DD/YYYY'));
您不应该使用.val(moment(new Date()).format('MM/DD/YYYY'));
in the case. 在这种情况下。
Additionally you can consider to use defaultValue
property of editoptions . 另外,您可以考虑使用editoptions的 defaultValue
属性。 It will be used in Add dialog of form editing. 将在表单编辑的“添加”对话框中使用。 Probably you will be not need to use any .val(...)
after the specifing of defaultValue
. 指定defaultValue
之后,可能不需要使用任何.val(...)
。
By the way, I'd recommend you to remove unneeded key: false
and index: 'CHK_DT_RCVD'
properties and to fix width: '130px'
to width: 130
because the value of width
have to be integer. 顺便说一句,我建议您删除不需要的key: false
和index: 'CHK_DT_RCVD'
属性,并将width: '130px'
固定为width: 130
因为width
的值必须为整数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.