1 Reply Latest reply on Feb 14, 2011 7:32 AM by meierhans

    Having multiple datagrids share the same state

    meierhans

      Hi,

      I have a tabPanel, some of the tabs need a datagrid for navigation purposes. Sometimes this datagrid is on a rich:modalPanel, somtimes directly on a tab. The datagrids need to have sortMode="multi". The problem is, once I change the sort of one datagrid (user clicks some column headers), then I need exactly the same sort setting on all the other datagrids as well. I have bound them all to the same datamodel, but the datamodel is always modified according to the state of the currently displayed datagrid. That sucks, because the datamodel jumps between the different states of the grids.

       

      So I need either a way to transfer the settings between the datagrids or I need to use the same datagrid with the same state everywhere, even on the modalPanels. Is that even possible with richfaces?

        • 1. Having multiple datagrids share the same state
          meierhans

          This is how I did it: I created a CustomSorter class like this:

           

          public class CustomSorter

          {

              private Ordering columnFirstNameSortOrder = Ordering.UNSORTED;

              private Ordering columnLastNameSortOrder = Ordering.UNSORTED;

           

           

              private Collection<String> sortPriorities = new Vector<String>();

           

              public void clearSort()

              {

                  this.sortPriorities.clear();

                  this.setColumnFirstNameSortOrder(Ordering.UNSORTED);

                  this.setColumnLastNameSortOrder(Ordering.UNSORTED);

                  /* ... */

           

           

              }

          }

           

          Then I bound my columns sortOrder attribute to these values and the sortPriority attribute of the grids to the sortPriorities member.

           

                  <rich:dataTable

                      id="aDataGrid1"

                      var="item"

                      value="#{bean.model}"

                      rows="#{bean.model.pageSize}"

                      sortMode="multi"

                      sortPriority="#{customSorter.sortPriorities}"

                      reRender="aDataGrid1, aDataGrid2, aDataGrid3"

                  >

                     

                   <rich:column id="columnFirstName" sortable="true" sortBy="#{item.firstName}" sortOrder="#{customSorter.columnFirstNameSortOrder}" filterBy="#{item.firstName}" >

                          <f:facet name="header">

                              <h:outputText value="First Name" />

                          </f:facet>

                          <h:outputText value="#{item.firstName}" />

                      </rich:column>

           

                   <rich:column id="columnLastName" sortable="true" sortBy="#{item.lastName}" sortOrder="#{customSorter.columnLastNameSortOrder}" filterBy="#{item.lastName}" >

                          <f:facet name="header">

                              <h:outputText value="Last Name" />

                          </f:facet>

                          <h:outputText value="#{item.lastName}" />

                      </rich:column>

          </rich:dataTable>

           

           

          This works! The solution was simple. I dunno why I tried so hard before.