我有一个PrimeFaces(3.5)数据表,其中包含一些带有
当我单击包含<代码>
这不会发生,当
在我的例子中,以这种方式选择一行是至关重要的,因为通过右键单击要删除的行,可以使用上下文菜单删除一行,与此showcase示例完全相同(该示例运行良好,因为它没有<代码>
已报告此问题,其状态为“WontFix”。他们说,
不支持同时选择单元格和行。
但是,将框架从3.5降级确实可行(因此,上面的引用应该是错误的,似乎被误解了),但这并不是一个解决方案。是否有人遇到此问题?有没有办法改变这种行为?
嗯,已经四年了,还没有修好。但是,您可以使用一些JS魔术来实现它。
首先定义JS函数,该函数按索引选择datatable行:
<script>
function selectCurrentRow(index) {
var table = PF('myTableWidgetVar');
table.unselectAllRows();
table.selectRow(index, false);
}
</script>
然后使用rowIndexVar属性集定义您的可数据对象:
<p:dataTable id="myTable" widgetVar="myTableWidgetVar" var="parameter"
value="#{serviceMB.parameters}"
rowIndexVar="rowIndex"
rowKey="#{parameter.id}"
selectionMode="single"
editMode="cell">
并将cell Editor字段包装在定义了onClick函数的div中:
<p:column>
<p:cellEditor>
<f:facet name="output">
<div onclick="selectCurrentRow(#{rowIndex});">
<p:outputLabel value="#{parameter.value}"/>
</div>
</f:facet>
<f:facet name="input">
<div onclick="selectCurrentRow(#{rowIndex});">
<p:inputText value="#{parameter.value}"/>
</div>
</f:facet>
</p:cellEditor>
</p:column>
如果您使用的是行分组datatable(行索引将被移动),那么这种方法将无法正常工作。
编辑:
如果使用的是行分组数据表,请使用此函数:
function selectByRowKey(rowKey, table) {
for (var i = 0; i < table.rows.length; i++) {
var row = table.rows.get(i);
if (row.getAttribute("data-rk") === rowKey) {
table.unselectAllRows();
table.selectRow(i, false);
break;
}
}
}
其中table=PF('myTableWidgetVar'),rowKey是当前选定的rowKey(例如“\{parameter.id}”)。
USE: style="show: block"在您的单元格中:编辑器,为我工作。
<p:cellEditor>
<f:facet name="output"><h:outputText style="display: block;" value="#{whatever}"/></f:facet>
<f:facet name="input"><p:inputText id=......../></f:facet>
</p:cellEditor>