Custom renderer function not working in handsontable plugin

只谈情不闲聊 提交于 2019-12-11 08:57:23

问题


I have a function that handles some onChange events and works well. That function calls another one to check for the contents of the cell, and if there is something wrong it should change the cell color.

function Check(x, y)
{
    var content =   $editorTableContainer.handsontable('getDataAtCell', y, x);
    var split   =   content.split(' ');    

    $.each(split, function (key, value) {
        $.get('check.php?word=' + value, function (data) {
            //blank if no error otherwise it returns an array of suggestions (only need to check if there is an error)
            if (data) {
                alert("test");
                var meta = $editorTableContainer.handsontable('getCellMeta', y, x);
                meta.renderer = ErrorRenderer;
            }
        });
    });

    return;
}

And here is my simple ErrorRenderer:

function ErrorRenderer(instance, td, row, col, prop, value, cellProperties)
{
  Handsontable.TextCell.renderer.apply(this, arguments);
  console.log(row);
  td.style.fontWeight = 'bold';
  td.style.color = 'green';
  td.style.background = '#CEC';
}

The ErrorRenderer is never called, eventhough the alert is triggered, any idea why?

Thank you


回答1:


If you are using handsontable, why don't you use its built in functionality?

Have a look at HTs conditional formatting

Also, in version 0.9.5 a column option was added validator. Details here.

validator (value: Mixed, callback: Function) 

or

validator : RegExp Object

Then using the event (details here):

afterValidate (isValid: Boolean, value: Mixed, row: Number, prop: String, source: String) 

do the formatting of the cell

Also, in your example, you are setting the renderer, but is the cell actually being rendered? Do you need to re-render?




回答2:


I can see that your renderer is for TextCell.. it would work for only text cell, check that error Renderer should work for TextCell or NumericCell



来源:https://stackoverflow.com/questions/17721500/custom-renderer-function-not-working-in-handsontable-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!