-
1. Re: Sorting with scrollableDataTable
arielt Jun 30, 2008 3:02 AM (in response to anacarda)Hi.
Here you have a working example, but sorting doesn't work.
After you sort a column, you won't get the corresponding object from the list. If you know how to solve this, please let me know.
xhtml:<rich:scrollableDataTable sortMode="single" rowKey="#{paises.idpais}" rowKeyVar="rkv" frozenColCount="1" height="200px" selection="#{paisesList.selection}" rendered="#{not empty paisesList.resultList}" width="auto" id="sdtPaises" columnClasses="col" var="paises" value="#{paisesList.resultList}" > <rich:column id="idpais" sortable="#{paisesList.sortable}" sortBy="#{paises.idpais}"> <f:facet name="header"><h:outputText styleClass="headerText" value="ID" /></f:facet> <h:outputText value="#{paises.idpais}" /> </rich:column> <rich:column id="descripcion" sortable="true" sortBy=""> <f:facet name="header"><h:outputText styleClass="headerText" value="Descripcion" /></f:facet> <h:outputText value="#{paises.descripcion}" /> </rich:column> <rich:column id="isoNumber" sortable="#{paisesList.sortable}" sortBy="#{paises.isoNumber}"> <f:facet name="header"><h:outputText styleClass="headerText" value="ISO #" /></f:facet> <h:outputText value="#{paises.isoNumber}" /> </rich:column> <rich:column id="iso2Chars" sortable="#{paisesList.sortable}" sortBy="#{paises.iso2Chars}"> <f:facet name="header"><h:outputText styleClass="headerText" value="ISO 2" /></f:facet> <h:outputText value="#{paises.iso2Chars}" /> </rich:column> <rich:column id="iso3Chars" sortable="#{paisesList.sortable}" sortBy="#{paises.iso3Chars}"> <f:facet name="header"><h:outputText styleClass="headerText" value="ISO 3" /></f:facet> <h:outputText value="#{paises.iso3Chars}" /> </rich:column> <rich:column id="caracteristica" sortable="#{paisesList.sortable}" sortBy="#{paises.caracteristica}"> <f:facet name="header"><h:outputText styleClass="headerText" value="Caracteristica" /></f:facet> <h:outputText value="#{paises.caracteristica}" /> </rich:column> </rich:scrollableDataTable> <a4j:commandButton value="Show Current Selection" action="#{paisesList.takeSelection}" />
Bean:@Name("paisesList") public class PaisesList extends EntityQuery<Paises> { private static final long serialVersionUID = 1230800736229942471L; private static final String[] RESTRICTIONS = { "lower(paises.descripcion) like concat(lower(#{paisesList.paises.descripcion}),'%')", "lower(paises.caracteristica) like concat(lower(#{paisesList.paises.caracteristica}),'%')", }; private static final boolean SORTABLE = false; private Paises paises = new Paises(); private SimpleSelection selection = new SimpleSelection(); public SimpleSelection getSelection() { return selection; } public void setSelection(SimpleSelection selection) { this.selection = selection; } private List<Paises> selectedPaises = new ArrayList<Paises>(); public List<Paises> getSelectedPaises() { return selectedPaises; } public void setSelectedPaises(List<Paises> selectedPaises) { this.selectedPaises = selectedPaises; } public String takeSelection() { getSelectedPaises().clear(); Iterator<SimpleRowKey> iterator = getSelection().getKeys(); while (iterator.hasNext()) { SimpleRowKey key = iterator.next(); System.out.println("key: " + key.intValue()); getSelectedPaises().add(getResultList().get(key.intValue())); } System.out.println("Mostrando paises seleccionados:"); for (Paises p : getSelectedPaises()) { System.out.println(p); } System.out.println("Fin Mostrando paises seleccionados"); return null; } @Override public String getEjbql() { return "select paises from Paises paises"; } @Override public Integer getMaxResults() { return 50; } public Paises getPaises() { return paises; } @Override public List<String> getRestrictions() { return Arrays.asList(RESTRICTIONS); } public boolean isSortable() { return SORTABLE; } }
-
2. Re: Sorting with scrollableDataTable
arielt Jul 3, 2008 2:50 AM (in response to anacarda)Sorry I expressed myself wrong.
Sorting WORKS but, Selection AFTER Sorting does not work.Seems like the solution is this (see code below) but I can't make the binding to UIScrollableDataTable work.
public String takeSelection() { getSelectedPaises().clear(); Iterator<Object> iterator = getSelection().getKeys(); while (iterator.hasNext()){ Object key = iterator.next(); table.setRowKey(key); if (table.isRowAvailable()) { getSelectedPaises().add((Paises) table.getRowData()); } } System.out.println("Mostrando paises seleccionados:"); for (Paises p : getSelectedPaises()) { System.out.println(p); } System.out.println("Fin Mostrando paises seleccionados"); return null; }
-
3. Re: Sorting with scrollableDataTable
nathandennis Dec 30, 2008 8:52 PM (in response to anacarda)did you ever get that binding to work? im having the same trouble.
-
4. Re: Sorting with scrollableDataTable
dxxvi Feb 28, 2009 12:38 PM (in response to anacarda)Did the SimpleSelection work for you? It doesn't for me. If it works for you, could you please send me an example? My email address is dxxvi at dangvufirm dot com.
Thank you.
-
5. Re: Sorting with scrollableDataTable
dxxvi Feb 28, 2009 12:40 PM (in response to anacarda)Did you ever get that SimpleSelection work? I don't. If it works for you, could you please send me an example? My email address is dxxvi at dangvufirm dot com.
Thank you.
-
6. Re: Sorting with scrollableDataTable
nagendra_singh_krishnawat Aug 21, 2009 3:54 AM (in response to anacarda)Did selection worked you you guys, it never worked for me, beside it gives a javascript err on load. I am using seam 3.3.1 which is almost latest version.
-
7. Re: Sorting with scrollableDataTable
nagendra_singh_krishnawat Aug 21, 2009 3:55 AM (in response to anacarda)Can anyone give me a working code of this.
-
8. Re: Sorting with scrollableDataTable
tzelve Jul 30, 2010 3:12 AM (in response to anacarda)I found a way to have correct selections and sorting with scrollableDataTable. The value property point to a property of extended type org.richfaces.model.ScrollableTableDataModel. In your class (witch extends org.richfaces.model.ScrollableTableDataModel) you must implement both getId and reverse getObjectById with a id for line (in my project i use the index position in the original List). After this the selection returns to you the correct list of selected id and sorting working correct.