【发布时间】:2020-10-24 05:28:07
【问题描述】:
我正在尝试在自定义编辑器中更新货币列值(因为我希望在编辑时显示小数点符号、货币符号和千位符号 - 然后我会在提交时将其改回)
这是到目前为止的代码(还没有添加或删除符号,只是试图让更新正常工作。 当单元格格式为货币类型时,有一个 cellClick 设置调用以下代码:
var inpck = $(mycell).find('input').length;
if (inpck == 1) {
console.log('Input Already Exists');
return;
}
$(mycell).html($(mycell).find('input')); // remove text node of orig cell
$(mycell).append('<input type="text">'); // add input box
var editor = $(mycell).find('input');
//Set value of editor to the current value of the cell
console.log('Start Money Val: ' + celltxt); // shows correctly
editor.val(celltxt);
// Set focus on the input when the editor is selected (timeout allows for editor to be added to DOM)
editor.focus();
// After editing, trigger the cell to update on blur
editor.on("blur", function(e) {
var editval = editor.val();
alert('EditedValue: ' + editval); // shows correctly
alert('CellID: ' + cellid); // shows correctly
alert('CellField: ' + cellf); // shows correctly
var updMonObj=[];
updMonObj['id']=cellid;
updMonObj[cellf]=editval;
$("<tableid>").tabulator("updateData", updMonObj);
$("<tableid>").tabulator("redraw");
});
发出警报后,单元格不会更新,当我刷新页面时,新值不会出现。如果可能的话,希望单元格更新并显示新值而不刷新整个表格。
还想要一种在他们返回时进行更新的方法。
谢谢
更新1:
好的,现在我有了这个(运行 v3.2 - 现在必须坚持使用旧版本):
In the column definitions, I think this should work:
,editor: "moneyEdit1";
Then the tabulator call, and then further down:
var moneyEdit1 = function(cell, onRendered, success, cancel, editorParams) {
//define custom editor
var inpck = $(cell).find('input').length;
if (inpck == 1) {console.log('Input Already Exists'); return;}
console.log('Inside Money Edit');
var mycell = cell.getElement();
console.log('MyCell: ' , mycell);
$(mycell).html($(mycell).find('input')); // remove text node
$(mycell).append('<input type="text">');
var editor = $(mycell).find('input');
// Set value of editor to the current value of the cell
console.log('Start Money Val: ' + celltxt);
editor.val(celltxt);
// Set focus on the input when the editor is selected
onRendered(function() {
editor.focus();
editor.style.width = "100%";
});
// After editing, trigger the cell to update
successFunc(function() {
console.log('Inside of Change/Blur/Enter');
var editval = editor.val();
alert('EditedValue: ' + editval);
success(editval);
});
// If they cancel w/ escape key
cancelFunc(function() {
console.log('Inside of Cancel');
cancel(editval);
});
editor.addEventListener("change", successFunc);
editor.addEventListener("blur", successFunc);
editor.addEventListener("keyup", function onEvent(e) {
if (e.which === 13) {successFunc;}
});
editor.addEventListener("keyup", function onEvent(e) {
if (e.which === 27) {cancelFunc;}
});
// Return the editor element
return editor;
}
这看起来应该有效吗?仍然没有调用自定义编辑器,因为我没有看到任何控制台日志,这是怎么回事?
【问题讨论】:
标签: javascript tabulator