@SetupRender void setupRender() { GridSortModel sortModel = grid.getSortModel(); if (sortModel.getSortConstraints().isEmpty()) { while (sortModel.getColumnSort(sortColumn) != sortOrder) { sortModel.updateSort(sortColumn); } } } }
/** * Resets the Grid to inital settings; this sets the current page to one, and * {@linkplain org.apache.tapestry5.grid.GridSortModel#clear() clears the sort model}. */ public void reset() { sortModel.clear(); setCurrentPage(1); }
void setupRender() { if (grid.getSortModel().getSortConstraints().isEmpty()) grid.getSortModel().updateSort("title"); }
/** * This method will set all the Sorting stuffs, thanks to sSortDir and iSortCol DataTable parameters, coming from the request */ public void prepareResponse(GridDataSource source){ String sortingCols = request.getParameter(DataTableConstants.SORTING_COLS); if(InternalUtils.isNonBlank(sortingCols)){ int nbSortingCols = Integer.parseInt(sortingCols); String sord = request.getParameter(DataTableConstants.SORT_DIR+"0"); String sidx = request.getParameter(DataTableConstants.SORT_COL+"0"); if(nbSortingCols>0) { List<String> names = model.getPropertyNames(); int indexProperty = Integer.parseInt(sidx); String propName = names.get(indexProperty); ColumnSort colSort =sortModel.getColumnSort(propName); if(!(InternalUtils.isNonBlank(colSort.name()) && colSort.name().startsWith(sord.toUpperCase()))) sortModel.updateSort(propName); } } }
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()); }
private ColumnSort getSortForColumn() { GridSortModel sortModel = gridModel.getSortModel(); String columnId = columnModel.getId(); return sortModel.getColumnSort(columnId); }
/** * Normal, non-Ajax event handler. */ boolean onSort(String columnId) { gridModel.getSortModel().updateSort(columnId); if (request.isXHR()) { resources.triggerEvent(InternalConstants.GRID_INPLACE_UPDATE, null, null); } return true; }
/** * 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; } }; } }; }
void onBeginRenderFromColumn(MarkupWriter writer) { String id = gridModel.getDataModel().get(propertyName).getId(); if (!lean) { writer.attributes("data-grid-property", id); } switch (gridModel.getSortModel().getColumnSort(id)) { case ASCENDING: writer.attributes("data-grid-column-sort", "ascending"); break; case DESCENDING: writer.attributes("data-grid-column-sort", "descending"); break; default: } }
void onActionFromSortRating() { grid.getSortModel().updateSort("rating"); } }
source.prepare(startIndex,endIndex,sortModel.getSortConstraints() );