void setupDataSource() { // TAP5-34: We pass the source into the CachingDataSource now; previously // we were accessing source directly, but during submit the value wasn't // cached, and therefore access was very inefficient, and sorting was // very inconsistent during the processing of the form submission. int effectiveCurrentPage = getCurrentPage(); int numberOfRowsRequiredToShowCurrentPage = 1 + (effectiveCurrentPage - 1) * rowsPerPage; int numberOfRowsRequiredToFillCurrentPage = effectiveCurrentPage * rowsPerPage; cachingSource = new CachingDataSource(source); if (pagerPosition != GridPagerPosition.NONE) { // We're going to render the pager, so we need to determine the total number of rows anyway. // We do that eagerly here so we don't have to perform two count operations; the subsequent // ones will return a cached result cachingSource.getAvailableRows(); } int availableRowsWithLimit = cachingSource.getAvailableRows(numberOfRowsRequiredToFillCurrentPage); if (availableRowsWithLimit == 0) return; // This captures when the number of rows has decreased, typically due to deletions. if (numberOfRowsRequiredToShowCurrentPage > availableRowsWithLimit) { int maxPage = ((availableRowsWithLimit - 1) / rowsPerPage) + 1; effectiveCurrentPage = maxPage; } int startIndex = (effectiveCurrentPage - 1) * rowsPerPage; int endIndex = Math.min(startIndex + rowsPerPage - 1, availableRowsWithLimit - 1); cachingSource.prepare(startIndex, endIndex, sortModel.getSortConstraints()); }
void setupRender() { if (grid.getSortModel().getSortConstraints().isEmpty()) grid.getSortModel().updateSort("title"); }
/** * Iterator for the look component in order to loop to each rows */ public Iterable<Integer> getLoopSource() { // Issue #284 : call prepared() before calling getRowValue() int startIndex = 0; int endIndex = getSource().getAvailableRows() - 1; getSource().prepare(startIndex, endIndex, sortModel.getSortConstraints()); return new Iterable<Integer>() { public Iterator<Integer> iterator() { return new Iterator<Integer>() { Integer i = new Integer(0); public boolean hasNext() { return i < getSource().getAvailableRows(); } public Integer next() { row = getSource().getRowValue(i); return i++; } public void remove() { i = 0; } }; } }; }
@SetupRender void setupRender() { GridSortModel sortModel = grid.getSortModel(); if (sortModel.getSortConstraints().isEmpty()) { while (sortModel.getColumnSort(sortColumn) != sortOrder) { sortModel.updateSort(sortColumn); } } } }
source.prepare(startIndex,endIndex,sortModel.getSortConstraints() );