ItEr27S11AltaEtiquetasTipoEtiquetaItEr26S13: [FixBug] Adds new elements to list of Labels preserving ascending/descending order
This commit is contained in:
parent
ea1431c141
commit
ac5b0f45ef
2 changed files with 26 additions and 1 deletions
|
|
@ -19,7 +19,9 @@ import org.zkoss.zk.ui.WrongValueException;
|
|||
import org.zkoss.zk.ui.event.Event;
|
||||
import org.zkoss.zk.ui.event.InputEvent;
|
||||
import org.zkoss.zk.ui.util.GenericForwardComposer;
|
||||
import org.zkoss.zul.Column;
|
||||
import org.zkoss.zul.Grid;
|
||||
import org.zkoss.zul.ListModelExt;
|
||||
import org.zkoss.zul.Messagebox;
|
||||
import org.zkoss.zul.Row;
|
||||
import org.zkoss.zul.Rows;
|
||||
|
|
@ -209,6 +211,29 @@ public class LabelTypeCRUDController extends GenericForwardComposer {
|
|||
public void createLabel() {
|
||||
labelTypeModel.addLabel();
|
||||
Util.reloadBindings(gridLabels);
|
||||
// After adding a new row, model might be disordered, so we force it to
|
||||
// sort again respecting previous settings
|
||||
forceSortGridLabels();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts {@link Grid} model by first column, respecting sort order
|
||||
*
|
||||
* FIXME: This is a temporary solution, there should be a better/smarter way
|
||||
* of preserving order in the Grid every time a new element is added to its
|
||||
* model
|
||||
*/
|
||||
private void forceSortGridLabels() {
|
||||
Column column = (Column) gridLabels.getColumns().getFirstChild();
|
||||
ListModelExt model = (ListModelExt) gridLabels.getModel();
|
||||
if ("ascending".equals(column.getSortDirection())) {
|
||||
model.sort(column.getSortAscending(), true);
|
||||
return;
|
||||
}
|
||||
if ("descending".equals(column.getSortDirection())) {
|
||||
model.sort(column.getSortDescending(), false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public void onChangeLabelName(Event e) {
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
<grid id="gridLabels" height="320px"
|
||||
model="@{controller.labels}">
|
||||
<columns sizable="true">
|
||||
<column label="${i18n:_('Name')}" sort="auto(name)" />
|
||||
<column label="${i18n:_('Name')}" sort="auto(name)" sortDirection="ascending" />
|
||||
<column label="${i18n:_('Operations')}" />
|
||||
</columns>
|
||||
<rows>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue