How to keep primefaces rowexpansion open?

后端 未结 3 1339
别那么骄傲
别那么骄傲 2021-01-25 06:20

I have a nested datatable with row expension so far so god, but I want to keep all rows expanded (open) how to achieve this on primefaces?

thanks in advance.

Sor

相关标签:
3条回答
  • 2021-01-25 06:47

    If you want to have your rows collapsed on start:

    <p:headerRow>
      <p:column styleClass="my-class">
        <h:outputText value="#{bean.value}"/>
      </p:column>
    </p:headerRow>
    
    ...
    
    <script>
      $(document).ready(function () {
        $('td.my-class > .ui-rowgroup-toggler').click();
      });
    </script>
    
    0 讨论(0)
  • 2021-01-25 06:56

    Another solution could be:

    <p:commandButton type="button" onclick="jQuery('.ui-row-toggler').click()" value="Expand/Collapse All" />
    
    0 讨论(0)
  • 2021-01-25 07:11

    According to the Primefaces 4.0 documentation:

    p:rowToggler component places an expand/collapse icon, clicking on a collapsed row loads expanded content with ajax. If you need to display a row as expanded by default, use expandedRow attribute which is evaluated before rendering of each row so value expressions are supported.

    To keep all rows open, use it in your datatable like this:

    <p:dataTable value="#{bean.list}" expandedRow="#{true}">
    

    To keep the rows open that were open before an update, you need to:

    • Keep track (server side might be best) of which rows are opened and closed manually (do this via ajax)
    • On (re)loading the p:dataTable you should in the expandedRow attribute put an EL that evaluates the current row it is processing (use the var attribute or the index on the datatable or the rowkey) that returns true for each row that was expanded before.

    Something like this (not fully tested)

    <p:dataTable value="#{bean.list}" var="myRow" expandedRow="#{bean.isExpanded(myRow)}">
    

    Here is the feature request at google code, which was targeted for 3.5.12 and 4.0.

    0 讨论(0)
提交回复
热议问题