Java 列表框中的ZK重新排序
我想在zk中使用listitem的重新排序,当我们在zul文件中定义了标记(listitem,listcell)时,我们怎么做呢?我不想使用ListitemRenderer。我发现了一些东西,但可能是他们没有更新内容Listbox重新排序列 下面的例子也可以在上面找到 拖放 首先是一个dnd示例,稍后我们将扩展到弹出方式。Java 列表框中的ZK重新排序,java,zk,Java,Zk,我想在zk中使用listitem的重新排序,当我们在zul文件中定义了标记(listitem,listcell)时,我们怎么做呢?我不想使用ListitemRenderer。我发现了一些东西,但可能是他们没有更新内容Listbox重新排序列 下面的例子也可以在上面找到 拖放 首先是一个dnd示例,稍后我们将扩展到弹出方式。 简单视图: <window apply="test.LboxViewCtrl"> <listbox id="l
简单视图:
<window apply="test.LboxViewCtrl">
<listbox id="lbox">
<listhead id="lHead">
<listheader draggable="head" droppable="head" label="Col A" />
<listheader draggable="head" droppable="head" label="Col B" />
<listheader draggable="head" droppable="head" label="Col C" />
</listhead>
<auxhead>
<auxheader colspan="3">
<button id="reorderBtn" label="Reorder" />
</auxheader>
</auxhead>
<listitem>
<listcell label="A1" />
<listcell label="B1" />
<listcell label="C1" />
</listitem>
<listitem>
<listcell label="A2" />
<listcell label="B2" />
<listcell label="C2" />
</listitem>
</listbox>
</window>
当然,我们需要弹出窗口的视图:
<window id="menu" visible="false" closable="true" position="center" width="400px" height="150px" border="normal" title="Reorder" apply="test.MenuViewCtrl">
<listbox id="box">
<template name="model">
<listitem label="${each.label}" draggable="move" droppable="move" />
</template>
</listbox>
</window>
到.zul中的zks
Listhead
组件,其中XXX
被评估为java.lang.Comparator
,或者设置在您的内部。我已经在zul本身中完成了重新排序,您可以检查我说的是重新排序,而不是排序,所以请定义重新排序。对我来说,重新排序正在进行,这就是在你的例子中发生的事情,zk doc正在我的链接中处理/I在例子中显示。我已经发布了以下标题的问题:-zk在列表框中重新排序而不是在zk列表框中排序。在例子中,你可以看到重新排序的图像。你是说小三角形在右上下显示?这也是您在我的awnser演示页面上看到的,三角形向上表示应用了sortAscending
三角形向下表示应用了sortDescending
。只需看演示并点击头部。啊,好的,下次请更具体地回答您的问题。您想要像示例中那样的拖放或弹出窗口吗?在你告诉我你的愿望后,我可以很容易地编辑它们。
@Listen("onClick = #reorderBtn")
public void onEditorOpen(Event e) {
Window win = (Window) Executions.createComponents("/lbMenu.zul", this.getSelf(), null);
win.doModal();
}
<window id="menu" visible="false" closable="true" position="center" width="400px" height="150px" border="normal" title="Reorder" apply="test.MenuViewCtrl">
<listbox id="box">
<template name="model">
<listitem label="${each.label}" draggable="move" droppable="move" />
</template>
</listbox>
</window>
@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);
}
sortAscending="XXX" sortDescending="XXX"