GridPanel.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. Ext.require([
  2. 'erp.util.*'
  3. ]);
  4. Ext.define('erp.view.fa.fix.datalist.GridPanel',{
  5. extend: 'Ext.grid.Panel',
  6. alias: 'widget.erpDatalistGridPanel',
  7. layout : 'auto',
  8. id: 'grid',
  9. emptyText : '无数据',
  10. columnLines : true,
  11. autoScroll : true,
  12. store: [],
  13. columns: [],
  14. bodyStyle:'background-color:#f1f1f1;',
  15. selModel: Ext.create('Ext.selection.CheckboxModel',{
  16. headerWidth: 0
  17. }),
  18. dockedItems: [{
  19. id : 'pagingtoolbar',
  20. xtype: 'erpDatalistToolbar',
  21. dock: 'bottom',
  22. displayInfo: true
  23. }],
  24. plugins: [Ext.create('Ext.ux.grid.GridHeaderFilters')],
  25. BaseUtil: Ext.create('erp.util.BaseUtil'),
  26. RenderUtil:Ext.create('erp.util.RenderUtil'),
  27. initComponent : function(){
  28. var me=this;
  29. condition = this.BaseUtil.getUrlParam('urlcondition');
  30. condition = (condition == null) ? "" : condition;
  31. condition = condition.replace(/@/,"'%").replace(/@/,"%'");
  32. caller = this.BaseUtil.getUrlParam('whoami');
  33. this.getCount(caller, condition);
  34. this.callParent(arguments);
  35. } ,
  36. getColumnsAndStore: function(caller, condition, page, pageSize){
  37. var me = this;
  38. me.BaseUtil.getActiveTab().setLoading(true);//loading...
  39. Ext.Ajax.request({//拿到grid的columns
  40. url : basePath + 'common/datalist.action',
  41. params: {
  42. caller: caller,
  43. condition: condition,
  44. page: page,
  45. pageSize: pageSize
  46. },
  47. method : 'post',
  48. callback : function(options,success,response){
  49. me.BaseUtil.getActiveTab().setLoading(false);
  50. var res = new Ext.decode(response.responseText);
  51. if(res.exception || res.exceptionInfo){
  52. showError(res.exceptionInfo);
  53. return;
  54. }
  55. var store = Ext.create('Ext.data.Store', {
  56. fields: res.fields,
  57. data: res.data != null ? Ext.decode(res.data.replace(/,}/g, '}').replace(/,]/g, ']')) : []//一定要去掉多余逗号,ie对此很敏感
  58. });
  59. //处理render
  60. Ext.Array.each(res.columns, function(column) {
  61. if(column.renderer!=null&&column.renderer!="")
  62. column.renderer= me.RenderUtil[column.renderer];
  63. });
  64. me.reconfigure(store, res.columns);
  65. //修改pagingtoolbar信息
  66. Ext.getCmp('pagingtoolbar').afterOnLoad();
  67. //拿到datalist对应的单表的关键词
  68. keyField = res.keyField;//form表主键字段
  69. pfField = res.pfField;//grid表主键字段
  70. url = basePath + res.url;//grid行选择之后iframe嵌入的页面链接
  71. }
  72. });
  73. },
  74. getCount: function(caller, condition){
  75. var me = this;
  76. Ext.Ajax.request({//拿到grid的数据总数count
  77. url : basePath + '/common/datalistCount.action',
  78. params: {
  79. caller: caller,
  80. condition: condition
  81. },
  82. method : 'post',
  83. callback : function(options,success,response){
  84. var res = new Ext.decode(response.responseText);
  85. if(res.exception || res.exceptionInfo){
  86. showError(res.exceptionInfo);
  87. return;
  88. }
  89. dataCount = res.count;
  90. me.getColumnsAndStore(caller, condition, page, pageSize);
  91. }
  92. });
  93. },
  94. listeners: {
  95. 'beforeheaderfiltersapply': function(grid, filters) {
  96. var condition = "1=1";
  97. for(var fn in filters){
  98. var value = filters[fn];
  99. if(!Ext.isEmpty(value)){
  100. value = " AND " + fn + " LIKE '" + value + "%' ";
  101. Ext.each(grid.columns, function(c){
  102. if(c.dataIndex == fn && c.xtype == 'datecolumn'){//日期形式的特殊处理成oracle支持的格式哦
  103. value = " AND " + fn + "=to_date('" + Ext.Date.toString(filters[fn]) + "','YYYY-MM-DD') ";
  104. }
  105. });
  106. condition = condition + value;
  107. }
  108. }
  109. if (condition == "1=1") return false;
  110. this.getColumnsAndStore(caller, condition, page, pageSize);
  111. return false;
  112. }
  113. },
  114. reconfigure: function(store, columns){
  115. //改写reconfigure方法
  116. var d = this.headerCt;
  117. if (this.columns.length <= 1 && columns) {//this.columns.length > 1表示grid的columns已存在,没必要remove再add
  118. if(Ext.isIE){//ie下,format出现NaN-NaN-NaN,暂时作string处理
  119. Ext.each(columns, function(c){
  120. if(c.xtype == 'datecolumn'){
  121. c.xtype = "";
  122. c.format = "";
  123. }
  124. });
  125. }
  126. d.suspendLayout = true;
  127. d.removeAll();
  128. d.add(columns);
  129. }
  130. if (store) {
  131. if(Ext.isIE){//ie下,format出现NaN-NaN-NaN
  132. Ext.each(store.fields, function(f){
  133. if(f.type == 'date'){
  134. f.type = "string";
  135. f.format = "";
  136. }
  137. });
  138. }
  139. this.bindStore(store);
  140. } else {
  141. this.getView().refresh();
  142. }
  143. if (columns) {
  144. d.suspendLayout = false;
  145. this.forceComponentLayout();
  146. }
  147. this.fireEvent("reconfigure", this);
  148. }
  149. });