-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I am using grid to show data of employee. I added auxheader to add filter to each column.
I added property to columns tag - menupopup="auto"
.
It is showing menu to each column.But when i hide some column from that menu, respective auxheader are still present in grid and hence mismatch occurs.
Is their any way to hide respective auxheader with column or any another tag that i can use instead of auxheader ??
Thanks for help in advance.
Hello Ashutosh,
In order to accomplish your task, you have to set unique id's to the columns, and filters. Furthermore you have to set forward events for the menu items.
I have prepared for you a sample code below so you can see the logic:
-- index.zul
<zk>
<menupopup id="editPopup">
<menuitem id="subjectMenuItem" label="Subject" forward="onShowColumn(subject)" />
<menuitem label="Received" forward="onShowColumn(received)" />
<menuitem label="Size" forward="onShowColumn(size)"/>
<menuseparator />
</menupopup>
<grid id="inboxGrid" width="600px" height="250px"
rowRenderer="pkg$.MyRowRenderer"
emptyMessage="Nothing in Inbox.">
<auxhead>
<auxheader>
<textbox id="subjectFilter" visible="true"></textbox>
</auxheader>
</auxhead>
<columns menupopup="editPopup">
<column id="subjectColumn" label="Subject" visible="true"/>
<column width="50px" label="Received" />
<column width="80px" label="Size" />
</columns>
</grid>
<!-- refresh content every 5 seconds -->
<timer id="timer" delay="2000" repeats="true" />
-- TestComposer:
package pkg$;
import org.zkoss.zk.ui.event.*;
import org.zkoss.zul.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.util.GenericForwardComposer;
import org.zkoss.zul.Grid;
import org.zkoss.zul.ListModelList;
public class TestComposer extends GenericForwardComposer{
/**
*
*/
private static final long serialVersionUID = 1L;
private Grid inboxGrid;
private Column subjectColumn;
private Textbox subjectFilter;
private boolean subjectVisible = true;
public void doAfterCompose(Component comp) throws Exception {
super.doAfterCompose(comp);
inboxGrid.setModel(new ListModelList(getData()));
}
public void onTimer$timer(Event e){
//inboxGrid.setModel(new ListModelList(getUpdatedData()));
}
public void onShowColumn(ForwardEvent event) throws Exception {
String columnName = (String) event.getData();
if (columnName.equals("subject")) {
subjectVisible = !subjectVisible;
subjectColumn.setVisible(subjectVisible);
subjectFilter.setVisible(subjectVisible);
}
event.getOrigin().stopPropagation();
}
/* simply return a small model here , you could read data from database for your own implementation.*/
private List<String[]> getData(){
ArrayList<String[]> list= new ArrayList<String[]>();
list.add(new String[]{"Test Mail1","TonyQ", "10k"});
list.add(new String[]{"Test Mail12","Ryan", "100k"});
list.add(new String[]{"Test Mail13","Simon", "15k"});
list.add(new String[]{"Test Mail14","Jimmy", "5k"});
return list;
}
private List<String[]> getUpdatedData(){
ArrayList<String[]> list= new ArrayList<String[]>();
list.add(new String[]{"Test Mail1-updated-"+new Date().toString(),"TonyQ", ((int ) ( Math.random() *100 )) + "k"});
list.add(new String[]{"Test Mail12-updated"+new Date().toString(),"Ryan", ((int ) ( Math.random() *100 )) + "k"});
list.add(new String[]{"Test Mail13-updated"+new Date().toString(),"Simon", ((int ) ( Math.random() *100 )) + "k"});
list.add(new String[]{"Test Mail14-updated"+new Date().toString(),"Jimmy", ((int ) ( Math.random() *100 )) + "k"});
list.add(new String[]{"Test Mail15-updated"+new Date().toString(),"Hi", ((int ) ( Math.random() *100 )) + "k"});
return list;
}
public boolean isSubjectVisible() {
return subjectVisible;
}
public void setSubjectVisible(boolean subjectVisible) {
this.subjectVisible = subjectVisible;
}
public Textbox getSubjectFilter() {
return subjectFilter;
}
public void setSubjectFilter(Textbox subjectFilter) {
this.subjectFilter = subjectFilter;
}
public Column getSubjectColumn() {
return subjectColumn;
}
public void setSubjectColumn(Column subjectColumn) {
this.subjectColumn = subjectColumn;
}
}
-- MyRowRenderer
package pkg$;
import org.zkoss.zul.Label;
import org.zkoss.zul.Row;
import org.zkoss.zul.RowRenderer;
public class MyRowRenderer implements RowRenderer {
@Override
public void render(Row row, Object data, int index) throws Exception {
String[] ary = (String[]) data;
new Label(ary[0]).setParent(row);
new Label(ary[1]).setParent(row);
new Label(ary[2]).setParent(row);
}
}
Best Regards,
Darksu
Asked: 2014-08-27 14:26:26 +0800
Seen: 35 times
Last updated: Aug 28 '14