覆盖 Primefaces 特定小部件的方法

Override a method from a Primefaces specific widget

我想覆盖 Primefaces 数据表组件的一个功能。根据这个问题:How do I find and/or override JavaScript in Primefaces component based on widgetVar? 可以使用 PrimeFaces.widget.DataTable.prototype.。但是我只想为一个数据表覆盖这个函数,而不是为所有数据表覆盖。

这不起作用:

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

这是应该的做法还是我完全错了?

用我的一张桌子测试过:

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

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

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

另请参阅: