在我的 p:column 中,我有几个带有文本的 div,如果我单击文本,它不会选择该行,也不会调用 rowSelect 事件。
示例:
...
<p:column>
text1
<div>text2</div>
<p:column>
...
我可以单击text1,但不能单击text2。问题出在哪里?
最佳答案
问题是 div 覆盖了列的 onclick 事件。我遇到了这个问题,我的解决方案是使用以下函数覆盖 div 上的事件:
XHTML:
<p:datatable ..(properties)... widgetVar="dt" rowIndexVar"rowIndex" ...>
.......
<p:column>
<div onclick="selectCurrentRow(dt,#{rowIndex});" > hola </div>
</p:column>
.......
<p:datatable/>
JS:
function selectCurrentRow_paginator(table,index){
table.unselectAllRows();
table.selectRow(index-(table.paginator.cfg.page*table.paginator.cfg.rows) ,false);
}
function selectCurrentRow(table,index){
table.unselectAllRows();
table.selectRow(index ,false);
}
如果 JS 说 dt 未定义,只需用 PF() 函数包围 wingetVar 名称,如下所示:
<div onclick="selectCurrentRow(PF('dt'),#{rowIndex});" > hola </div>
此解决方案也有助于 oncontextmenu 事件:
<div oncontextmenu="selectCurrentRow(PF('dt'),#{rowIndex});" onclick="selectCurrentRow(PF('dt'),#{rowIndex});" > hola </div>
关于jsf-2 - Primefaces:单击 p:column 内的 div 时不会调用 rowSelect 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21338440/