0

Auto sort on a grid - doesn't update after refresh of data?

asked 2011-11-30 14:26:08 +0800

IanS gravatar image IanS
39

updated 2011-11-30 14:26:25 +0800

I was looking through the docs and found http://sourceforge.net/tracker/?func=detail&aid=3195870&group_id=152762&atid=785194

This led me to believe the below was possible, but it loses the sort when the data is refreshed. (Try sorting sender then hitting update data). Ideas?

ZKFiddle-Link

MyMail.java
package j3qsost7$v3;

public class MyMail {

private String subject;

private String sender;

private Integer size;

public MyMail(String subject, String sender, Integer size) {
this.subject = subject;
this.sender = sender;
this.size = size;
}

public String getSubject() {
return subject;
}

public void setSubject(String subject) {
this.subject = subject;
}

public String getSender() {
return sender;
}

public void setSender(String sender) {
this.sender = sender;
}

public Integer getSize() {
return size;
}

public void setSize(Integer size) {
this.size = size;
}

}


MyRowRenderer.java
package j3qsost7$v3;

import org.zkoss.zk.ui.*;
import org.zkoss.zk.ui.event.*;
import org.zkoss.zk.ui.util.*;
import org.zkoss.zk.ui.ext.*;
import org.zkoss.zk.au.*;
import org.zkoss.zk.au.out.*;
import org.zkoss.zul.*;


public class MyRowRenderer implements RowRenderer {
public void render(final Row row, final java.lang.Object data) {
MyMail mail = (MyMail) data;
new Label(mail.getSubject()).setParent(row);
new Label(mail.getSender()).setParent(row);
new Label(mail.getSize().toString()).setParent(row);
}
}


TestComposer.java
package j3qsost7$v3;

import org.zkoss.zk.ui.*;
import org.zkoss.zk.ui.event.*;
import org.zkoss.zk.ui.util.*;
import org.zkoss.zk.ui.ext.*;
import org.zkoss.zk.au.*;
import org.zkoss.zk.au.out.*;
import org.zkoss.zul.*;
import java.util.*;

public class TestComposer extends GenericForwardComposer{

private Grid inboxGrid;
public void doAfterCompose(Component comp) throws Exception {
super.doAfterCompose(comp);

inboxGrid.setModel(new ListModelList(getData()));

}

public void onClick$refreshBtn(Event e){
inboxGrid.setModel(new ListModelList(getUpdatedData()));
}

/* simply return a small model here , you could read data from database for your own implementation.*/
private List<MyMail> getData(){
ArrayList<MyMail> list= new ArrayList<MyMail>();

list.add(new MyMail("Test Mail1","TonyQ", 10));
list.add(new MyMail("Test Mail12","Ryan", 100));
list.add(new MyMail("Test Mail13","Simon", 15));
list.add(new MyMail("Test Mail14","Jimmy", 5));
return list;
}

private List<MyMail> getUpdatedData(){
ArrayList<MyMail> list= new ArrayList<MyMail>();

list.add(new MyMail("Test Mail1-updated","TonyQ", 10));
list.add(new MyMail("Test Mail12-updated","Ryan", 100));
list.add(new MyMail("Test Mail13-updated","Simon", 15));
list.add(new MyMail("Test Mail14-updated","Jimmy", 5));
return list;
}

}


index.zul
<zk>

<div apply="j3qsost7$v3.TestComposer">
<grid id="inboxGrid" height="350px"
rowRenderer="j3qsost7$v3.MyRowRenderer"
emptyMessage="Nothing in Inbox.">
<columns>
<column label="Subject" />
<column width="150px" label="Received" sort="auto(sender)" />
<column width="80px" label="Size" />
</columns>
</grid>

<button label="updated data and refresh" id="refreshBtn" />
</div>
</zk>

delete flag offensive retag edit

2 Replies

Sort by ยป oldest newest

answered 2011-12-01 01:50:51 +0800

matthewgo gravatar image matthewgo
375

Hi IanS
Please add custom-attributes:

<grid  ......>
<custom-attributes org.zkoss.zul.grid.autoSort="true" />
</grid>

Please refer to this doc

link publish delete flag offensive edit

answered 2011-12-01 09:44:01 +0800

IanS gravatar image IanS
39

Brilliant thanks!

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2011-11-30 14:26:08 +0800

Seen: 225 times

Last updated: Dec 01 '11

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More