在pe:sheet中添加自定义单元格渲染器

编程入门 行业动态 更新时间:2024-10-27 18:20:14
本文介绍了在pe:sheet中添加自定义单元格渲染器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试为pe:sheet组件实现自定义单元格渲染器.

I am trying to implement a custom cell renderer to the pe:sheet component.

由于此组件基于Handsontable,因此我尝试了如下所述的方法: handsontable/docs/6.2.2/demo- custom-renderers.html

As this component is based on Handsontable, I tried the approach as described here: handsontable/docs/6.2.2/demo-custom-renderers.html

我还更改了用于从Handsontable.renderers.registerRenderer('myRenderer',myCustomRenderer)进行注册的代码; 到 this.cfg.renderers.registerRenderer('myRenderer',myCustomRenderer); 试图访问pe:sheet中的handsontable实例.

I also changed the code for registering from Handsontable.renderers.registerRenderer('myRenderer', myCustomRenderer); to this.cfg.renderers.registerRenderer('myRenderer', myCustomRenderer); in an attempt to access the instance of handsontable inside pe:sheet.

我正在通过pe:sheet的扩展器属性来调用sheetExtender.

I am calling my sheetExtender via the extender attribute of pe:sheet.

function sheetExtender() { // this.cfg.renderers.registerRenderer('myRenderer', myCustomRenderer); // Handsontable.renderers.registerRenderer('myRenderer', myCustomRenderer); console.log(this); }

var myCustomRenderer = function (instance, td, row, col, prop, value, cellProperties) { $(td).empty().append('TEST'); };

在pe:sheetcolumn的colType属性中添加"myRenderer",我希望列值会被"TEST"覆盖.

Adding 'myRenderer' to the colType attribute of a pe:sheetcolumn, I would expect the column values to be overwritten by 'TEST'.

当我使用'this.cfg ...'时,出现Uncaught TypeError:无法读取未定义的属性'registerRenderer'.

When I use 'this.cfg...' I get an Uncaught TypeError: Cannot read property 'registerRenderer' of undefined.

当我使用"Handsontable ..."时,我没有得到错误,但也没有任何结果,因为我猜想,这种方法可能没有将渲染器添加到handsontable的实际实例中.

When I use 'Handsontable...' I don't get the error, but no results either, as, I guess, this approach propably didn't add the renderer to the actual instance of handsontable.

是否可以在pe:sheet中添加自定义单元格渲染器,或者至少使单元格渲染HTML?

Is there a way to add custom cell renderers in pe:sheet, or at least make a cell render HTML?

推荐答案

我是pe:sheet的作者.如果要自定义渲染器,可以执行以下操作...

I am the author of pe:sheet. If you want to customize the renderer you can do the following...

这是它在组件中发生的位置: github/primefaces-extensions/core/blob/master/src/main/resources/META-INF/resources/primefaces-extensions/sheet/1-sheet.js#L59-L116

This is where it happens in the component: github/primefaces-extensions/core/blob/master/src/main/resources/META-INF/resources/primefaces-extensions/sheet/1-sheet.js#L59-L116

您可以使用自己的默认值覆盖默认的 TextCellRenderer .

You can just override the default TextCellRenderer with your own.

function sheetExtender() { this.cfg.textCellRenderer = function (instance, td, row, col, prop, value, cellProperties) { Handsontable.renderers.HtmlRenderer.apply(this, arguments); // call your custom renderer method here myCustomerRenderer(instance, td, row, col, prop, value, cellProperties); } }

更多推荐

在pe:sheet中添加自定义单元格渲染器

本文发布于:2023-11-23 02:04:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1619696.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   单元格   渲染器   pe   sheet

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!