【问题标题】:Tabulator - Update Value of Custom Editor for Money Column制表符 - 更新货币列自定义编辑器的值
【发布时间】: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


    【解决方案1】:

    您在示例代码中错过了该编辑器的函数定义。在Editor Documentation 中,您将看到有两个函数传递到函数的第三个和第四个参数中,successcancel

    var custom editor = function(cell, onRendered, success, cancel, editorParams){
       //define custom editor
    }
    

    您应该调用这些函数让制表员知道编辑已成功或已被取消。

    在您的编辑器中,您不应该调用 updateDataredraw 函数。相反,您应该调用 success 函数并将新值传递给它:

    success(editval);
    

    【讨论】:

    • 只是为了引起你的注意。
    • 请创建一个演示问题的 JS 小提琴,如果没有看到实际的表格,很难提供建议
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-12-10
    • 1970-01-01
    • 2012-02-22
    • 2012-07-21
    • 2011-03-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多