展开Datatable JSF中表行的折叠

Nru*_*gha 2 datatable jsf expand collapse

我一直在尝试使用核心JSF实现表行扩展/折叠的功能,并且我还必须保留排序.在核心JSF中有没有办法实现这个功能?

Bal*_*usC 5

如果您在使用仅参考实现坚持,那么你就不能使用嵌套到处去h:dataTable和/或h:panelGroup良好的 CSS的杆拿到好听对齐.然后,您可以使用JavaScript以智能方式显示/隐藏行详细信息.

这是一个基本的启动示例:

<h:dataTable value="#{bean.orders}" var="order">
    <h:column>
        <h:panelGrid columns="3">
            <h:graphicImage id="expand" value="expand.gif" onclick="toggleDetails(this);" />
            <h:outputText value="#{order.id}" />
            <h:outputText value="#{order.name}" />
        </h:panelGrid>
        <h:dataTable id="details" value="#{order.details}" var="detail" style="display: none;">
            <h:column><h:outputText value="#{detail.date}" /></h:column>
            <h:column><h:outputText value="#{detail.description}" /></h:column>
            <h:column><h:outputText value="#{detail.quantity}" /></h:column>
        </h:dataTable>
    </h:column>
</h:dataTable>
Run Code Online (Sandbox Code Playgroud)

toggleDetails()函数可能看起来像(注意它需要考虑JSF生成的客户端ID):

function toggleDetails(image) {
    var detailsId = image.id.substring(0, image.id.lastIndexOf(':')) + ':details';
    var details = document.getElementById(detailsId);
    if (details.style.display == 'none') {
        details.style.display = 'block';
        image.src = 'collapse.gif';
    } else {
        details.style.display = 'none';
        image.src = 'expand.gif';
    }
}
Run Code Online (Sandbox Code Playgroud)