...
Code Block | ||||
---|---|---|---|---|
| ||||
<component type="grid" name="orderGroups" reference="grid">
<option type="column" name="number" fields="number" link="true" />
<option type="column" name="name" fields="name" link="true" />
<!-- suggested option for an column from a custom dataset, the main entity must always be in the 0 column index -->
<option type="column" name="ordersCount" datasetColumIndex="1" />
<option type="column" name="dateFrom" fields="dateFrom" />
<option type="column" name="dateTo" fields="dateTo" />
<option type="order" column="name" direction="asc" />
<option type="correspondingView" value="orderGroups/orderGroupDetails" />
<option type="correspondingComponent" value="form" />
<option type="searchable" value="name,number,dateFrom,dateTo" />
<option type="orderable" value="name,number,dateFrom,dateTo" />
<option type="fullscreen" value="true" />
<option type="multiselect" value="true" />
</component>
|
Code Block | ||
---|---|---|
| ||
loadOrderGroups(viewState) { grid = viewState.getComponentByReference("orderGroupsGrid"); // expanded Hibernate or JPA criteria builder criteriaBuilder = someService.getCriteriaBuilder(); criteriaQuery = criteriaBuilder.createQuery(); from = criteriaQuery.from("orderGroup"); min = criteriaBuilder.min(from.get("orders")); // the 'modelName' entity must be always first criteriaQuery = criteriaQuery.multiselect(from, min); // this would apply criteria from the grids filter but not pagination yet criteriaQuery = someService.applyGridFilterCriteria(criteriaQuery, grid); query = someService.createQuery(criteriaQuery); // list() dosn't fetch data from the db, it just prepares the list // object which in fact is a proxy to the database datasetSize = query.list().size(); query.setFirstResult(grid.getFirstResult()); query.setMaxResults(grid.getMaxResults()); // the first get from the list will actualy call select on the db // remember that in this case this is actually a List<Object[]> grid.setDatasetPage(query.list()); grid.setDatasetSize(datasetSize); } |
...
Code Block | ||
---|---|---|
| ||
loadInventory(viewState) { grid = viewState.getComponentByReference("inventoryGrid"); criteriaBuilder = someService.getCriteriaBuilder(); // my method that prepares a query criteriaQuery = preapreBaseInventoryCriteriaQuery(criteriaBuilder); searchFilters = grid.getSearchFilters() // my method to add the right criteria criteriaQuery = applyInventorySearchFilters(criteriaQuery, searchFilters); ordering = grid.getOrdering(); // my method to add the right criteria criteriaQuery = applyInventoryOrderFilters(criteriaQuery); query = someService.createQuery(criteriaQuery); datasetSize = query.list().size(); query.setFirstResult(grid.getFirstResult()); query.setMaxResults(grid.getMaxResults()); grid.setDatasetPage(query.list()); grid.setDatasetSize(datasetSize); } |
...