我想覆盖 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>
这是应该的做法还是我完全错了?
最佳答案
用我的一张 table 测试过:
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);
}
另请参阅:
关于javascript - 覆盖 Primefaces 特定小部件的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39639532/