JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » AJAX討論區 » ZK  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to postflat modego to previous topicgo to next topic
己加入精華區
by jumperchen at 2009-06-10 15:29
本主題所含的標籤
作者 Re:第一次建立適合龐大資料的Grid分頁就上手 [Re:javck]
swlin





發文: 17
積分: 0
於 2009-07-28 11:19 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
javck wrote:
請提供你的程式碼以及畫面,否則我不知道該如何幫你!


好的,謝謝javck兄

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?page title="new page title" contentType="text/html;charset=UTF-8"?>
<zk>
<window title="new page title" border="normal" apply="MyComposer">
  <paging id="pg"/>    
    <grid id="result_grid" rowRenderer="myRowRenderer">
    <columns>
      <column>是否上線</column>
      <column>VS Server</column>
      <column>車機編號</column>
      <column>對應的AP</column>
      <column>最後上線時間</column>
    </columns>
    <rows>
      <row />  
    </rows>
  </grid>
</window>
</zk>


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
public class MyComposer implements Composer{
  Paging pg;
  Object[] result = AdpcVsIboxMap.getIbox_vs().keySet().toArray();
  int pageSize=2;
  Grid result_grid;
  int startPageNumber=0;
  TemporaryPageModel TemporaryModel;
 
  @Override
  public void doAfterCompose(Component win) throws Exception {
    Components.wireVariables(win, this);
      Events.addEventListeners(win, this);
      Components.addForwards(win, this);
      
      pg.setPageSize(pageSize);
      pg.setTotalSize(result.length);
      pg.setActivePage(0);
                  //將paging 與gird作連結
      result_grid.setPaginal(pg);
 
  }
  
  public void onPaging$pg(ForwardEvent event) {
      final PagingEvent pe = (PagingEvent) event.getOrigin();
      refreshModel(startPageNumber = pe.getActivePage());
    }
         //修改grid的model
    private void refreshModel(int activePage) {
      result_grid.setModel(TemporaryModel = new TemporaryPageModel(
          activePage, pageSize, result));
    }
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
public class myRowRenderer implements RowRenderer {
 
  public void render(Row row, Object data) throws Exception {
    if (data != null) {
 
      String iboxNum = (String) data;
      Map m = (Map) AdpcVsIboxMap.getIbox_vs().get(iboxNum);
 
      System.out.println("iboxNum:" + iboxNum);
 
      Label l;
 
      l = new Label();
      l.setValue(((AdpcVsIboxMap.getLastUpdateTimeByiboxNum(iboxNum) - 60000) > 0) + "");
      l.setParent(row);
 
      l = new Label();
      l.setValue(AdpcVsIboxMap.getVsName(iboxNum));
      l.setParent(row);
 
      l = new Label();
      l.setValue(iboxNum);
      l.setParent(row);
 
      l = new Label();
      l.setValue(AdpcApIboxMap.getApNamesByIboxNum(iboxNum) + "");
      l.setParent(row);
 
      l = new Label();
      l.setValue(m.get(AdpcVsIboxMap.SYSTIME) + "");
      l.setParent(row);
    }
  }
 
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
public class TemporaryPageModel extends AbstractListModel{
  private static final long serialVersionUID = 20090609;
    private Object[] result = null;
    private int startPageNumber;
    private int pageSize;
 
    /**
     * 
     * @param startPageNumber 目前頁次
     * @param pageSize 每頁筆數
           * @param result2 資料
     */
    public TemporaryPageModel(int startPageNumber, int pageSize,Object[] result) {
      super();
      this.startPageNumber = startPageNumber;
      this.pageSize = pageSize;
      this.result = result;
    }
    
    /*
     * @see org.zkoss.zul.ListModel#getElementAt(int) 
     */
    public String getElementAt(int index) {
      
      int currIndex = startPageNumber * pageSize + index;
      if(currIndex<result.length){
        return (String)result[currIndex];
      }else{
        return null;
      }
      
    }
    /*
     * @see org.zkoss.zul.ListModel#getSize()
     */
    public int getSize() {
      return pageSize;
    }
    public int getStartPageNumber() {
      return startPageNumber;
    }
}


reply to postreply to post
話題樹型展開
人氣 標題 作者 字數 發文時間
5087 [精華] 第一次建立適合龐大資料的Grid分頁就上手 javck 3361 2009-06-10 14:43
4353 Re:第一次建立適合龐大資料的Grid分頁就上手 swlin 115 2009-07-21 17:41
4303 Re:第一次建立適合龐大資料的Grid分頁就上手 javck 25 2009-07-22 11:02
4873 Re:第一次建立適合龐大資料的Grid分頁就上手 swlin 3455 2009-07-28 11:19
» JWorld@TW »  AJAX討論區 » ZK

reply to postflat modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8