我想在zk中使用 listitem 的重新排序当我们在 zul 文件中定义标签(listitem,listcell)时,我们怎么做呢。我不是想要使用 ListitemRenderer 。Here我找到了一些东西,但可能是他们没有更新东西
答案 0 :(得分:3)
下面的例子也可以在zk fiddle找到。
我们稍后会以弹出方式扩展的第一个例子 简单的观点:
<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>
控制器解释说:
public class LboxViewCtrl extends SelectorComposer<Component> {
@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));
}
}
}
现在我们可以找到列。
首先,如果我们点击列表框中的按钮,我们会添加一个打开菜单的方法。
@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);
}
如果您想使用向上/向下按钮而不是dnd,请查看此zk demo.
这很容易,可以在ZK-Documentation和ZK Demosite上快速找到 只需添加
sortAscending="XXX" sortDescending="XXX"
到.zul中的zks Listhead
组件,其中XXX
被data binding,el expression评估为java.lang.Comparator
或在您的内部设置{{1}} composer
答案 1 :(得分:0)
我已在ZUL中重新排序,您可以查看Here