10 Replies Latest reply on Feb 23, 2011 4:40 AM by almar

    Clear Sorting in dataTable or extendedDataTable without modi

    Markus Meijer Newbie

      Hey together,

      I hope somebody can help me with this.
      I need a possibility to clear the user-defined sorting (selfSorted=true). I don't want to change the about 40 tables I created so far and I don't want to write a modifiable class only for this purpose either. Everything else works perfectly.

      I tried to setSortFields of the bound variable to null and to change the ordering property of sortFields.get(0) but nothing happens...

      Thanks in advance.

        • 1. Re: Clear Sorting in dataTable or extendedDataTable without
          Ilya Shaikovsky Master

          map column sortOrder's to some bean properties and reset them to unsorted when need.

          • 2. Re: Clear Sorting in dataTable or extendedDataTable without
            Markus Meijer Newbie

             

            "ilya_shaikovsky" wrote:
            map column sortOrder's to some bean properties and reset them to unsorted when need.


            Thanks for your fast answer.
            Is there no way to do it more "central" without modifying each column? In this way I would have to change up to 50 column entries.

            • 3. Re: Clear Sorting in dataTable or extendedDataTable without
              Ilya Shaikovsky Master

              Very simplified example:
              (seems what you need.. just parametrize reset call instead of hardcode usage)

               <h:form id="form">
               <rich:dataTable value="#{capitalsBean.capitals}" var="cap" width="300px" columnClasses="center"
               rows="15" reRender="ds" id="simpleSortingTable">
               <f:facet name="header">
               <h:outputText value="Sorting Example"/>
               </f:facet>
               <rich:column sortBy="#{cap.state}">
               <f:facet name="header">
               <h:outputText value="State Name"/>
               </f:facet>
               <h:outputText value="#{cap.state}"/>
               </rich:column>
               <rich:column sortBy="#{cap.name}">
               <f:facet name="header">
               <h:outputText value="State Capital"/>
               </f:facet>
               <h:outputText value="#{cap.name}"/>
               </rich:column>
               <rich:column>
               <f:facet name="header">
               <h:outputText value="Time Zone"/>
               </f:facet>
               <h:outputText value="#{cap.timeZone}"/>
               </rich:column>
               <f:facet name="footer">
               <rich:datascroller id="ds"></rich:datascroller>
               </f:facet>
               </rich:dataTable>
               <a4j:commandButton ajaxSingle="true" reRender="simpleSortingTable" action="#{capitalsBean.resetSorting}"></a4j:commandButton>
               </h:form>
              

               public void resetSorting() {
               UIDataTable table = (UIDataTable)FacesContext.getCurrentInstance().getViewRoot().findComponent("form:simpleSortingTable");
               for (UIComponent column : table.getChildren()) {
               ((UIColumn)column).setSortOrder(Ordering.UNSORTED);
               }
               }
              


              • 4. Re: Clear Sorting in dataTable or extendedDataTable without
                Markus Meijer Newbie

                This would be a great solution!
                But I get a NullPointerException clicking the button!

                • 5. Re: Clear Sorting in dataTable or extendedDataTable without
                  Ilya Shaikovsky Master

                  just check the method execution in debug.

                  • 6. Re: Clear Sorting in dataTable or extendedDataTable without
                    Markus Meijer Newbie

                     

                    
                    [...]
                    
                     <body id="appBody" style="font-weight:normal">
                     <h:form binding="#{DataMBean.form}" id="awau57DataForm">
                    
                    [...]
                    
                     <div class="tableFrame">
                     <rich:dataTable reRender="hscroll" value="#{DataMBean.daten}"
                     var="entry" id="awau57Table">
                     <rich:column sortable="true" sortBy="#{entry.smand}">
                     <f:facet name="header">
                     <h:outputText value="#{mast._Mand}"/>
                     </f:facet>
                     <h:outputText value="#{entry.smand}"/>
                     </rich:column>
                     <rich:column sortable="true" sortBy="#{entry.swerk}">
                     <f:facet name="header">
                     <h:outputText value="#{mast._Werk}"/>
                     </f:facet>
                     <h:outputText value="#{entry.swerk}"/>
                     </rich:column>
                     <rich:column sortable="true" sortBy="#{entry.sabt}">
                     <f:facet name="header">
                     <h:outputText value="#{DataMBean.sabt}"/>
                     </f:facet>
                     <h:outputText value="#{entry.sabt}"/>
                     </rich:column>
                     <rich:column sortable="true" sortBy="#{entry.skst}">
                     <f:facet name="header">
                     <h:outputText value="#{DataMBean.skst}"/>
                     </f:facet>
                     <h:outputText value="#{entry.skst}"/>
                     </rich:column>
                     <rich:column sortable="true" sortBy="#{entry.sfullname}" style="#{entry.scolorstyle}">
                     <f:facet name="header">
                     <h:outputText value="#{mast._Name}"/>
                     </f:facet>
                     <h:outputText value="#{entry.sfullname}"/>
                     </rich:column>
                     <rich:column sortable="true" sortBy="#{entry.spers}">
                     <f:facet name="header">
                     <h:outputText value="#{mast._Pers}"/>
                     </f:facet>
                     <h:outputText value="#{entry.spers}"/>
                     </rich:column>
                     <rich:column sortable="true" sortBy="#{entry.drestAnspVJ}" style="text-align:right">
                     <f:facet name="header">
                     <h:outputText value="#{mast._RestAnspVJ}"/>
                     </f:facet>
                     <h:outputText value="#{entry.srestanspvj}" />
                     </rich:column>
                     <rich:column sortable="true" sortBy="#{entry.danspruch}" style="text-align:right">
                     <f:facet name="header">
                     <h:outputText value="#{mast._AnspruchUrl}"/>
                     </f:facet>
                     <h:outputText value="#{entry.sanspruch}" />
                     </rich:column>
                     <rich:column sortable="true" sortBy="#{entry.dgenom}" style="text-align:right">
                     <f:facet name="header">
                     <h:outputText value="#{mast._Genom}"/>
                     </f:facet>
                     <h:outputText value="#{entry.sgenom}"/>
                     </rich:column>
                     <rich:column sortable="true" sortBy="#{entry.dgeplant}" style="text-align:right">
                     <f:facet name="header">
                     <h:outputText value="#{mast._Geplant}"/>
                     </f:facet>
                     <h:outputText value="#{entry.sgeplant}" />
                     </rich:column>
                     <rich:column sortable="true" sortBy="#{entry.ddiff}" width="60" style="text-align:right">
                     <f:facet name="header">
                     <h:outputText value="+/-"/>
                     </f:facet>
                     <h:outputText value="#{entry.sdiff}" />
                     </rich:column>
                     <rich:column sortable="true" sortBy="#{entry.drestLfd}" style="text-align:right">
                     <f:facet name="header">
                     <h:outputText value="#{mast.RestLfd}"/>
                     </f:facet>
                     <h:outputText value="#{entry.srestlfd}" />
                     </rich:column>
                     <rich:column sortable="true" sortBy="#{entry.drestStichtag}" style="text-align:right" visible="#{DataMBean.bshowrest}">
                     <f:facet name="header">
                     <h:outputText value="#{mast._ResturlaubTg}"/>
                     </f:facet>
                     <h:outputText value="#{entry.sreststich}" />
                     </rich:column>
                     <rich:column sortable="true" sortBy="#{entry.drestVor}" style="text-align:right">
                     <f:facet name="header">
                     <h:outputText value="#{mast.RestVor}"/>
                     </f:facet>
                     <h:outputText value="#{entry.srestvor}" />
                     </rich:column>
                    
                     <f:facet name="footer">
                     <rich:datascroller for="awau57Table" align="left" id="hscroll"
                     maxPages="10"
                     page="#{DataMBean.ipagegrid}" />
                     </f:facet>
                     </rich:dataTable>
                    
                     <a4j:commandButton ajaxSingle="true" reRender="awau57Table" action="#{DataMBean.resetTableSorting}"></a4j:commandButton>
                    
                    
                     </div>
                     </div>
                     </h:form>
                     </body>
                    
                    [...]
                    
                    



                    DataMBean:

                    
                     public void resetTableSorting() {
                    
                     UIDataTable table = (UIDataTable)FacesContext.getCurrentInstance().getViewRoot().findComponent("awau57DataForm:awau57Table");
                     System.out.println(table==null);
                     for (UIComponent column : table.getChildren()) {
                     ((UIColumn)column).setSortOrder(Ordering.UNSORTED);
                     }
                     }
                    
                    


                    • 7. Re: Clear Sorting in dataTable or extendedDataTable without
                      Markus Meijer Newbie

                      Works!!!
                      Thank you very much!!!

                      • 8. Re: Clear Sorting in dataTable or extendedDataTable without
                        Markus Meijer Newbie

                        I'm sorry. Another problem: if i try to call the reset method not at button click but in the constructor of the bean, I get an exception. Is there a way to call it if moved to this site? Further the table must then be rerendered I think...

                        • 9. Re: Clear Sorting in dataTable or extendedDataTable without
                          Markus Meijer Newbie

                           

                          "marmei2" wrote:
                          I'm sorry. Another problem: if i try to call the reset method not at button click but in the constructor of the bean, I get an exception. Is there a way to call it if moved to this site? Further the table must then be rerendered I think...


                          Problem solved. Thanks anyway.

                          • 10. Re: Clear Sorting in dataTable or extendedDataTable without
                            almar Newbie

                            Don't forget to reset the sort priority when using 'sortMode="multi"'. Add following line to Ilya's sollution.

                             

                             

                            table.getSortPriority().clear();