/samples/showcase2/src/com/gwtext/sample/showcase2/public/source/grid/RemotePagingSample.java.html

http://gwt-ext.googlecode.com/ · HTML · 206 lines · 178 code · 28 blank · 0 comment · 0 complexity · f89069726ee79673e7ef7833ea23909f MD5 · raw file

  1. <html>
  2. <head>
  3. <link rel="stylesheet" href="../../js/sh/SyntaxHighlighter.css" type="text/css" />
  4. <script src="../../js/sh/shCore.js"></script>
  5. <script src="../../js/sh/shBrushJava.js"></script>
  6. <style>
  7. * {
  8. font-family:Courier New,monospace;
  9. padding: 0;
  10. margin: 0;
  11. white-space: nowrap;
  12. font-size: 11px;
  13. }
  14. .dp-highlighter {
  15. white-space: nowrap;
  16. overflow: visible;
  17. width: 800px;
  18. font-size: 11px;
  19. font-family:Courier New,monospace;
  20. }
  21. </style>
  22. </head>
  23. <body>
  24. <textarea name="code" class="java:nogutter:nocontrols" rows="15" cols="120">
  25. /*
  26. * GWT-Ext Widget Library
  27. * Copyright 2007 - 2008, GWT-Ext LLC., and individual contributors as indicated
  28. * by the @authors tag. See the copyright.txt in the distribution for a
  29. * full listing of individual contributors.
  30. *
  31. * This is free software; you can redistribute it and/or modify it
  32. * under the terms of the GNU Lesser General Public License as
  33. * published by the Free Software Foundation; either version 3 of
  34. * the License, or (at your option) any later version.
  35. *
  36. * This software is distributed in the hope that it will be useful,
  37. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  38. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  39. * Lesser General Public License for more details.
  40. *
  41. * You should have received a copy of the GNU Lesser General Public
  42. * License along with this software; if not, write to the Free
  43. * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  44. * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  45. */
  46. package com.gwtext.tutorials.client;
  47. import com.google.gwt.core.client.EntryPoint;
  48. import com.google.gwt.user.client.ui.RootPanel;
  49. import com.gwtext.client.core.SortDir;
  50. import com.gwtext.client.core.TextAlign;
  51. import com.gwtext.client.data.*;
  52. import com.gwtext.client.util.DateUtil;
  53. import com.gwtext.client.util.Format;
  54. import com.gwtext.client.widgets.*;
  55. import com.gwtext.client.widgets.event.ButtonListenerAdapter;
  56. import com.gwtext.client.widgets.event.PanelListenerAdapter;
  57. import com.gwtext.client.widgets.grid.*;
  58. import java.util.Date;
  59. public class RemotePagingSample implements EntryPoint {
  60. private GridPanel grid;
  61. private boolean showPreview = true;
  62. private Renderer renderTopic = new Renderer() {
  63. public String render(Object value, CellMetadata cellMetadata, Record record,
  64. int rowIndex, int colNum, Store store) {
  65. return Format.format("<b><a href=\"http://extjs.com/forum/showthread.php?t={2}\"
  66. target=\"_blank\">{0}</a></b>
  67. <a href=\"http://extjs.com/forum/forumdisplay.php?f={3}\" target=\"_blank\">{1} Forum</a>",
  68. new String[]{(String) value,
  69. record.getAsString("forumtitle"),
  70. record.getId(),
  71. record.getAsString("forumid"),
  72. });
  73. }
  74. };
  75. private Renderer renderLast = new Renderer() {
  76. public String render(Object value, CellMetadata cellMetadata, Record record, int rowIndex,
  77. int colNum, Store store) {
  78. Date lastPost = record.getAsDate("lastpost");
  79. String lastPostStr = DateUtil.format(lastPost, "M j, Y, g:i a");
  80. return Format.format("{0}<br/>by {1}", new String[]{lastPostStr, record.getAsString("lastposter")});
  81. }
  82. };
  83. public void onModuleLoad() {
  84. Panel panel = new Panel();
  85. panel.setBorder(false);
  86. panel.setPaddings(15);
  87. DataProxy dataProxy = new ScriptTagProxy("http://extjs.com/forum/topics-browse-remote.php");
  88. final RecordDef recordDef = new RecordDef(new FieldDef[]{
  89. new StringFieldDef("title"),
  90. new StringFieldDef("forumtitle"),
  91. new StringFieldDef("forumid"),
  92. new StringFieldDef("author"),
  93. new IntegerFieldDef("replycount"),
  94. new DateFieldDef("lastpost", "lastpost", "timestamp"),
  95. new StringFieldDef("lastposter"),
  96. new StringFieldDef("excerpt")
  97. });
  98. JsonReader reader = new JsonReader(recordDef);
  99. reader.setRoot("topics");
  100. reader.setTotalProperty("totalCount");
  101. reader.setId("threadid");
  102. final Store store = new Store(dataProxy, reader, true);
  103. store.setDefaultSort("lastpost", SortDir.DESC);
  104. ColumnConfig topicColumn = new ColumnConfig("Topic", "title", 420, false, renderTopic, "topic");
  105. topicColumn.setCss("white-space:normal;");
  106. ColumnConfig authorColumn = new ColumnConfig("Author", "author", 100);
  107. authorColumn.setHidden(true);
  108. ColumnConfig repliesColumn = new ColumnConfig("Replies", "replycount", 70);
  109. repliesColumn.setAlign(TextAlign.RIGHT);
  110. ColumnConfig lastPostColumn = new ColumnConfig("Last Post", "lastPost", 150, true, renderLast, "last");
  111. ColumnModel columnModel = new ColumnModel(new ColumnConfig[]{
  112. topicColumn,
  113. authorColumn,
  114. repliesColumn,
  115. lastPostColumn
  116. });
  117. columnModel.setDefaultSortable(true);
  118. grid = new GridPanel();
  119. grid.setWidth(700);
  120. grid.setHeight(500);
  121. grid.setTitle("Remote Paging Grid ");
  122. grid.setStore(store);
  123. grid.setColumnModel(columnModel);
  124. grid.setTrackMouseOver(false);
  125. grid.setLoadMask(true);
  126. grid.setSelectionModel(new RowSelectionModel());
  127. grid.setFrame(true);
  128. grid.setStripeRows(true);
  129. grid.setIconCls("grid-icon");
  130. GridView view = new GridView() {
  131. public String getRowClass(Record record, int index, RowParams rowParams, Store store) {
  132. if (showPreview) {
  133. rowParams.setBody(Format.format("<p>{0}</p>", record.getAsString("excerpt")));
  134. return "x-grid3-row-expanded";
  135. } else {
  136. return "x-grid3-row-collapsed";
  137. }
  138. }
  139. };
  140. view.setForceFit(true);
  141. view.setEnableRowBody(true);
  142. grid.setView(view);
  143. PagingToolbar pagingToolbar = new PagingToolbar(store);
  144. pagingToolbar.setPageSize(25);
  145. pagingToolbar.setDisplayInfo(true);
  146. pagingToolbar.setDisplayMsg("Displaying topics {0} - {1} of {2}");
  147. pagingToolbar.setEmptyMsg("No topics to display");
  148. pagingToolbar.addSeparator();
  149. ToolbarButton toolbarButton = new ToolbarButton("Show Preview");
  150. toolbarButton.setPressed(showPreview);
  151. toolbarButton.setEnableToggle(true);
  152. toolbarButton.setCls("x-btn-text-icon details");
  153. toolbarButton.addListener(new ButtonListenerAdapter() {
  154. public void onToggle(Button button, boolean pressed) {
  155. toggleDetails(pressed);
  156. }
  157. });
  158. pagingToolbar.addButton(toolbarButton);
  159. grid.setBottomToolbar(pagingToolbar);
  160. grid.addListener(new PanelListenerAdapter() {
  161. public void onRender(Component component) {
  162. store.load(0, 25);
  163. }
  164. });
  165. panel.add(grid);
  166. RootPanel.get().add(panel);
  167. }
  168. private void toggleDetails(boolean pressed) {
  169. showPreview = pressed;
  170. grid.getView().refresh();
  171. }
  172. }
  173. </textarea>
  174. <script class="javascript">
  175. dp.SyntaxHighlighter.HighlightAll('code');
  176. </script>
  177. </body>
  178. </html>