本文介绍了自定义渲染器功能在Handsontable插件中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个处理某些onChange事件并运行良好的函数.该函数调用另一个函数来检查单元格的内容,如果有问题,则应更改单元格的颜色.

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;
}

这是我简单的ErrorRenderer:

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';
}

即使触发了警报,也永远不会调用ErrorRenderer,知道为什么吗?

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

谢谢

推荐答案

如果您使用handontable,为什么不使用其内置功能?

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

看看HTs 条件格式

此外,在0.9.5版中,添加了列选项validator.详细信息此处.

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

validator (value: Mixed, callback: Function) 

validator : RegExp Object

然后使用事件(详细信息此处):

Then using the event (details here):

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

对单元格进行格式化

此外,在您的示例中,您正在设置渲染器,但是实际上正在渲染单元格吗?您需要重新渲染吗?

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

这篇关于自定义渲染器功能在Handsontable插件中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 22:43