Preparing the backend for lazy loading
Lazy loading (and filtering) capabilities should be delegated to the backend as much as possible. Although the Grid
class itself is able to cache some of the data and send it to the client only when needed, it cannot prevent you from querying the whole database, for example. In order to support lazy loading, backend services should provide the means to lazily load the data.
Typically, the UI gets the data from a service or repository class. Let's see an example of how a repository class can provide methods with lazy loading capabilities. The CallRepository
class could define a findAll
method that queries a slice of the rows in the Call
table, as follows:
public class CallRepository { public static List<Call> findAll(int offset, int limit) { ... } public static int count() { ... } }
In the previous code, limit
is used to limit the number of rows (actually, instances of User
) that should be returned. When using SQL...