【问题标题】:handsontable customizing renderer and numeric format not workingHandsontable 自定义渲染器和数字格式不起作用
【发布时间】:2016-12-03 22:07:48
【问题描述】:

我正在尝试为同一个可动手操作的单元格自定义渲染器和数字格式,但没有成功。指定自定义渲染器或数字格式都可以正常工作,但将两者应用于同一单元格时,数字格式将被忽略。

这是一个演示问题的简单示例代码。没有 cellProperties.renderer = firstRowRenderer; 1.5 正确显示为 1,50 €,而该行显示为 1.5(粗体绿色)。

JSP

<div id="exampleGrid"></div>

Javascript

function firstRowRenderer(instance, td, row, col, prop, value, cellProperties) {
       Handsontable.renderers.TextRenderer.apply(this, arguments);
       td.style.fontWeight = 'bold';
       td.style.color = '#177B57';
       td.style.background = '#CEC';
  }
var contExample = document.getElementById("exampleGrid");
var ExampleHOT;
var language = {
            delimiters: {
                thousands: '.',
                decimal: ','
            },
            abbreviations: {
                thousand: 'k',
                million: 'm',
                billion: 'b',
                trillion: 't'
            },
            ordinal: function (number) {
                return '.';
            },
            currency: {
                symbol: '€'
            }
        };
  if (typeof window !== 'undefined' && this.numeral && this.numeral.language)  {
      this.numeral.language('de', language);
  }  
  function ExampleTable(){
      ExampleHOT = new Handsontable(contExample,{
        data: [ [1.5], [] ],
        rowHeaders: true,
        colHeaders: true,
        cells: function (row, col, prop) {
            var cellProperties = {};
            cellProperties.renderer = firstRowRenderer; // removing this line makes the format work
            cellProperties.type = 'numeric';
            cellProperties.format = '0.00 $';
            cellProperties.language = 'de';

            return cellProperties;
        }
    });}

    ExampleTable();

有没有人找到解决方案? 非常感谢!

【问题讨论】:

    标签: javascript jsp format handsontable renderer


    【解决方案1】:

    你能不能试着改变这一行:

    Handsontable.renderers.TextRenderer.apply(this, arguments);
    

    通过这一行:

    Handsontable.renderers.NumericRenderer.apply(this, arguments);
    

    祝你好运;)

    【讨论】:

    • 即使这个答案已经很老了(3 年),它今天救了我的命,经过几天的寻找。谢谢!
    猜你喜欢
    • 2016-02-03
    • 2013-07-17
    • 2015-03-29
    • 2015-01-01
    • 2020-02-01
    • 2016-04-26
    • 2017-11-06
    • 1970-01-01
    • 2017-01-24
    相关资源
    最近更新 更多