How to sort and disarray a JSF datatable by clicking on the column?

Asked

Viewed 2,195 times

0

Good guys, I have an application in JSF, I would like to know how to sort and disorganize datatable when clicking the column, in this table there are 6 columns and 3 of them I would like to click it sort according to the column clicked?

*demand consultation

  • You will probably want to use Collection.Sort() on your bean. But you can do this in several ways, below are some examples including sample code for download. This example here should fit better in your demand query case http://uaihebert.com/paginacao-de-datatable-lazy-com-jsf-primefaces/ http://www.mkyong.com/jsf2/jsf-datatable-sorting-example/ http://www.guj.com.br/java/42554-jsf-order-datatable

  • 1

    what exactly would it be desordenar? do you want to leave your lines random? what difficulty are you having? could show the relevant part of your code?

  • SORT: crescent: 123456 decreasing: 654321 DISORDER: 643521

  • The clutter part gets a little complicated using the "sortBy" of the "primefaces". You would have to implement the sorting methods themselves and generate, among the possible values, random lines.

1 answer

4

If you are using or can use Primefaces, just include the "sortBy" property in your column

<p:dataTable value="#{testeMB.objetos}" var="o">
  <p:column headerText="Nome" sortBy="#{o.nome}">
    #{o.nome}
  </p:column>
</p:dataTable>
  • I note only that the "objects" must be an attribute of a class (including Managed or Named) and not just a method that returns the list of objects.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.