4c543a52ac263a67f7f9f71b8ab1f586a63947a6.svn-base 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. <%@page language="java" pageEncoding="UTF-8"%>
  2. <%
  3. String path = request.getContextPath();
  4. %>
  5. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  6. <html xmlns="http://www.w3.org/1999/xhtml">
  7. <head>
  8. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  9. <title>基本表格模板</title>
  10. <!--框架必需start-->
  11. <script type="text/javascript" src="<%=path%>/libs/js/jquery.js"></script>
  12. <script type="text/javascript" src="<%=path%>/libs/js/language/cn.js"></script>
  13. <script type="text/javascript" src="<%=path%>/libs/js/framework.js"></script>
  14. <link href="<%=path%>/libs/css/import_basic.css" rel="stylesheet" type="text/css"/>
  15. <link rel="stylesheet" type="text/css" id="skin" prePath="<%=path%>/" scrollerY="false"/>
  16. <link rel="stylesheet" type="text/css" id="customSkin"/>
  17. <!--框架必需end-->
  18. <!--数据表格start-->
  19. <script src="<%=path%>/libs/js/table/quiGrid.js" type="text/javascript"></script>
  20. <!--数据表格end-->
  21. <!-- 日期选择框start -->
  22. <script type="text/javascript" src="<%=path%>/libs/js/form/datePicker/WdatePicker.js"></script>
  23. <!-- 日期选择框end -->
  24. <!-- 数字步进器start -->
  25. <script type="text/javascript" src="<%=path%>/libs/js/form/stepper.js"></script>
  26. <!-- 数字步进器end -->
  27. <!-- 树组件start -->
  28. <script type="text/javascript" src="<%=path%>/libs/js/tree/ztree/ztree.js"></script>
  29. <link type="text/css" rel="stylesheet" href="<%=path%>/libs/js/tree/ztree/ztree.css"></link>
  30. <!-- 树组件end -->
  31. <!-- 树形下拉框start -->
  32. <script type="text/javascript" src="<%=path%>/libs/js/form/selectTree.js"></script>
  33. <!-- 树形下拉框end -->
  34. <!-- 表单验证start -->
  35. <script src="<%=path%>/libs/js/form/validationRule.js" type="text/javascript"></script>
  36. <script src="<%=path%>/libs/js/form/validation.js" type="text/javascript"></script>
  37. <!-- 表单验证end -->
  38. <!--自动提示框start-->
  39. <script type='text/javascript' src='<%=path%>/libs/js/form/suggestion.js'></script>
  40. <!--自动提示框end-->
  41. <!-- 日期选择框start -->
  42. <script type="text/javascript" src="<%=path%>/libs/js/form/datePicker/WdatePicker.js"></script>
  43. <!-- 日期选择框end -->
  44. </head>
  45. <style>
  46. .img_pencel2{
  47. background-image: url(<%=path%>/libs/images/icons/edit.png);
  48. background-repeat: no-repeat;
  49. background-position:0% 0%;
  50. width: 20px;
  51. height: 20px;
  52. display:inline-block;
  53. }
  54. </style>
  55. <body>
  56. <fieldset >
  57. <legend>功能点:</legend>
  58. 1、当点击某一单元格后开始编辑后,就可以使用上下左右箭头切换编辑单元格。<br/>
  59. 2、如果行不够可以批量添加行,也可在某行点击右键可以动态插入或删除一行。可以动态修改列名,可索引定位。<br/>
  60. 3、出现滚动条时,在当前可视的最后行按下箭头,表格会自动向下滚动。同理,如果上面仍有行,可视第一行按上箭头,会向上滚动。<br/>
  61. ( 为简化代码,编辑结果并未提交到后台。批量删除、导入、导入和即时编辑提交等功能的实现见其他示例。)
  62. </fieldset>
  63. <div class="padding_right5">
  64. <div style="height:1px;overflow:hidden;" id="tipParent"></div>
  65. <div style="height:1px;overflow:hidden;" id="tipParent2"></div>
  66. <div id="maingrid"></div>
  67. </div>
  68. <script type="text/javascript">
  69. var g;
  70. var menu;
  71. var currentRow;
  72. var rowSettingData={"list":[{"value":"0","key":"行尾"},{"value":"1","key":"行首"}]};
  73. var testData={"form.paginate.pageNo":1,"form.paginate.totalRows":1000,"rows":[
  74. {"A":"小张","B":"","C":"","D":"","E":"","F":"","G":""},
  75. {"A":"小李","B":"","C":"","D":"","E":"","F":"","G":""},
  76. {"A":"","B":"","C":"","D":"","E":"","F":"","G":""},
  77. {"A":"","B":"","C":"","D":"","E":"","F":"","G":""},
  78. {"A":"","B":"","C":"","D":"","E":"","F":"","G":""},
  79. {"A":"","B":"","C":"","D":"","E":"","F":"","G":""},
  80. {"A":"","B":"","C":"","D":"","E":"","F":"","G":""},
  81. {"A":"小赵","B":"","C":"","D":"","E":"","F":"","G":""},
  82. {"A":"","B":"","C":"","D":"","E":"","F":"","G":""},
  83. {"A":"","B":"","C":"","D":"","E":"","F":"","G":""},
  84. {"A":"","B":"","C":"","D":"","E":"","F":"","G":""},
  85. {"A":"","B":"","C":"","D":"","E":"","F":"","G":""},
  86. {"A":"","B":"","C":"","D":"","E":"","F":"","G":""},
  87. {"A":"","B":"","C":"","D":"","E":"","F":"","G":""},
  88. {"A":"","B":"","C":"","D":"","E":"","F":"","G":""},
  89. {"A":"","B":"","C":"","D":"","E":"","F":"","G":""},
  90. {"A":"","B":"","C":"","D":"","E":"","F":"","G":""},
  91. {"A":"","B":"","C":"","D":"","E":"","F":"","G":""},
  92. {"A":"","B":"","C":"","D":"","E":"","F":"","G":""},
  93. {"A":"","B":"","C":"","D":"","E":"","F":"","G":""}
  94. ]}
  95. var listdata={"list":[
  96. {value:"1",key:"北京",suggest:"北京|beijing|bj"},
  97. {value:"2",key:"广州",suggest:"广州|guangzhou|gz"},
  98. {value:"3",key:"深圳",suggest:"深圳|shenzhen|sz"},
  99. {value:"4",key:"上海",suggest:"上海|shanghai|sh"},
  100. {value:"5",key:"长沙",suggest:"长沙|changsha|cs"},
  101. {value:"6",key:"成都",suggest:"成都|chengdu|cd"},
  102. {value:"7",key:"贵阳",suggest:"贵阳|guiyang|gy"},
  103. {value:"8",key:"海口",suggest:"海口|haikou|hk"},
  104. {value:"9",key:"杭州",suggest:"杭州|hangzhou|hz"},
  105. {value:"10",key:"昆明",suggest:"昆明|kunming|km"},
  106. {value:"11",key:"南昌",suggest:"南昌|nanchang|nc"},
  107. {value:"12",key:"南京",suggest:"南京|nanjing|nj"},
  108. {value:"13",key:"三亚",suggest:"三亚|sanya|sy"},
  109. {value:"14",key:"沈阳",suggest:"沈阳|shenyang|sy"},
  110. {value:"15",key:"温州",suggest:"温州|wenzhou|wz"},
  111. {value:"16",key:"武汉",suggest:"武汉|wuhan|wh"},
  112. {value:"17",key:"厦门",suggest:"厦门|xiamen|xm"},
  113. {value:"18",key:"西安",suggest:"西安|xian|xa"},
  114. {value:"19",key:"郑州",suggest:"郑州|zhenghou|zz"},
  115. {value:"20",key:"汕头",suggest:"汕头|shantou|st"},
  116. {value:"21",key:"太原",suggest:"太原|taiyuan|ty"},
  117. {value:"22",key:"天津",suggest:"天津|tianjin|tj"}]};
  118. var newrowid=200;
  119. function initComplete(){
  120. //$("#rowSettingSelect").data("data",rowSettingData);
  121. //$("#rowSettingSelect").render();
  122. menu = $.rightClickMenu({ width: 120, items:
  123. [
  124. { text: '向前插入行', click: itemclick, iconClass: 'icon_btn_up2',menuId:0 },
  125. { line: true },
  126. { text: '向后插入行', click: itemclick, iconClass: 'icon_btn_down2',menuId:1 },
  127. { line: true },
  128. { text: '删除本行', click: itemclick, iconClass: 'icon_delete',menuId:2 }
  129. ]
  130. });
  131. initGrid();
  132. $("fieldset").bind("click",function(e){
  133. g.endEdit();
  134. })
  135. $(".headerChangeBtn").bind("click",function(){
  136. var pencelBtn=$(this);
  137. var headerText=pencelBtn.parent().prev().text();
  138. var tip=pencelBtn.tip({content: '列标题:<input type="text" value="'+headerText+'" class="textinput" style="width:120px;"/> <input type="button" value="确定" class="button"/>',showCloseBtn:true,width:250,distanceX:-20});
  139. var tipId=pencelBtn.attr("tipId");
  140. $("#"+tipId).find(".button").click(function(){
  141. var newText=$(this).prev().val();
  142. pencelBtn.parent().prev().text(newText);
  143. tip.remove();
  144. })
  145. })
  146. }
  147. function initGrid(){
  148. g = $("#maingrid").quiGrid({
  149. columns: [
  150. { name: 'A', align: 'left', width: 120,editor: { type: 'text'},isSort:false,headerRender:function(column){
  151. return '<span style="float:left;padding-left:20px;">A</span><div style="float:right;padding-right:10px;width:20px;"><span class="img_pencel2 hand headerChangeBtn"></span></div><div class="clear"></div>'
  152. }},
  153. { name: 'B', align: 'left', width: 120,editor: { type: 'text'},isSort:false,headerRender:function(column){
  154. return '<span style="float:left;padding-left:20px;">B</span><div style="float:right;padding-right:10px;width:20px;"><span class="img_pencel2 hand headerChangeBtn"></span></div><div class="clear"></div>'
  155. }},
  156. { name: 'C', align: 'left', width: 120,editor: { type: 'text'},isSort:false,headerRender:function(column){
  157. return '<span style="float:left;padding-left:20px;">C</span><div style="float:right;padding-right:10px;width:20px;"><span class="img_pencel2 hand headerChangeBtn"></span></div><div class="clear"></div>'
  158. }},
  159. { name: 'D', align: 'left', width: 120,editor: { type: 'text'},isSort:false,headerRender:function(column){
  160. return '<span style="float:left;padding-left:20px;">D</span><div style="float:right;padding-right:10px;width:20px;"><span class="img_pencel2 hand headerChangeBtn"></span></div><div class="clear"></div>'
  161. }},
  162. { name: 'E', align: 'left', width: 120,editor: { type: 'text'},isSort:false,headerRender:function(column){
  163. return '<span style="float:left;padding-left:20px;">E</span><div style="float:right;padding-right:10px;width:20px;"><span class="img_pencel2 hand headerChangeBtn"></span></div><div class="clear"></div>'
  164. }},
  165. { name: 'F', align: 'left', width: 155,isSort:false,editor: { type: 'suggestion',data:listdata,inputWidth:150,showList:true },render:function (item){
  166. for (var i = 0; i < listdata["list"].length; i++)
  167. {
  168. if (listdata["list"][i]['value'] == item.F)
  169. return listdata["list"][i]['key']
  170. }
  171. return item.F;
  172. },headerRender:function(column){
  173. return '<span style="float:left;padding-left:20px;">F</span><div style="float:right;padding-right:10px;width:20px;"><span class="img_pencel2 hand headerChangeBtn"></span></div><div class="clear"></div>'
  174. }},
  175. { name: 'G', align: 'left', width: 150,isSort:false,editor: { type: 'date',dateFmt:'yyyy-MM-dd'},headerRender:function(column){
  176. return '<span style="float:left;padding-left:20px;">G</span><div style="float:right;padding-right:10px;width:20px;"><span class="img_pencel2 hand headerChangeBtn"></span></div><div class="clear"></div>'
  177. }}
  178. ],
  179. data:testData,sortName: 'A',rownumbers:true,checkbox:true,pageSize:1000,dataAction:"server",usePager: true,
  180. height: "100%", width:"100%",enabledEdit: true,onBeforeEdit: onBeforeEdit, onBeforeSubmitEdit: onBeforeSubmitEdit,
  181. onAfterEdit: onAfterEdit, whenRClickToSelect:false,excelMode:true,usePager:false,onDelete:onDelete,
  182. onContextmenu : function (parm,e)
  183. {
  184. currentRow = parm.data;
  185. menu.show({ top: e.pageY, left: e.pageX });
  186. return false;
  187. },
  188. toolbar:{
  189. items:[
  190. {text: '批量新增', click: addRows, iconClass: 'icon_add'},
  191. { line : true },
  192. {text: '批量删除', iconClass: 'icon_delete'},
  193. { line : true },
  194. {text: '导入', iconClass: 'icon_import'},
  195. { line : true },
  196. {text: '导出', iconClass: 'icon_reply'},
  197. { line : true },
  198. {text: '索引定位', click: findRow, iconClass: 'icon_find'}
  199. ]
  200. }
  201. });
  202. }
  203. function addRows(){
  204. $("#tipParent").tip({content: "",showCloseBtn:true,width:300,height:60,distanceY:20,distanceX:30});
  205. var tipId=$("#tipParent").attr("tipId");
  206. var formContent=$("#"+tipId).find(".qui-tip-con");
  207. if(formContent.find("#addRowSetting").length==0){
  208. var $table=$('<div id="addRowSetting"><table><tr><td>插入</td><td><input type="text" style="width:60px" value="1" id="rowSettingInput" inputMode="numberOnly"/></td><td>行,到</td><td><select id="rowSettingSelect" selWidth="70"></select></td><td><input id="rowSettingSure" type="button" value="确定" onclick="addRowsHandler()"/></td></tr></table></div>')
  209. $("#"+tipId).find(".qui-tip-con").append($table);
  210. $table.find("#rowSettingInput").render();
  211. $table.find("#rowSettingSelect").data("data",rowSettingData);
  212. $table.find("#rowSettingSelect").render();
  213. $table.find("#rowSettingSure").render();
  214. }
  215. }
  216. function cancelAddRows(){
  217. $("#tipParent").hideTip();
  218. }
  219. function addRowsHandler(){
  220. var inputValue=$("#rowSettingInput").val();
  221. if(inputValue>20){
  222. top.Dialog.alert("批量新增一次不能超过20条");
  223. return;
  224. }
  225. var selValue=$("#rowSettingSelect").attr("relValue");
  226. var firstRow = g.getRow(0);
  227. for(var i=0;i<inputValue;i++){
  228. var rowData={
  229. A:"",
  230. B:"",
  231. C:"",
  232. D:"",
  233. E:"",
  234. F:"",
  235. G:""
  236. }
  237. if(selValue==0){
  238. g.addRow(rowData);
  239. }
  240. else{
  241. g.addRow(rowData, firstRow, true);
  242. }
  243. }
  244. $("#tipParent").hideTip();
  245. }
  246. function itemclick(item, i)
  247. {
  248. var rowData={
  249. A:"",
  250. B:"",
  251. C:"",
  252. D:"",
  253. E:"",
  254. F:"",
  255. G:""
  256. }
  257. if(item.menuId==0){
  258. g.addRow(rowData, currentRow, true);
  259. }
  260. else if(item.menuId==1){
  261. g.addRow(rowData, currentRow, false);
  262. }
  263. else if(item.menuId==2){
  264. g.deleteRow(currentRow);
  265. }
  266. }
  267. function addUser(){
  268. var valid = $('#myFormId').validationEngine({returnIsValid: true});
  269. if(valid){
  270. addUserHandler();
  271. }
  272. }
  273. function onDelete(rowindex){
  274. var rowData=g.getRow(rowindex);
  275. //alert(JSON.stringify(rowData));
  276. g.deleteRow(rowData);
  277. }
  278. function findRow(){
  279. $("#tipParent2").tip({content: "",showCloseBtn:true,width:350,height:60,distanceY:20,distanceX:430});
  280. var tipId=$("#tipParent2").attr("tipId");
  281. var formContent=$("#"+tipId).find(".qui-tip-con");
  282. if(formContent.find("#findRowSetting").length==0){
  283. var $table=$('<div id="findRowSetting"><table><tr><td>查找第一列包含关键字:</td><td><input type="text" style="width:120px" value="小赵" id="rowFindInput"/></td><td><input id="rowFindSure" type="button" value="确定" onclick="findRowHandler()"/></td></tr></table></div>')
  284. $("#"+tipId).find(".qui-tip-con").append($table);
  285. $table.find("#rowFindInput").render();
  286. $table.find("#rowFindSure").render();
  287. $table.find("#rowFindInput").bind("enter",function(){
  288. findRowHandler()
  289. })
  290. }
  291. }
  292. function findRowHandler(){
  293. var inputValue=$("#rowFindInput").val();
  294. for (var record in g.records){
  295. if(g.records[record]['A']==inputValue){
  296. var targetRow=g.records[record];
  297. g.select(targetRow);
  298. var rowPosition=g.records[record]['rowPosition'];
  299. g.setScroller(rowPosition,null,true);
  300. }
  301. }
  302. $("#tipParent2").hideTip();
  303. }
  304. //编辑前事件
  305. function onBeforeEdit(e)
  306. {
  307. var str="编辑前事件,可阻止某些行或列进行编辑。列名:"+e.column.name+";行号:"+e.rowindex+";编辑前的值:"+e.value+"\n";
  308. //if(e.record.id=="121"){
  309. // top.Dialog.alert("此行不可编辑",null,null,null,2);
  310. // return false;
  311. //}
  312. }
  313. //编辑提交前事件
  314. function onBeforeSubmitEdit(e){
  315. }
  316. //编辑后事件
  317. function onAfterEdit(e)
  318. {
  319. //var str="编辑后事件,用于ajax提交处理。列名:"+e.column.name+";行号:"+e.rowindex+";编辑后的值:"+e.value+"\n";
  320. }
  321. </script>
  322. </body>
  323. </html>