无法将日期时间选择器添加到制表符列
Can ’t add datetimepicker to Tabulator column
我想为我的 Tabulator 创建自定义编辑器 table。我需要编辑日期值并想使用 jQuery DateTimePicker。
我尝试从 Tabulator 网站编辑示例代码,但它对我不起作用。我的自定义编辑器代码如下所示:
var dateEditor = function (cell, onRendered, success, cancel, editorParams) {
var editor = document.createElement("input");
editor.setAttribute("type", "text");
editor.value = cell.getValue();
onRendered(function(){
jQuery(editor).datetimepicker({
format: "dd.mm.yyyy HH:mm",
});
editor.focus();
});
function onChange(e){
success(editor.value);
}
editor.addEventListener("change", onChange);
editor.addEventListener("blur", onChange);
return editor;
};
和列定义:
{title:"Date", field:"date", align:"left", headerFilter: "input", editor: dateEditor, headerFilterPlaceholder:" "},
日期选择器组件出现,但当我尝试更改值时,出现以下消息:
"Uncaught Missing instance data for this datepicker"
感谢您的帮助。
编辑#1:发现日期格式有问题,但主要问题仍然存在。
我能够重现该问题。问题是您不应该使用文本框的 onChange
或 onBlur
事件。相反,您想使用日期选择器事件
var dateEditor = function(cell, onRendered, success, cancel, editorParams){
var cellValue = cell.getValue(),
input = document.createElement("input");
input.setAttribute("type", "text");
input.style.padding = "4px";
input.style.width = "100%";
input.style.boxSizing = "border-box";
input.value = typeof cellValue !== "undefined" ? cellValue : "";
onRendered(function(){
input.style.height = "100%";
$(input).datepicker({
onClose: onChange
}); //turn input into datepicker
input.focus();
});
function onChange(e){
if(((cellValue === null || typeof cellValue === "undefined") && input.value !== "") || input.value != cellValue){
success(input.value);
}else{
cancel();
}
}
return input;
}
https://jsfiddle.net/kcf1jes0/7/
我想为我的 Tabulator 创建自定义编辑器 table。我需要编辑日期值并想使用 jQuery DateTimePicker。
我尝试从 Tabulator 网站编辑示例代码,但它对我不起作用。我的自定义编辑器代码如下所示:
var dateEditor = function (cell, onRendered, success, cancel, editorParams) {
var editor = document.createElement("input");
editor.setAttribute("type", "text");
editor.value = cell.getValue();
onRendered(function(){
jQuery(editor).datetimepicker({
format: "dd.mm.yyyy HH:mm",
});
editor.focus();
});
function onChange(e){
success(editor.value);
}
editor.addEventListener("change", onChange);
editor.addEventListener("blur", onChange);
return editor;
};
和列定义:
{title:"Date", field:"date", align:"left", headerFilter: "input", editor: dateEditor, headerFilterPlaceholder:" "},
日期选择器组件出现,但当我尝试更改值时,出现以下消息:
"Uncaught Missing instance data for this datepicker"
感谢您的帮助。
编辑#1:发现日期格式有问题,但主要问题仍然存在。
我能够重现该问题。问题是您不应该使用文本框的 onChange
或 onBlur
事件。相反,您想使用日期选择器事件
var dateEditor = function(cell, onRendered, success, cancel, editorParams){
var cellValue = cell.getValue(),
input = document.createElement("input");
input.setAttribute("type", "text");
input.style.padding = "4px";
input.style.width = "100%";
input.style.boxSizing = "border-box";
input.value = typeof cellValue !== "undefined" ? cellValue : "";
onRendered(function(){
input.style.height = "100%";
$(input).datepicker({
onClose: onChange
}); //turn input into datepicker
input.focus();
});
function onChange(e){
if(((cellValue === null || typeof cellValue === "undefined") && input.value !== "") || input.value != cellValue){
success(input.value);
}else{
cancel();
}
}
return input;
}
https://jsfiddle.net/kcf1jes0/7/