手控表 - 文本在数字单元格上对齐

Handsontable - text align on numeric cells

本文关键字:数字 单元格 对齐 文本      更新时间:2023-09-26

我正在使用handsontable在类似MVC Excel的应用程序 ASP.NET 编辑数字数据。我通过以下代码设置单元格格式:

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: '€'
    }
});
var container = document.getElementById('hot');
var workflowActionType = '@ViewBag.WorkflowActionType';
var hot = new Handsontable(container,
{
    data: data,
    maxRows: 32,
    colWidths: [500, 60, 100, 100, 100, 100],
    cells: function (row, col, prop) {
        var cellProperties = {};
        cellProperties.type = "numeric";
        cellProperties.format = '0.00';
        cellProperties.language = 'ru';
        if (row === 0) {
            cellProperties.renderer = headerRowRenderer;
            cellProperties.readOnly = true;
        }
        if (col === 0 && (row !== 0 || row !== 1)) {
            cellProperties.readOnly = true;
        }
        if (row === 1) {
            cellProperties.renderer = numberRowRenderer;
            cellProperties.readOnly = true;
        }
        if (col === 1 && row !== 0 && row !== 1) {
            cellProperties.renderer = rowCodeRenderer;
            cellProperties.readOnly = true;
        }
        if ((col === 2 || col === 3 || col === 4 || col === 5) && 
            (row === 0 || row === 1)) {
            cellProperties.readOnly = true;
        }
        return cellProperties;
    }
});

由此行设置的数字格式:

cellProperties.type = "numeric";  
cellProperties.format = '0.00';  
cellProperties.language = 'ru';  

之后,在本地开发环境(由Visual Studio运行的IIS Express)上,所有数字都对齐正确。但在生产服务器上 - 所有数字都左对齐。我做错了什么?

问题已解决。

由开发和生产服务器上的不同区域设置导致的不同数字呈现。在开发计算机上,DB 使用点 "." 作为小数分隔符,在生产服务器上,DB 使用逗号 ","作为小数分隔符。通过设置正确的区域设置重新创建生产数据库来解决。