extpaging.jsp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  2. <%@ page contentType="text/html;charset=GBK"%>
  3. <% String a="hi";%>
  4. <html>
  5. <head>
  6. <meta http-equiv="Content-Type" content="text/html; charset=GBK">
  7. <title>Paging Grid Example</title>
  8. <link rel="stylesheet" type="text/css" href="/shares/js/ext/resources/css/ext-all.css"/>
  9. <!-- GC -->
  10. <!-- LIBS -->
  11. <script type="text/javascript" src="/ynet/js/ext/adapter/ext/ext-base.js"></script>
  12. <!-- ENDLIBS -->
  13. <script type="text/javascript" src="/ynet/js/ext/ext-all.js"></script>
  14. <script type="text/javascript" src="/ynet/js/ext/ux/SearchField.js"></script>
  15. <script type="text/javascript">
  16. function edit(id){}
  17. /*!
  18. * Ext JS Library 3.0.0
  19. * Copyright(c) 2006-2009 Ext JS, LLC
  20. * licensing@extjs.com
  21. * http://www.extjs.com/license
  22. */
  23. Ext.onReady(function(){
  24. Ext.QuickTips.init();
  25. // create the Data Store
  26. var store = new Ext.data.JsonStore({
  27. root: 'data',
  28. totalProperty: 'totalCount',
  29. remoteSort: true,
  30. fields:<%=request.getAttribute("fields")%>,
  31. // load using script tags for cross domain, if the data in on the same domain as
  32. // this page, an HttpProxy would be better
  33. proxy: new Ext.data.HttpProxy({
  34. url: '/ynet/ExtPagingImpl.do?v=<%=request.getParameter("v")%>'
  35. }),
  36. baseParams: {limit:20, forumId: 4}
  37. });
  38. // pluggable renders
  39. function renderCommand(value, p, record){
  40. var edit="<a href=<%=request.getContextPath()%>/<%=request.getAttribute("edit")%>?id="+record.data.universalid+">修改</a>";
  41. var see="&nbsp;<a href=<%=request.getContextPath()%>/<%=request.getAttribute("see")%>?id="+record.data.universalid+">查看</a>";
  42. return (edit+see);
  43. }
  44. function renderCommand1(value, p, record){
  45. var edit="<%=request.getContextPath()%>/<%=request.getAttribute("edit")%>?id="+record.data.universalid;
  46. var id=record.get('universalid');
  47. return String.format("<a href=# onclick=edit('{0}')>浏览</a>",record.data.universalid);
  48. }
  49. function renderCommand2(edit){
  50. var editWindow = new Ext.Window({
  51. title: '查看记录',
  52. width: 800,
  53. height:600,
  54. collapsible:true,
  55. maximizable:true,
  56. layout: 'fit',
  57. plain:true,
  58. bodyStyle:'padding:5px;',
  59. modal:true,
  60. html:'<iframe scrolling="auto" frameborder="0" width="100%" height="100%" src='+edit+'></iframe>'
  61. });
  62. editWindow.show();
  63. }
  64. var sm = new Ext.grid.CheckboxSelectionModel();
  65. function hi(action){
  66. var records =grid.getSelectionModel().getSelections();
  67. if (records.length==0){
  68. Ext.Msg.alert('操作提示','没有选择');
  69. return;
  70. }
  71. var ids=[];
  72. for (var i = 0, len = records.length; i < len; i++) {
  73. ids[i]=records[i].data.universalid;
  74. }
  75. Ext.Ajax.request({
  76. url:action,
  77. method:'post',
  78. params:{ids:ids},
  79. success: function(arg) {
  80. var jsonResult = Ext.util.JSON.decode(arg.responseText);
  81. if (jsonResult[0].sucess=='ok'){
  82. Ext.Msg.alert('操作提示', jsonResult[0].info);
  83. }
  84. else{
  85. Ext.Msg.alert('操作提示',jsonResult[0].info);
  86. }
  87. },
  88. failure: function(response) {
  89. //var respText = Ext.util.JSON.decode(resp.responseText);
  90. Ext.Msg.alert('操作失败', 'hi');
  91. }
  92. });
  93. //grid.store.reload();
  94. }
  95. var grid = new Ext.grid.GridPanel({
  96. //layout:'fit',
  97. height:Ext.getBody().getViewSize().height,
  98. title:'列表',
  99. store: store,
  100. trackMouseOver:false,
  101. disableSelection:true,
  102. loadMask: true,
  103. // 列数据,从服务器生成
  104. columns:<%=request.getAttribute("columns")%>,
  105. sm:sm,
  106. //工具条,以下从服务器生成
  107. tbar:[<%=request.getAttribute("toolButtons")%>,
  108. 'Search: ', ' ',
  109. new Ext.ux.form.SearchField({
  110. store: store,
  111. width:320
  112. })
  113. ],
  114. // paging bar on the bottom
  115. bbar: new Ext.PagingToolbar({
  116. pageSize: 20,
  117. store: store,
  118. beforePageText:"当前第",
  119. afterPageText:"页,共{0}页",
  120. lastText:"尾页",
  121. nextText :"下一页",
  122. prevText :"上一页",
  123. firstText :"首页",
  124. refreshText:"刷新页面",
  125. displayInfo: true,
  126. displayMsg:"当前显示 {0} - {1}条, 共 {2}",
  127. emptyMsg: "没有记录"
  128. })
  129. });
  130. grid.addListener('cellclick',function(grid, rowIndex,columnIndex,e){
  131. //alert(columnIndex);
  132. var record = grid.getStore().getAt(rowIndex).data;
  133. var edit="<%=request.getContextPath()%>/<%=request.getAttribute("edit")%>?id="+record.universalid;
  134. //renderCommand2(edit);
  135. if(columnIndex == 1){
  136. var record = grid.getStore().getAt(rowIndex).data;
  137. //alert(columnIndex);
  138. }
  139. });
  140. // render it
  141. grid.render('grid');
  142. // trigger the data store load
  143. store.load({params:{start:0, limit:20}});
  144. });
  145. </script>
  146. <link rel="stylesheet" type="text/css" href="grid-examples.css" />
  147. <!-- Common Styles for the examples -->
  148. </head>
  149. <body height="100%">
  150. <div id="grid"></div>
  151. </body>
  152. </html>