You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

sqlcontainer-filteringsorting.asciidoc 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. ---
  2. title: Filtering and Sorting
  3. order: 3
  4. layout: page
  5. ---
  6. [[sqlcontainer.filteringsorting]]
  7. = Filtering and Sorting
  8. Filtering and sorting the items contained in an SQLContainer is, by design,
  9. always performed in the database. In practice this means that whenever the
  10. filtering or sorting rules are modified, at least some amount of database
  11. communication will take place (the minimum is to fetch the updated row count
  12. using the new filtering/sorting rules).
  13. [[sqlcontainer.filteringsorting.filtering]]
  14. == Filtering
  15. Filtering is performed using the filtering API in Vaadin, which allows for very
  16. complex filtering to be easily applied. More information about the filtering API
  17. can be found in
  18. <<dummy/../../../framework/datamodel/datamodel-container#datamodel.container.filtered,"Filterable
  19. Containers">>.
  20. In addition to the filters provided by Vaadin, SQLContainer also implements the
  21. [classname]#Like# filter as well as the [classname]#Between# filter. Both of
  22. these map to the equally named WHERE-operators in SQL. The filters can also be
  23. applied on items that reside in memory, for example, new items that have not yet
  24. been stored in the database or rows that have been loaded and updated, but not
  25. yet stored.
  26. The following is an example of the types of complex filtering that are possible
  27. with the new filtering API. We want to find all people named Paul Johnson that
  28. are either younger than 18 years or older than 65 years and all Johnsons whose
  29. first name starts with the letter "A":
  30. ----
  31. mySQLContainer.addContainerFilter(
  32. new Or(new And(new Equal("NAME", "Paul"),
  33. new Or(new Less("AGE", 18),
  34. new Greater("AGE", 65))),
  35. new Like("NAME", "A%")));
  36. mySQLContainer.addContainerFilter(
  37. new Equal("LASTNAME", "Johnson"));
  38. ----
  39. This will produce the following WHERE clause:
  40. ----
  41. WHERE (("NAME" = "Paul" AND ("AGE" < 18 OR "AGE" > 65)) OR "NAME" LIKE "A%") AND "LASTNAME" = "Johnson"
  42. ----
  43. [[sqlcontainer.filteringsorting.sorting]]
  44. == Sorting
  45. Sorting can be performed using standard Vaadin, that is, using the sort method
  46. from the [classname]#Container.Sortable# interface. The [parameter]#propertyId#
  47. parameter refers to column names.
  48. ----
  49. public void sort(Object[] propertyId, boolean[] ascending)
  50. ----
  51. In addition to the standard method, it is also possible to directly add an
  52. [classname]#OrderBy# to the container via the [methodname]#addOrderBy()# method.
  53. This enables the developer to insert sorters one by one without providing the
  54. whole array of them at once.
  55. All sorting rules can be cleared by calling the sort method with null or an
  56. empty array as the first argument.