ZK在列表框中重新排序

我想在zk中使用listitem的重新排序当我们在zul文件中定义标签(listitem,listcell)时,我们怎么做呢。我不想使用ListitemRenderer 。 在这里我找到了一些东西,但可能是他们没有更新的东西

列表框重新排序列

下面的例子也可以在zk小提琴上找到。

通过拖放

首先是我们稍后扩展到弹出窗口的示例。
简单的看法:

                        

控制器解释说:

 public class LboxViewCtrl extends SelectorComposer { @Wire private Listbox lbox; @Wire private Listhead lHead; @Wire private Panel menu; @Wire private Listbox box; @Listen("onDrop = #lbox > #lHead > listheader") public void onDroplHead(DropEvent ev) { // get the dragged Listheader and the one it is dropped on. Listheader dragged = (Listheader) ev.getDragged(); Listheader droppedOn = (Listheader) ev.getTarget(); // then get their indexes. int from = lHead.getChildren().indexOf(dragged); int to = lHead.getChildren().indexOf(droppedOn); // swap the positions lHead.insertBefore(dragged, droppedOn); // swap related Listcell in all Listitem instances for (Listitem item : lbox.getItems()) { item.insertBefore(item.getChildren().get(from), item.getChildren().get(to)); } } } 

现在我们可以列出这些列。

随着弹出

首先,如果单击Listbox中的按钮,我们会添加一个打开菜单的方法。

 @Listen("onClick = #reorderBtn") public void onEditorOpen(Event e) { Window win = (Window) Executions.createComponents("/lbMenu.zul", this.getSelf(), null); win.doModal(); } 

当然我们需要一个弹出视图:

      

和控制器一样:

  @Wire private Window menu; @Wire private Listbox box; private Listhead lHead; @Override public void doAfterCompose(Component comp) throws Exception { super.doAfterCompose(comp); // get the Listboxhead in which we like to change the the col order lHead = (Listhead) menu.getParent().query("#lbox > #lHead"); // set the model for Listbox box in the pop up box.setModel(new ListModelList<>(lHead.getChildren())); } @Listen("onDrop = listitem") public void onDropInMenu(DropEvent ev) { // get the draged and dropped again Listitem dragged = (Listitem) ev.getDragged(); Listitem droppedOn = (Listitem) ev.getTarget(); // then get their indexes. int from = box.getItems().indexOf(dragged); int to = box.getItems().indexOf(droppedOn); // swap the positions lHead.insertBefore(lHead.getChildren().get(from), lHead.getChildren().get(to)); // swap related Listcell in all Listitem instances for (Listitem item : lHead.getListbox().getItems()) { item.insertBefore(item.getChildren().get(from), item.getChildren().get(to)); } // swap the items in pop up Lisbox as well box.insertBefore(dragged, droppedOn); } 

如果你想拥有向上/向下按钮而不是dnd,只需看看这个zk演示。

列表框重新排序行

它非常简单,可以在ZK-Documentation和ZK Demosite中快速找到。
只需添加

 sortAscending="XXX" sortDescending="XXX" 

到.zul中的zks Listhead组件,其中XXX被评估为
java.lang.Comparator通过数据绑定 , 表达式或在composer php中设置。

我已经在ZUL中进行了重新排序,你可以在这里查看