Ordering rows in Grid components

As you can guess, ordering (or sorting) is another task that should be delegated to the backend services when possible. Moreover, it is most likely required when you are implementing pagination (that is, lazy loading using limit and offset parameters) in the backend service as well.

The service method should include a parameter that specifies how to perform the ordering. The Grid component allows users to click on the column headers to activate ordering by that column. These columns that need ordering are passed to the DataProvider in a Query object. You can get these by calling the Query.getSortOrders() method, which returns a List of QuerySortOrder objects. You could pass this List to the service method, but it's always a good idea to avoid coupling the backend services with frontend technologies. QuerySortOrder is a class included in Vaadin Framework, so you would need to include Vaadin dependencies in your backend services if they are deployed in a separate artifact, for example. To avoid this coupling, we can implement a utility method that converts between QuerySortOrder objects to framework-independent objects. In the backend services, we can use a Map<String, Boolean>, where the key is a String containing the name of the property, and the value is a Boolean that tells the method whether to order in an ascending mode or not.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset