刚写的B/S高级查询界面(基于ExtJs框架)

这几天赶着做一个B/S系统,基于ExtJs框架,从中学了不少东西,今天写的高级查询界面感觉比较有意义,很多人应该也用得着,特拿出来共享一下。当然没正式完工,余下与服务器交互、Lookup列表、取生成查询条件一部分没有完成,做得有点腻了,先放出来,曾经做过的不妨交流一下。

界面:

查询界面

代码:

  1. <DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html><head><title>XXXX系统V1.0</title>
  3. <metaname="Author"contect="彭国辉">
  4. <meta name="Keywords" content="blog:http://blog.csdn.net/nhconch" />
  5. <metahttp-equiv="Content-Type"content="text/html;charset=utf8">
  6. <linkrel="stylesheet"type="text/css"href="resources/css/ext-all.css">
  7. <linkrel="stylesheet"type="text/css"href="resources/css/hndc.css">
  8. <scripttype="text/javascript"src="adapter/ext/ext-base.js"></script>
  9. <scripttype="text/javascript"src="ext-all.js"></script>
  10. <scripttype="text/javascript"src="source/locale/ext-lang-zh_CN.js"></script>
  11. <scripttype="text/javascript">
  12. Ext.BLANK_IMAGE_URL='resources/images/default/s.gif';
  13. Ext.onReady(function(){
  14. vardsPQ=newExt.data.JsonStore({
  15. fields:["idx","relation","leftParenthesis","fieldname","operator","value","rightParenthesis"]
  16. });
  17. varfieldsDef=newExt.data.JsonStore({
  18. fields:['value','text','type'],
  19. data:[
  20. {value:'A.Billno',text:'预约单号',type:'string'},
  21. {value:'A.Date',text:'时间',type:'date'},
  22. {value:'A.boolean',text:'布尔',type:'boolean'},
  23. {value:'A.int',text:'整形',type:'int'},
  24. {value:'A.float',text:'浮点',type:'float'},
  25. {value:'A.lookup',text:'Lookup',type:'lookup',data:[[1,'list1'],[2,'list2'],[3,'list3']]}
  26. ]
  27. });
  28. varnumericOp=datetimeOp=newExt.data.SimpleStore({
  29. fields:['value','text'],
  30. data:[['=','='],['<>','<>'],['<','<'],['<=','<='],['<','>'],['>=','>='],['isnull','空白'],['isnotnull','非空白']]
  31. });
  32. varstringOp=newExt.data.SimpleStore({
  33. fields:['value','text'],
  34. data:[['=','='],['<>','<>'],['<','<'],['<','>'],
  35. ['like|%','以...开头'],['like%|','以...结尾'],['like%|%','包含字符'],['notlike%|%','不包含字符'],
  36. ['isnull','空白'],['isnotnull','非空白']]
  37. });
  38. varlookupOp=booleanOp=newExt.data.SimpleStore({
  39. fields:['value','text'],
  40. data:[['=','='],['<>','<>'],['isnull','空白'],['isnotnull','非空白']]
  41. });
  42. varobjGridTextEditor=newExt.grid.GridEditor(newExt.form.TextField());
  43. //varobjGridMemoEditor=newExt.grid.GridEditor(newExt.form.TextArea());
  44. varobjGridDateEditor=newExt.grid.GridEditor(newExt.form.DateField({format:'Y-m-d'}));
  45. varobjGridIntegerEditor=newExt.grid.GridEditor(newExt.form.NumberField({allowBlank:false,allowNegative:false,allowDecimals:false}));
  46. varobjGridFloatEditor=newExt.grid.GridEditor(newExt.form.NumberField({allowBlank:false,allowNegative:false}));
  47. varobjGridBooleanEditor=newExt.grid.GridEditor(newExt.form.ComboBox({
  48. store:[[true,'是'],[false,'否']],
  49. mode:'local',
  50. readOnly:true,
  51. triggerAction:'all',
  52. allowBlank:false,
  53. editable:false,
  54. forceSelection:true,
  55. blankText:'请选择...'
  56. }));
  57. varobjGridLookupEditor=newExt.grid.GridEditor(newExt.form.ComboBox({
  58. //store:[],
  59. mode:'local',
  60. readOnly:true,
  61. triggerAction:'all',
  62. allowBlank:false,
  63. editable:false,
  64. forceSelection:true,
  65. blankText:'请选择...'
  66. }));
  67. functionfileListChange(field,newValue,oldValue){
  68. //alert(field);
  69. }
  70. functionfindRecordValue(store,prop,propValue,field){
  71. varrecord;
  72. if(store.getCount()>0){
  73. store.each(function(r){
  74. if(r.data[prop]==propValue){
  75. rrecord=r;
  76. returnfalse;
  77. }
  78. });
  79. }
  80. returnrecord?record.data[field]:'';
  81. }
  82. functiondisplayOperator(v){
  83. switch(v){
  84. case'isnull':return'空白';
  85. case'isnotnull':return'非空白';
  86. case'like|%':return'以...开头';
  87. case'like%|':return'以...结尾';
  88. case'like%|%':return'包含字符';
  89. case'notlike%|%':return'不包含字符';
  90. default:returnv;
  91. }
  92. }
  93. functiondisplayValue(v,params,record){
  94. vardataType=findRecordValue(fieldsDef,'value',record.get('fieldname'),'type');
  95. varoperator=record.get('operator');
  96. if(operator=='isnull'||operator=='isnotnull')return'';
  97. switch(dataType){
  98. case'date':returnv?v.dateFormat('Y-m-d'):'';
  99. case'boolean':return(v?'是':'否');
  100. default:returnv;
  101. }
  102. }
  103. varqRowData=Ext.data.Record.create([
  104. {name:'idx',type:'int'},
  105. {name:'relation',type:'string'},
  106. {name:'leftParenthesis',type:'string'},
  107. {name:'fieldname',type:'string'},
  108. {name:'operator',type:'string'},
  109. {name:'value',type:'string'},
  110. {name:'rightParenthesis',type:'string'}
  111. ]);
  112. vardsPQ=newExt.data.JsonStore({
  113. data:[],
  114. fields:["idx","relation","leftParenthesis","fieldname","operator","value","rightParenthesis"]
  115. });
  116. varcolM=newExt.grid.ColumnModel([
  117. {
  118. header:"关系",
  119. dataIndex:"relation",
  120. width:50,
  121. renderer:function(v){return(v=='and'?'并且':'或者')},
  122. editor:newExt.form.ComboBox({
  123. store:[['and','并且'],['or','或者']],
  124. mode:'local',
  125. readOnly:true,
  126. triggerAction:'all',
  127. allowBlank:false,
  128. editable:false,
  129. forceSelection:true,
  130. blankText:'请选择'
  131. })
  132. },{
  133. header:"括号",
  134. dataIndex:"leftParenthesis",
  135. width:40,
  136. editor:newExt.form.ComboBox({
  137. store:['(','((','((','(((','(((('],
  138. mode:'local',
  139. triggerAction:'all',
  140. valueField:'value',
  141. displayField:'text',
  142. editable:false
  143. })
  144. },{
  145. header:"字段名",
  146. dataIndex:"fieldname",
  147. width:130,
  148. renderer:function(v){returnfindRecordValue(fieldsDef,'value',v,'text');},
  149. editor:newExt.form.ComboBox({
  150. store:fieldsDef,
  151. mode:'local',
  152. triggerAction:'all',
  153. valueField:'value',
  154. displayField:'text',
  155. editable:false,
  156. listeners:{change:fileListChange}
  157. })
  158. },{
  159. header:"运算符",
  160. width:80,
  161. dataIndex:"operator",
  162. renderer:displayOperator
  163. },{
  164. header:"内容",
  165. dataIndex:"value",
  166. width:130,
  167. renderer:displayValue
  168. },{
  169. header:"括号",
  170. width:40,
  171. dataIndex:"rightParenthesis",
  172. editor:newExt.form.ComboBox({
  173. store:[')','))',')))','))))'],
  174. mode:'local',
  175. triggerAction:'all',
  176. valueField:'value',
  177. displayField:'text',
  178. editable:false
  179. })
  180. }
  181. ]);
  182. vargrdDPQuery=newExt.grid.EditorGridPanel({
  183. height:500,
  184. width:490,
  185. renderTo:"hello",
  186. cm:colM,
  187. sm:newExt.grid.RowSelectionModel({singleSelect:false}),
  188. store:dsPQ,
  189. region:'center',
  190. border:false,
  191. enableColumnMove:false,
  192. enableHdMenu:false,
  193. loadMask:{msg:'加载数据...'},
  194. clicksToEdit:1,
  195. tbar:[
  196. {text:'添加',handler:function(){
  197. varcount=dsPQ.getCount();
  198. varr=newqRowData({idx:dsPQ.getCount(),relation:'and',leftParenthesis:'',fieldname:'',operator:'=',value:'',rightParenthesis:''});
  199. dsPQ.commitChanges();
  200. dsPQ.insert(count,r);
  201. }
  202. },
  203. {text:'删除',handler:function(){
  204. //store=grid.getStore();
  205. varselections=grdDPQuery.getSelectionModel().getSelections();
  206. for(vari=0;i<selections.length;i++){
  207. dsPQ.remove(selections[i]);
  208. }
  209. }
  210. },
  211. {text:'全部清除',handler:function(){dsPQ.removeAll();}}
  212. ],
  213. listeners:{
  214. afteredit:function(e){
  215. if(e.column==2/*e.field=='fieldname'*/){
  216. varoldDataType=findRecordValue(fieldsDef,'value',e.originalValue,'type');
  217. varnewDataType=findRecordValue(fieldsDef,'value',e.value,'type');
  218. if(oldDataType!=newDataType){
  219. e.record.set('operator','=');
  220. e.record.set('value','');
  221. }
  222. }
  223. },
  224. cellclick:function(grid,rowIndex,columnIndex,e){
  225. if(columnIndex!=3&&columnIndex!=4)return;
  226. varrecord=grid.getStore().getAt(rowIndex);//GettheRecord
  227. //varfieldName=grid.getColumnModel().getDataIndex(columnIndex);//Getfieldname
  228. //vardata=record.get(fieldName);
  229. vardataType=findRecordValue(fieldsDef,'value',record.get('fieldname'),'type');
  230. if(dataType=='')return;//未选定字段,退出
  231. if(columnIndex==3){//绑定运算符
  232. vargrdEditor=grid.colModel.getCellEditor(columnIndex,rowIndex);
  233. if(grdEditor)grdEditor.destroy();
  234. var_store;
  235. switch(dataType){
  236. case'string':_store=stringOp;break;
  237. case'date':_store=datetimeOp;break;
  238. case'boolean':_store=booleanOp;break;
  239. case'int':
  240. case'float':_store=numericOp;break;
  241. case'lookup':_store=lookupOp;break;
  242. }
  243. grdEditor=newExt.form.ComboBox({
  244. store:_store,
  245. mode:'local',
  246. triggerAction:'all',
  247. valueField:'value',
  248. displayField:'text',
  249. editable:false
  250. })
  251. grid.colModel.setEditor(columnIndex,newExt.grid.GridEditor(grdEditor));
  252. }
  253. elseif(columnIndex==4){//绑定编辑器
  254. varoperator=record.get('operator');
  255. if(operator=='isnull'||operator=='isnotnull'){
  256. grid.colModel.setEditor(columnIndex,null);
  257. return;
  258. }
  259. vargrdEditor;
  260. switch(dataType){
  261. case'string':grdEditor=objGridTextEditor;break;
  262. case'date':grdEditor=objGridDateEditor;break;
  263. case'boolean':grdEditor=objGridBooleanEditor;break;
  264. case'int':grdEditor=objGridIntegerEditor;break;
  265. case'float':grdEditor=objGridFloatEditor;break;
  266. case'lookup':grdEditor=objGridLookupEditor;break;
  267. }
  268. if(grid.colModel.getCellEditor(columnIndex,rowIndex)!=grdEditor){
  269. grid.colModel.setEditor(columnIndex,grdEditor);
  270. }
  271. }
  272. }
  273. }
  274. });
  275. });
  276. </script>
  277. </head><divid="hello"></div><body>
  278. </body></html>

搞掂,收工。


<!-- google_ad_client = "pub-5395599807454886"; /* 468x15文字连接广告, 创建于 08-11-21 */ google_ad_slot = "5196248270"; google_ad_width = 468; google_ad_height = 15; //-->
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值