覆盖来自 Primefaces 特定小部件的方法 [英] Override a method from a Primefaces specific widget

查看:30
本文介绍了覆盖来自 Primefaces 特定小部件的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想覆盖 Primefaces 数据表组件的功能.根据这个问题:如何基于 widgetVar 在 Primefaces 组件中查找和/或覆盖 JavaScript? 可以使用 PrimeFaces.widget.DataTable.prototype..但我只想为一个数据表覆盖此函数,而不是为所有数据表覆盖.

I want to overwrite a function of Primefaces datatable component. According to this question: How do I find and/or override JavaScript in Primefaces component based on widgetVar? it is possible by using PrimeFaces.widget.DataTable.prototype.. But I want to override this function for one datatable only, not for all.

这不起作用:

<p:dataTable widgetVar="myTable" ...>
</p:dataTable>
....
<script type="text/javascript">
       $(document).ready(function(){
           if (PF('myTable') !== undefined) {
                PF('myTable').jq.datatable({
                     showCellEditor: function (c) {
                         console.log('my function');
                     }
                 });
            }
         });
</script>

这是应该怎么做还是我完全错了?

Is this how it is supposed to be done or am I completely wrong?

推荐答案

用我的一张桌子测试过:

Tested with one of my tables:

PF('myTable').showCellEditor = function() {
    console.log('my function')
}

如果需要,不要忘记调用通用实现:

Don't forget to call the generic implementation if you need to:

PF('myTable').showCellEditor = function() {
    console.log('my function')
    // call the generic implementation:
    PrimeFaces.widget.DataTable.prototype.showCellEditor.call(this);
}

另见:

这篇关于覆盖来自 Primefaces 特定小部件的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆