2 Replies Latest reply on Apr 17, 2012 3:32 AM by sandy4you

    SortBy not working

    pzelenka00

      Hi,

       

      I have problem with dataTable sorting. If I click on any sortable column I always get empty table (zero rows). The reklamaceBean backing bean is request scope. I tried to use a4j:keepAlive but it didn't help.

      Any Idea what is wrong?

       

      Thank

       

      Pavel

       

       

      <rich:dataTable id="reklamacetable" value="#{reklamaceBean.reklamaceList}" binding="#{reklamaceBean.htmlDataTable}" 
                                  var="rekl" rows="20">
                      <f:facet name="caption">
                          <h:outputText value="Toto uvidí inspektor"/>
                      </f:facet>
                      <rich:column sortBy="#{rekl.reklamaceDatum}">
                          <f:facet name="header">
                              <h:outputLabel value="Datum"/>
                          </f:facet>
                          <h:outputText value="#{rekl.reklamaceDatum}">
                              <f:convertDateTime timeZone="Europe/Prague" pattern="dd.MM.yyyy" />
                          </h:outputText>
                      </rich:column>
                      <rich:column sortBy="#{rekl.id}">
                          <f:facet name="header">
                              <h:outputLabel value="ID"/>
                          </f:facet>
                          <h:commandLink value="#{rekl.id}" action="detail">
                              <f:setPropertyActionListener value="#{rekl}" target="#{sessionBean.reklamace}"/>
                          </h:commandLink>
                      </rich:column>
                      <rich:column>
                          <f:facet name="header">
                              <h:outputLabel value="Divize"/>
                          </f:facet>
                          <h:outputText value="#{rekl.okrsek.divize.zkratka}"/>
                      </rich:column>
                      <rich:column>
                          <f:facet name="header">
                              <h:outputLabel value="Okrsek"/>
                          </f:facet>
                          <h:outputText value="#{rekl.okrsek.okrsekKod}"/>
                      </rich:column>
                      <rich:column sortBy="#{rekl.reklamaceKod.CReklamaceNazev}">
                          <f:facet name="header">
                              <h:outputLabel value="Typ"/>
                          </f:facet>
                          <h:outputText value="#{rekl.reklamaceKod.CReklamaceNazev}"/>
                      </rich:column>
                      <rich:column>
                          <f:facet name="header">
                              <h:outputLabel value="Stav"/>
                          </f:facet>
                          <h:outputText value="#{rekl.reklamaceStav.reklamaceStavNazev}"/>
                      </rich:column>
                      <rich:column>
                          <f:facet name="header">
                              <h:outputLabel value="Adresa"/>
                          </f:facet>
                          <h:outputText value="#{rekl.adresa.fullText}"/>
                      </rich:column>
                      <rich:column>
                          <f:facet name="header">
                              <h:outputLabel value="Popis"/>
                          </f:facet>
                          <h:outputText value="#{rekl.reklamaceText}"/>
                      </rich:column>
                      <rich:column>
                          <f:facet name="header">
                          </f:facet>
                          <h:commandLink action="#{reklamaceBean.createVyjadreni}">
                              <f:setPropertyActionListener value="#{rekl}" target="#{sessionBean.reklamace}"/>
                              <h:graphicImage url="/images/edit.gif" style="border: 0" title="Vyjádření"/>
                          </h:commandLink>
                      </rich:column>
                      <f:facet name="footer">
                          <rich:datascroller for="reklamacetable" id="ds" page="#{sessionBean.reklamacePage}"/>
                      </f:facet>
                  </rich:dataTable>
      
      
        • 1. Re: SortBy not working
          pzelenka00

          I found out that the sorting doesn't rerender the table. So it looks like this problem: https://community.jboss.org/message/556418#556418

          • 2. Re: SortBy not working
            sandy4you

            Hi Pavel,

             

            I would suggest you to use <rich:extendedDataTable>.

            And then in the column whch you want to sort as per your requirment you need to write the below code inoder to re-render the table.

            Better you create a composite component like "extTblColHeader" if you are going to use at various places.

             

            I have done the same in the application.

             

            Column Code:

                          

                     

                     <rich:column

                        id="createdOn"

                        rendered="#{not gui:isColumnHidden(cc.attrs.extendedTableBacking.tableState, 'createdOn')}">

                        <f:facet name="header">

                            <comp:extTblColHeader

                                id="createdOnCol"

                                tableCompId="#{cc.attrs.extendedTableBacking.tableId}"

                                sortField="insertedAt"

                                extendedTableBacking="#{cc.attrs.extendedTableBacking}"

                                headerLabel="#{commonTrans['CDM.ui.unicorn.createdOn']}"

                                sortable="#{cc.attrs.sortable}"

                                deleteable="#{cc.attrs.deleteable}" />

                        </f:facet>

                        <h:outputText value="#{rowDTO.serviceRequest.insertedAt}" />

                    </rich:column>

             

            Code in the composite component:

             

                      <h:panelGroup

                           id="mouseOverSortableDeletable"

                           style="position:relative; display:block;"

                           rendered="#{cc.attrs.sortable and cc.attrs.deleteable}">

                           <h:commandLink

                                id="search"

                                action="#{cc.attrs.extendedTableBacking.dataModel.sort}"

                                style="width: 100%; height: 100%; text-decoration: none;">

                                <h:outputText value="#{cc.attrs.headerLabel} " />

                                <h:graphicImage

                                     library="images/tables"

                                     name="sort_#{cc.attrs.extendedTableBacking.dataModel.getSortDirectionLower(cc.attrs.sortField)}.gif" />

                                <f:actionListener

                                     binding="#{cc.attrs.extendedTableBacking.dataModel.sortListener}" />

                                <f:attribute

                                     name="sortColumn"

                                     value="#{cc.attrs.sortField}" />

                                <a4j:ajax

                                     execute="@this"

                                     render=":#{cc.attrs.extendedTableBacking.tableId}:table"

                                     oncomplete="setupHideBtn()" />

                           </h:commandLink>

             

                           <h:commandLink id="hideCol"

                                styleClass="hide_mouse"

                                style="position: absolute; top: 0; right:0; display: none;"

                                action="#{cc.attrs.extendedTableBacking.tableState.noop}">

                                <h:outputText id="hideBtn" value="x" />

                                <f:actionListener

                                     binding="#{cc.attrs.extendedTableBacking.tableState.hideListener}" />

                                <a4j:ajax

                                     execute="@this"

                                     render=":#{cc.attrs.extendedTableBacking.tableId}:table"

                                     oncomplete="setupHideBtn()" />

                           </h:commandLink>

                           <br />

                           <composite:insertChildren />

                      </h:panelGroup>

             

            Hope this helps you.

             

            Cheers,

            Sandy