首页 > 解决方案 > 出现错误未捕获的错误:尝试在单元格中添加渲染器时单元格类型必须是字符串 Handsontable

问题描述

我有一种情况,我必须根据几个条件在单元格中添加不同的渲染器。所以解决这个问题我已经完成了以下步骤;

makeHighlight(rowNum,colNum, highlightFor = '')
{
  var root = this;
  handsOnTable.updateSettings({
        cells: function (row, col) {

            var cellProperties = {};

            //if for row never cell property set means 
            sheetConfig.cellProperties[row] == undefined
            if(sheetConfig.cellProperties[row] == undefined)
                sheetConfig.cellProperties[row] = [];

            //If row number and column number matches
            if (row == rowNum && col == colNum) {

                if(highlightFor == 'condition1')
                {
                    cellProperties = {
                        type : {
                            renderer : root.renderer1
                        }
                    }
                    sheetConfig.cellProperties[row][col] = cellProperties;
                }
                if(highlightFor == 'condition2')
                {
                    cellProperties = {
                        type : {
                            renderer : root.renderer2
                        }
                    }
                    sheetConfig.cellProperties[row][col] = cellProperties;
                }
                if(highlightFor == 'condition3')
                {
                    cellProperties = {
                        type : {
                            renderer : root.renderer3
                        }
                    }
                    sheetConfig.cellProperties[row][col] = cellProperties;
                }
            }
            else
            {
                if(sheetConfig.cellProperties[row][col] != undefined)
                {
                    cellProperties = sheetConfig.cellProperties[row][col];
                }
            }
            return cellProperties;
        }
    });
 }

现在我的渲染器功能是;

renderer1(instance, td, row, col, prop, value,cellProperties) {
    Handsontable.renderers.TextRenderer.apply(this, arguments);   
    //td.style.background = '#ffff00';
    td.style.background = '#ffff0091';
};

renderer2(instance, td, row, col, prop, value,cellProperties) {
    Handsontable.renderers.TextRenderer.apply(this, arguments);   
    td.style.background = '#FF9999';
};

renderer3(instance, td, row, col, prop, value,cellProperties) 
{
    Handsontable.renderers.TextRenderer.apply(this, arguments);   
    td.style.background = '#FFFF33';
};

现在的问题是我收到一个错误;

未捕获的错误:单元格类型必须是字符串

你能帮我解决我做错了什么吗?我试图弄清楚,但仍然没有运气。

任何帮助对我来说都会很棒。

提前致谢。

标签: javascriptjqueryhandsontable

解决方案


推荐阅读