【问题标题】:Handsontable - can't set thousand separator for custom cellHandsontable - 无法为自定义单元格设置千位分隔符
【发布时间】:2015-09-14 21:52:18
【问题描述】:

我正在使用 Handsontable 库来编辑包含财务数据的电子表格。 我设置了自定义数字格式,使用''(空格)作为千位分隔符。

numeral.language('ru', {
    delimiters: {
        thousands: ' ',
        decimal: ','
    },
    abbreviations: {
        thousand: 'k',
        million: 'm',
        billion: 'b',
        trillion: 't'
    },
    ordinal: function (number) {
        return number === 1 ? 'er' : 'ème';
    },
    currency: {
        symbol: '€'
    }
});

一切正常,但在某些(使用自定义颜色和文本对齐)单元格中,此设置不起作用。怎么了?

用于设置颜色和对齐的自定义单元格渲染器:

function sumCellRenderer(instance, td, row, col, prop, value, cellProperties) {
    Handsontable.renderers.TextRenderer.apply(this, arguments);
    td.style.background = '#FFFF88';
    td.style.textAlign = 'right';      
}

http://jsfiddle.net/m2dxws5a/7/ 的工作示例

底部的自定义单元格用黄色标记。

【问题讨论】:

    标签: javascript css numeric handsontable


    【解决方案1】:

    当您应用自定义渲染器时,您会覆盖渲染器的类型,因此必须自行设置。如果您查看您的代码,您正在使用TextRenderer,并且您现在可能已经猜到了,这将呈现text。在 Handsontable 中,数字是 numeric 类型,关联的渲染器是 NumericRenderer。所以,解决方案:

    替换

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

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

    之后应该可以工作了!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-19
      • 1970-01-01
      相关资源
      最近更新 更多