我正在尝试为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中添加自定义单元格渲染器
发布评论