Javascript 制表器-更新货币列自定义编辑器的值
我正在尝试在自定义编辑器中更新货币列值(因为我希望在编辑时显示十进制符号、货币符号和千符号-然后在提交时将其更改回来) 这是到目前为止的代码(还没有添加或删除符号,只是试图让更新正常工作。 当单元格格式为货币类型时,有一个cellClick设置调用以下代码:Javascript 制表器-更新货币列自定义编辑器的值,javascript,tabulator,Javascript,Tabulator,我正在尝试在自定义编辑器中更新货币列值(因为我希望在编辑时显示十进制符号、货币符号和千符号-然后在提交时将其更改回来) 这是到目前为止的代码(还没有添加或删除符号,只是试图让更新正常工作。 当单元格格式为货币类型时,有一个cellClick设置调用以下代码: var inpck = $(mycell).find('input').length; if (inpck == 1) { console.log('Input Already Exists'); return; }
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");
});
var inpck=$(mycell).find('input').length;
如果(inpck==1){
log('输入已经存在');
返回;
}
$(mycell.html($(mycell.find('input'));//删除原始单元格的文本节点
$(mycell.append(“”);//添加输入框
变量编辑器=$(mycell.find('input');
//将编辑器的值设置为单元格的当前值
console.log('Start Money Val:'+celltxt);//正确显示
editor.val(celltxt);
//选择编辑器时将焦点设置在输入上(超时允许将编辑器添加到DOM)
editor.focus();
//编辑后,触发单元格以更新模糊
编辑。关于(“模糊”,函数(e){
var editval=editor.val();
警报('EditedValue:'+editval);//显示正确
警报('CellID:'+CellID);//显示正确
警报('CellField:'+cellf);//显示正确
var updMonObj=[];
updMonObj['id']=cellid;
updMonObj[cellf]=editval;
$(“”)。制表器(“更新数据”,updMonObj);
$(“”)。制表器(“重画”);
});
警报后,单元格不会更新,当我刷新页面时,新值不会出现。希望单元格更新并显示新值,而不刷新整个表(如果可能)
也希望有一种方式来更新时,他们点击返回
谢谢
更新1:
好的,现在我有了这个(运行v3.2-现在必须坚持使用旧版本):
在列定义中,我认为这应该是可行的:
编辑:《moneyEdit1》;
然后调用制表器,然后再向下:
var moneyEdit1=函数(单元格、onRendered、success、cancel、editorParams){
//定义自定义编辑器
var inpck=$(单元格).find('input').length;
如果(inpck==1){console.log('Input ready Exists');return;}
console.log(“内部资金编辑”);
var mycell=cell.getElement();
log('MyCell:',MyCell);
$(mycell.html($(mycell.find('input'));//删除文本节点
$(迈塞尔)。附加(“”);
变量编辑器=$(mycell.find('input');
//将编辑器的值设置为单元格的当前值
log('Start Money Val:'+celltxt);
editor.val(celltxt);
//选择编辑器时,将焦点设置在输入上
onRendered(函数(){
editor.focus();
editor.style.width=“100%”;
});
//编辑后,触发单元格进行更新
successFunc(函数(){
console.log('Change/Blur/Enter'内部);
var editval=editor.val();
警报('EditedValue:'+editval);
成功(editval);
});
//如果他们用退出键取消
cancelFunc(函数(){
console.log('Cancel'内部);
取消(编辑);
});
editor.addEventListener(“更改”,successFunc);
编辑器。addEventListener(“模糊”,successFunc);
编辑者。addEventListener(“键控”,函数OneEvent(e){
如果(e.which==13){successFunc;}
});
编辑者。addEventListener(“键控”,函数OneEvent(e){
如果(e.which==27){cancelFunc;}
});
//返回编辑器元素
返回编辑器;
}
这看起来应该有效吗?仍然没有调用自定义编辑器,因为我没有看到任何控制台日志,有什么问题吗?您在示例代码中遗漏了该编辑器的函数定义。在中,您将看到有两个函数传递到函数的第三个和第四个参数中,success和取消
var custom editor=函数(单元格、onRendered、成功、取消、editorParams){
//定义自定义编辑器
}
您应该调用这些函数,让制表器知道编辑已成功或已取消
在编辑器中,您不应该调用updateData或redraw函数。相反,您应该调用success函数并将新值传递给它:
success(editval);
只是为了引起您的注意,请创建一个JS提琴来演示这个问题,如果没有看到表的实际操作,很难提供建议
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;
}