You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

932 lines
33 KiB

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*!
  2. * Ext JS Library 3.3.1
  3. * Copyright(c) 2006-2010 Sencha Inc.
  4. * licensing@sencha.com
  5. * http://www.sencha.com/license
  6. */
  7. /*!
  8. * Ext JS Library 3.3.0
  9. * Copyright(c) 2006-2010 Ext JS, Inc.
  10. * licensing@extjs.com
  11. * http://www.extjs.com/license
  12. */
  13. Ext.ns('Ext.ux.grid');
  14. Ext.ux.grid.LockingGridView = Ext.extend(Ext.grid.GridView, {
  15. lockText : 'Lock',
  16. unlockText : 'Unlock',
  17. rowBorderWidth : 1,
  18. lockedBorderWidth : 1,
  19. /*
  20. * This option ensures that height between the rows is synchronized
  21. * between the locked and unlocked sides. This option only needs to be used
  22. * when the row heights aren't predictable.
  23. */
  24. syncHeights: false,
  25. initTemplates : function(){
  26. var ts = this.templates || {};
  27. if (!ts.masterTpl) {
  28. ts.masterTpl = new Ext.Template(
  29. '<div class="x-grid3" hidefocus="true">',
  30. '<div class="x-grid3-locked">',
  31. '<div class="x-grid3-header"><div class="x-grid3-header-inner"><div class="x-grid3-header-offset" style="{lstyle}">{lockedHeader}</div></div><div class="x-clear"></div></div>',
  32. '<div class="x-grid3-scroller"><div class="x-grid3-body" style="{lstyle}">{lockedBody}</div><div class="x-grid3-scroll-spacer"></div></div>',
  33. '</div>',
  34. '<div class="x-grid3-viewport x-grid3-unlocked">',
  35. '<div class="x-grid3-header"><div class="x-grid3-header-inner"><div class="x-grid3-header-offset" style="{ostyle}">{header}</div></div><div class="x-clear"></div></div>',
  36. '<div class="x-grid3-scroller"><div class="x-grid3-body" style="{bstyle}">{body}</div><a href="#" class="x-grid3-focus" tabIndex="-1"></a></div>',
  37. '</div>',
  38. '<div class="x-grid3-resize-marker">&#160;</div>',
  39. '<div class="x-grid3-resize-proxy">&#160;</div>',
  40. '</div>'
  41. );
  42. }
  43. this.templates = ts;
  44. Ext.ux.grid.LockingGridView.superclass.initTemplates.call(this);
  45. },
  46. getEditorParent : function(ed){
  47. return this.el.dom;
  48. },
  49. initElements : function(){
  50. var el = Ext.get(this.grid.getGridEl().dom.firstChild),
  51. lockedWrap = el.child('div.x-grid3-locked'),
  52. lockedHd = lockedWrap.child('div.x-grid3-header'),
  53. lockedScroller = lockedWrap.child('div.x-grid3-scroller'),
  54. mainWrap = el.child('div.x-grid3-viewport'),
  55. mainHd = mainWrap.child('div.x-grid3-header'),
  56. scroller = mainWrap.child('div.x-grid3-scroller');
  57. if (this.grid.hideHeaders) {
  58. lockedHd.setDisplayed(false);
  59. mainHd.setDisplayed(false);
  60. }
  61. if(this.forceFit){
  62. scroller.setStyle('overflow-x', 'hidden');
  63. }
  64. Ext.apply(this, {
  65. el : el,
  66. mainWrap: mainWrap,
  67. mainHd : mainHd,
  68. innerHd : mainHd.dom.firstChild,
  69. scroller: scroller,
  70. mainBody: scroller.child('div.x-grid3-body'),
  71. focusEl : scroller.child('a'),
  72. resizeMarker: el.child('div.x-grid3-resize-marker'),
  73. resizeProxy : el.child('div.x-grid3-resize-proxy'),
  74. lockedWrap: lockedWrap,
  75. lockedHd: lockedHd,
  76. lockedScroller: lockedScroller,
  77. lockedBody: lockedScroller.child('div.x-grid3-body'),
  78. lockedInnerHd: lockedHd.child('div.x-grid3-header-inner', true)
  79. });
  80. this.focusEl.swallowEvent('click', true);
  81. },
  82. getLockedRows : function(){
  83. return this.hasRows() ? this.lockedBody.dom.childNodes : [];
  84. },
  85. getLockedRow : function(row){
  86. return this.getLockedRows()[row];
  87. },
  88. getCell : function(row, col){
  89. var lockedLen = this.cm.getLockedCount();
  90. if(col < lockedLen){
  91. return this.getLockedRow(row).getElementsByTagName('td')[col];
  92. }
  93. return Ext.ux.grid.LockingGridView.superclass.getCell.call(this, row, col - lockedLen);
  94. },
  95. getHeaderCell : function(index){
  96. var lockedLen = this.cm.getLockedCount();
  97. if(index < lockedLen){
  98. return this.lockedHd.dom.getElementsByTagName('td')[index];
  99. }
  100. return Ext.ux.grid.LockingGridView.superclass.getHeaderCell.call(this, index - lockedLen);
  101. },
  102. addRowClass : function(row, cls){
  103. var lockedRow = this.getLockedRow(row);
  104. if(lockedRow){
  105. this.fly(lockedRow).addClass(cls);
  106. }
  107. Ext.ux.grid.LockingGridView.superclass.addRowClass.call(this, row, cls);
  108. },
  109. removeRowClass : function(row, cls){
  110. var lockedRow = this.getLockedRow(row);
  111. if(lockedRow){
  112. this.fly(lockedRow).removeClass(cls);
  113. }
  114. Ext.ux.grid.LockingGridView.superclass.removeRowClass.call(this, row, cls);
  115. },
  116. removeRow : function(row) {
  117. Ext.removeNode(this.getLockedRow(row));
  118. Ext.ux.grid.LockingGridView.superclass.removeRow.call(this, row);
  119. },
  120. removeRows : function(firstRow, lastRow){
  121. var lockedBody = this.lockedBody.dom,
  122. rowIndex = firstRow;
  123. for(; rowIndex <= lastRow; rowIndex++){
  124. Ext.removeNode(lockedBody.childNodes[firstRow]);
  125. }
  126. Ext.ux.grid.LockingGridView.superclass.removeRows.call(this, firstRow, lastRow);
  127. },
  128. syncScroll : function(e){
  129. this.lockedScroller.dom.scrollTop = this.scroller.dom.scrollTop;
  130. Ext.ux.grid.LockingGridView.superclass.syncScroll.call(this, e);
  131. },
  132. updateSortIcon : function(col, dir){
  133. var sortClasses = this.sortClasses,
  134. lockedHeaders = this.lockedHd.select('td').removeClass(sortClasses),
  135. headers = this.mainHd.select('td').removeClass(sortClasses),
  136. lockedLen = this.cm.getLockedCount(),
  137. cls = sortClasses[dir == 'DESC' ? 1 : 0];
  138. if(col < lockedLen){
  139. lockedHeaders.item(col).addClass(cls);
  140. }else{
  141. headers.item(col - lockedLen).addClass(cls);
  142. }
  143. },
  144. updateAllColumnWidths : function(){
  145. var tw = this.getTotalWidth(),
  146. clen = this.cm.getColumnCount(),
  147. lw = this.getLockedWidth(),
  148. llen = this.cm.getLockedCount(),
  149. ws = [], len, i;
  150. this.updateLockedWidth();
  151. for(i = 0; i < clen; i++){
  152. ws[i] = this.getColumnWidth(i);
  153. var hd = this.getHeaderCell(i);
  154. hd.style.width = ws[i];
  155. }
  156. var lns = this.getLockedRows(), ns = this.getRows(), row, trow, j;
  157. for(i = 0, len = ns.length; i < len; i++){
  158. row = lns[i];
  159. row.style.width = lw;
  160. if(row.firstChild){
  161. row.firstChild.style.width = lw;
  162. trow = row.firstChild.rows[0];
  163. for (j = 0; j < llen; j++) {
  164. trow.childNodes[j].style.width = ws[j];
  165. }
  166. }
  167. row = ns[i];
  168. row.style.width = tw;
  169. if(row.firstChild){
  170. row.firstChild.style.width = tw;
  171. trow = row.firstChild.rows[0];
  172. for (j = llen; j < clen; j++) {
  173. trow.childNodes[j - llen].style.width = ws[j];
  174. }
  175. }
  176. }
  177. this.onAllColumnWidthsUpdated(ws, tw);
  178. this.syncHeaderHeight();
  179. },
  180. updateColumnWidth : function(col, width){
  181. var w = this.getColumnWidth(col),
  182. llen = this.cm.getLockedCount(),
  183. ns, rw, c, row;
  184. this.updateLockedWidth();
  185. if(col < llen){
  186. ns = this.getLockedRows();
  187. rw = this.getLockedWidth();
  188. c = col;
  189. }else{
  190. ns = this.getRows();
  191. rw = this.getTotalWidth();
  192. c = col - llen;
  193. }
  194. var hd = this.getHeaderCell(col);
  195. hd.style.width = w;
  196. for(var i = 0, len = ns.length; i < len; i++){
  197. row = ns[i];
  198. row.style.width = rw;
  199. if(row.firstChild){
  200. row.firstChild.style.width = rw;
  201. row.firstChild.rows[0].childNodes[c].style.width = w;
  202. }
  203. }
  204. this.onColumnWidthUpdated(col, w, this.getTotalWidth());
  205. this.syncHeaderHeight();
  206. },
  207. updateColumnHidden : function(col, hidden){
  208. var llen = this.cm.getLockedCount(),
  209. ns, rw, c, row,
  210. display = hidden ? 'none' : '';
  211. this.updateLockedWidth();
  212. if(col < llen){
  213. ns = this.getLockedRows();
  214. rw = this.getLockedWidth();
  215. c = col;
  216. }else{
  217. ns = this.getRows();
  218. rw = this.getTotalWidth();
  219. c = col - llen;
  220. }
  221. var hd = this.getHeaderCell(col);
  222. hd.style.display = display;
  223. for(var i = 0, len = ns.length; i < len; i++){
  224. row = ns[i];
  225. row.style.width = rw;
  226. if(row.firstChild){
  227. row.firstChild.style.width = rw;
  228. row.firstChild.rows[0].childNodes[c].style.display = display;
  229. }
  230. }
  231. this.onColumnHiddenUpdated(col, hidden, this.getTotalWidth());
  232. delete this.lastViewWidth;
  233. this.layout();
  234. },
  235. doRender : function(cs, rs, ds, startRow, colCount, stripe){
  236. var ts = this.templates, ct = ts.cell, rt = ts.row, last = colCount-1,
  237. tstyle = 'width:'+this.getTotalWidth()+';',
  238. lstyle = 'width:'+this.getLockedWidth()+';',
  239. buf = [], lbuf = [], cb, lcb, c, p = {}, rp = {}, r;
  240. for(var j = 0, len = rs.length; j < len; j++){
  241. r = rs[j]; cb = []; lcb = [];
  242. var rowIndex = (j+startRow);
  243. for(var i = 0; i < colCount; i++){
  244. c = cs[i];
  245. p.id = c.id;
  246. p.css = (i === 0 ? 'x-grid3-cell-first ' : (i == last ? 'x-grid3-cell-last ' : '')) +
  247. (this.cm.config[i].cellCls ? ' ' + this.cm.config[i].cellCls : '');
  248. p.attr = p.cellAttr = '';
  249. p.value = c.renderer(r.data[c.name], p, r, rowIndex, i, ds);
  250. p.style = c.style;
  251. if(Ext.isEmpty(p.value)){
  252. p.value = '&#160;';
  253. }
  254. if(this.markDirty && r.dirty && Ext.isDefined(r.modified[c.name])){
  255. p.css += ' x-grid3-dirty-cell';
  256. }
  257. if(c.locked){
  258. lcb[lcb.length] = ct.apply(p);
  259. }else{
  260. cb[cb.length] = ct.apply(p);
  261. }
  262. }
  263. var alt = [];
  264. if(stripe && ((rowIndex+1) % 2 === 0)){
  265. alt[0] = 'x-grid3-row-alt';
  266. }
  267. if(r.dirty){
  268. alt[1] = ' x-grid3-dirty-row';
  269. }
  270. rp.cols = colCount;
  271. if(this.getRowClass){
  272. alt[2] = this.getRowClass(r, rowIndex, rp, ds);
  273. }
  274. rp.alt = alt.join(' ');
  275. rp.cells = cb.join('');
  276. rp.tstyle = tstyle;
  277. buf[buf.length] = rt.apply(rp);
  278. rp.cells = lcb.join('');
  279. rp.tstyle = lstyle;
  280. lbuf[lbuf.length] = rt.apply(rp);
  281. }
  282. return [buf.join(''), lbuf.join('')];
  283. },
  284. processRows : function(startRow, skipStripe){
  285. if(!this.ds || this.ds.getCount() < 1){
  286. return;
  287. }
  288. var rows = this.getRows(),
  289. lrows = this.getLockedRows(),
  290. row, lrow;
  291. skipStripe = skipStripe || !this.grid.stripeRows;
  292. startRow = startRow || 0;
  293. for(var i = 0, len = rows.length; i < len; ++i){
  294. row = rows[i];
  295. lrow = lrows[i];
  296. row.rowIndex = i;
  297. lrow.rowIndex = i;
  298. if(!skipStripe){
  299. row.className = row.className.replace(this.rowClsRe, ' ');
  300. lrow.className = lrow.className.replace(this.rowClsRe, ' ');
  301. if ((i + 1) % 2 === 0){
  302. row.className += ' x-grid3-row-alt';
  303. lrow.className += ' x-grid3-row-alt';
  304. }
  305. }
  306. this.syncRowHeights(row, lrow);
  307. }
  308. if(startRow === 0){
  309. Ext.fly(rows[0]).addClass(this.firstRowCls);
  310. Ext.fly(lrows[0]).addClass(this.firstRowCls);
  311. }
  312. Ext.fly(rows[rows.length - 1]).addClass(this.lastRowCls);
  313. Ext.fly(lrows[lrows.length - 1]).addClass(this.lastRowCls);
  314. },
  315. syncRowHeights: function(row1, row2){
  316. if(this.syncHeights){
  317. var el1 = Ext.get(row1),
  318. el2 = Ext.get(row2),
  319. h1 = el1.getHeight(),
  320. h2 = el2.getHeight();
  321. if(h1 > h2){
  322. el2.setHeight(h1);
  323. }else if(h2 > h1){
  324. el1.setHeight(h2);
  325. }
  326. }
  327. },
  328. afterRender : function(){
  329. if(!this.ds || !this.cm){
  330. return;
  331. }
  332. var bd = this.renderRows() || ['&#160;', '&#160;'];
  333. this.mainBody.dom.innerHTML = bd[0];
  334. this.lockedBody.dom.innerHTML = bd[1];
  335. this.processRows(0, true);
  336. if(this.deferEmptyText !== true){
  337. this.applyEmptyText();
  338. }
  339. this.grid.fireEvent('viewready', this.grid);
  340. },
  341. renderUI : function(){
  342. var templates = this.templates,
  343. header = this.renderHeaders(),
  344. body = templates.body.apply({rows:'&#160;'});
  345. return templates.masterTpl.apply({
  346. body : body,
  347. header: header[0],
  348. ostyle: 'width:' + this.getOffsetWidth() + ';',
  349. bstyle: 'width:' + this.getTotalWidth() + ';',
  350. lockedBody: body,
  351. lockedHeader: header[1],
  352. lstyle: 'width:'+this.getLockedWidth()+';'
  353. });
  354. },
  355. afterRenderUI: function(){
  356. var g = this.grid;
  357. this.initElements();
  358. Ext.fly(this.innerHd).on('click', this.handleHdDown, this);
  359. Ext.fly(this.lockedInnerHd).on('click', this.handleHdDown, this);
  360. this.mainHd.on({
  361. scope: this,
  362. mouseover: this.handleHdOver,
  363. mouseout: this.handleHdOut,
  364. mousemove: this.handleHdMove
  365. });
  366. this.lockedHd.on({
  367. scope: this,
  368. mouseover: this.handleHdOver,
  369. mouseout: this.handleHdOut,
  370. mousemove: this.handleHdMove
  371. });
  372. this.scroller.on('scroll', this.syncScroll, this);
  373. if(g.enableColumnResize !== false){
  374. this.splitZone = new Ext.grid.GridView.SplitDragZone(g, this.mainHd.dom);
  375. this.splitZone.setOuterHandleElId(Ext.id(this.lockedHd.dom));
  376. this.splitZone.setOuterHandleElId(Ext.id(this.mainHd.dom));
  377. }
  378. if(g.enableColumnMove){
  379. this.columnDrag = new Ext.grid.GridView.ColumnDragZone(g, this.innerHd);
  380. this.columnDrag.setOuterHandleElId(Ext.id(this.lockedInnerHd));
  381. this.columnDrag.setOuterHandleElId(Ext.id(this.innerHd));
  382. this.columnDrop = new Ext.grid.HeaderDropZone(g, this.mainHd.dom);
  383. }
  384. if(g.enableHdMenu !== false){
  385. this.hmenu = new Ext.menu.Menu({id: g.id + '-hctx'});
  386. this.hmenu.add(
  387. {itemId: 'asc', text: this.sortAscText, cls: 'xg-hmenu-sort-asc'},
  388. {itemId: 'desc', text: this.sortDescText, cls: 'xg-hmenu-sort-desc'}
  389. );
  390. if(this.grid.enableColLock !== false){
  391. this.hmenu.add('-',
  392. {itemId: 'lock', text: this.lockText, cls: 'xg-hmenu-lock'},
  393. {itemId: 'unlock', text: this.unlockText, cls: 'xg-hmenu-unlock'}
  394. );
  395. }
  396. if(g.enableColumnHide !== false){
  397. this.colMenu = new Ext.menu.Menu({id:g.id + '-hcols-menu'});
  398. this.colMenu.on({
  399. scope: this,
  400. beforeshow: this.beforeColMenuShow,
  401. itemclick: this.handleHdMenuClick
  402. });
  403. this.hmenu.add('-', {
  404. itemId:'columns',
  405. hideOnClick: false,
  406. text: this.columnsText,
  407. menu: this.colMenu,
  408. iconCls: 'x-cols-icon'
  409. });
  410. }
  411. this.hmenu.on('itemclick', this.handleHdMenuClick, this);
  412. }
  413. if(g.trackMouseOver){
  414. this.mainBody.on({
  415. scope: this,
  416. mouseover: this.onRowOver,
  417. mouseout: this.onRowOut
  418. });
  419. this.lockedBody.on({
  420. scope: this,
  421. mouseover: this.onRowOver,
  422. mouseout: this.onRowOut
  423. });
  424. }
  425. if(g.enableDragDrop || g.enableDrag){
  426. this.dragZone = new Ext.grid.GridDragZone(g, {
  427. ddGroup : g.ddGroup || 'GridDD'
  428. });
  429. }
  430. this.updateHeaderSortState();
  431. },
  432. layout : function(){
  433. if(!this.mainBody){
  434. return;
  435. }
  436. var g = this.grid;
  437. var c = g.getGridEl();
  438. var csize = c.getSize(true);
  439. var vw = csize.width;
  440. if(!g.hideHeaders && (vw < 20 || csize.height < 20)){
  441. return;
  442. }
  443. this.syncHeaderHeight();
  444. if(g.autoHeight){
  445. this.scroller.dom.style.overflow = 'visible';
  446. this.lockedScroller.dom.style.overflow = 'visible';
  447. if(Ext.isWebKit){
  448. this.scroller.dom.style.position = 'static';
  449. this.lockedScroller.dom.style.position = 'static';
  450. }
  451. }else{
  452. this.el.setSize(csize.width, csize.height);
  453. var hdHeight = this.mainHd.getHeight();
  454. var vh = csize.height - (hdHeight);
  455. }
  456. this.updateLockedWidth();
  457. if(this.forceFit){
  458. if(this.lastViewWidth != vw){
  459. this.fitColumns(false, false);
  460. this.lastViewWidth = vw;
  461. }
  462. }else {
  463. this.autoExpand();
  464. this.syncHeaderScroll();
  465. }
  466. this.onLayout(vw, vh);
  467. },
  468. getOffsetWidth : function() {
  469. return (this.cm.getTotalWidth() - this.cm.getTotalLockedWidth() + this.getScrollOffset()) + 'px';
  470. },
  471. renderHeaders : function(){
  472. var cm = this.cm,
  473. ts = this.templates,
  474. ct = ts.hcell,
  475. cb = [], lcb = [],
  476. p = {},
  477. len = cm.getColumnCount(),
  478. last = len - 1;
  479. for(var i = 0; i < len; i++){
  480. p.id = cm.getColumnId(i);
  481. p.value = cm.getColumnHeader(i) || '';
  482. p.style = this.getColumnStyle(i, true);
  483. p.tooltip = this.getColumnTooltip(i);
  484. p.css = (i === 0 ? 'x-grid3-cell-first ' : (i == last ? 'x-grid3-cell-last ' : '')) +
  485. (cm.config[i].headerCls ? ' ' + cm.config[i].headerCls : '');
  486. if(cm.config[i].align == 'right'){
  487. p.istyle = 'padding-right:16px';
  488. } else {
  489. delete p.istyle;
  490. }
  491. if(cm.isLocked(i)){
  492. lcb[lcb.length] = ct.apply(p);
  493. }else{
  494. cb[cb.length] = ct.apply(p);
  495. }
  496. }
  497. return [ts.header.apply({cells: cb.join(''), tstyle:'width:'+this.getTotalWidth()+';'}),
  498. ts.header.apply({cells: lcb.join(''), tstyle:'width:'+this.getLockedWidth()+';'})];
  499. },
  500. updateHeaders : function(){
  501. var hd = this.renderHeaders();
  502. this.innerHd.firstChild.innerHTML = hd[0];
  503. this.innerHd.firstChild.style.width = this.getOffsetWidth();
  504. this.innerHd.firstChild.firstChild.style.width = this.getTotalWidth();
  505. this.lockedInnerHd.firstChild.innerHTML = hd[1];
  506. var lw = this.getLockedWidth();
  507. this.lockedInnerHd.firstChild.style.width = lw;
  508. this.lockedInnerHd.firstChild.firstChild.style.width = lw;
  509. },
  510. getResolvedXY : function(resolved){
  511. if(!resolved){
  512. return null;
  513. }
  514. var c = resolved.cell, r = resolved.row;
  515. return c ? Ext.fly(c).getXY() : [this.scroller.getX(), Ext.fly(r).getY()];
  516. },
  517. syncFocusEl : function(row, col, hscroll){
  518. Ext.ux.grid.LockingGridView.superclass.syncFocusEl.call(this, row, col, col < this.cm.getLockedCount() ? false : hscroll);
  519. },
  520. ensureVisible : function(row, col, hscroll){
  521. return Ext.ux.grid.LockingGridView.superclass.ensureVisible.call(this, row, col, col < this.cm.getLockedCount() ? false : hscroll);
  522. },
  523. insertRows : function(dm, firstRow, lastRow, isUpdate){
  524. var last = dm.getCount() - 1;
  525. if(!isUpdate && firstRow === 0 && lastRow >= last){
  526. this.refresh();
  527. }else{
  528. if(!isUpdate){
  529. this.fireEvent('beforerowsinserted', this, firstRow, lastRow);
  530. }
  531. var html = this.renderRows(firstRow, lastRow),
  532. before = this.getRow(firstRow);
  533. if(before){
  534. if(firstRow === 0){
  535. this.removeRowClass(0, this.firstRowCls);
  536. }
  537. Ext.DomHelper.insertHtml('beforeBegin', before, html[0]);
  538. before = this.getLockedRow(firstRow);
  539. Ext.DomHelper.insertHtml('beforeBegin', before, html[1]);
  540. }else{
  541. this.removeRowClass(last - 1, this.lastRowCls);
  542. Ext.DomHelper.insertHtml('beforeEnd', this.mainBody.dom, html[0]);
  543. Ext.DomHelper.insertHtml('beforeEnd', this.lockedBody.dom, html[1]);
  544. }
  545. if(!isUpdate){
  546. this.fireEvent('rowsinserted', this, firstRow, lastRow);
  547. this.processRows(firstRow);
  548. }else if(firstRow === 0 || firstRow >= last){
  549. this.addRowClass(firstRow, firstRow === 0 ? this.firstRowCls : this.lastRowCls);
  550. }
  551. }
  552. this.syncFocusEl(firstRow);
  553. },
  554. getColumnStyle : function(col, isHeader){
  555. var style = !isHeader ? this.cm.config[col].cellStyle || this.cm.config[col].css || '' : this.cm.config[col].headerStyle || '';
  556. style += 'width:'+this.getColumnWidth(col)+';';
  557. if(this.cm.isHidden(col)){
  558. style += 'display:none;';
  559. }
  560. var align = this.cm.config[col].align;
  561. if(align){
  562. style += 'text-align:'+align+';';
  563. }
  564. return style;
  565. },
  566. getLockedWidth : function() {
  567. return this.cm.getTotalLockedWidth() + 'px';
  568. },
  569. getTotalWidth : function() {
  570. return (this.cm.getTotalWidth() - this.cm.getTotalLockedWidth()) + 'px';
  571. },
  572. getColumnData : function(){
  573. var cs = [], cm = this.cm, colCount = cm.getColumnCount();
  574. for(var i = 0; i < colCount; i++){
  575. var name = cm.getDataIndex(i);
  576. cs[i] = {
  577. name : (!Ext.isDefined(name) ? this.ds.fields.get(i).name : name),
  578. renderer : cm.getRenderer(i),
  579. id : cm.getColumnId(i),
  580. style : this.getColumnStyle(i),
  581. locked : cm.isLocked(i)
  582. };
  583. }
  584. return cs;
  585. },
  586. renderBody : function(){
  587. var markup = this.renderRows() || ['&#160;', '&#160;'];
  588. return [this.templates.body.apply({rows: markup[0]}), this.templates.body.apply({rows: markup[1]})];
  589. },
  590. refreshRow: function(record){
  591. var store = this.ds,
  592. colCount = this.cm.getColumnCount(),
  593. columns = this.getColumnData(),
  594. last = colCount - 1,
  595. cls = ['x-grid3-row'],
  596. rowParams = {
  597. tstyle: String.format("width: {0};", this.getTotalWidth())
  598. },
  599. lockedRowParams = {
  600. tstyle: String.format("width: {0};", this.getLockedWidth())
  601. },
  602. colBuffer = [],
  603. lockedColBuffer = [],
  604. cellTpl = this.templates.cell,
  605. rowIndex,
  606. row,
  607. lockedRow,
  608. column,
  609. meta,
  610. css,
  611. i;
  612. if (Ext.isNumber(record)) {
  613. rowIndex = record;
  614. record = store.getAt(rowIndex);
  615. } else {
  616. rowIndex = store.indexOf(record);
  617. }
  618. if (!record || rowIndex < 0) {
  619. return;
  620. }
  621. for (i = 0; i < colCount; i++) {
  622. column = columns[i];
  623. if (i == 0) {
  624. css = 'x-grid3-cell-first';
  625. } else {
  626. css = (i == last) ? 'x-grid3-cell-last ' : '';
  627. }
  628. meta = {
  629. id: column.id,
  630. style: column.style,
  631. css: css,
  632. attr: "",
  633. cellAttr: ""
  634. };
  635. meta.value = column.renderer.call(column.scope, record.data[column.name], meta, record, rowIndex, i, store);
  636. if (Ext.isEmpty(meta.value)) {
  637. meta.value = ' ';
  638. }
  639. if (this.markDirty && record.dirty && typeof record.modified[column.name] != 'undefined') {
  640. meta.css += ' x-grid3-dirty-cell';
  641. }
  642. if (column.locked) {
  643. lockedColBuffer[i] = cellTpl.apply(meta);
  644. } else {
  645. colBuffer[i] = cellTpl.apply(meta);
  646. }
  647. }
  648. row = this.getRow(rowIndex);
  649. row.className = '';
  650. lockedRow = this.getLockedRow(rowIndex);
  651. lockedRow.className = '';
  652. if (this.grid.stripeRows && ((rowIndex + 1) % 2 === 0)) {
  653. cls.push('x-grid3-row-alt');
  654. }
  655. if (this.getRowClass) {
  656. rowParams.cols = colCount;
  657. cls.push(this.getRowClass(record, rowIndex, rowParams, store));
  658. }
  659. // Unlocked rows
  660. this.fly(row).addClass(cls).setStyle(rowParams.tstyle);
  661. rowParams.cells = colBuffer.join("");
  662. row.innerHTML = this.templates.rowInner.apply(rowParams);
  663. // Locked rows
  664. this.fly(lockedRow).addClass(cls).setStyle(lockedRowParams.tstyle);
  665. lockedRowParams.cells = lockedColBuffer.join("");
  666. lockedRow.innerHTML = this.templates.rowInner.apply(lockedRowParams);
  667. lockedRow.rowIndex = rowIndex;
  668. this.syncRowHeights(row, lockedRow);
  669. this.fireEvent('rowupdated', this, rowIndex, record);
  670. },
  671. refresh : function(headersToo){
  672. this.fireEvent('beforerefresh', this);
  673. this.grid.stopEditing(true);
  674. var result = this.renderBody();
  675. this.mainBody.update(result[0]).setWidth(this.getTotalWidth());
  676. this.lockedBody.update(result[1]).setWidth(this.getLockedWidth());
  677. if(headersToo === true){
  678. this.updateHeaders();
  679. this.updateHeaderSortState();
  680. }
  681. this.processRows(0, true);
  682. this.layout();
  683. this.applyEmptyText();
  684. this.fireEvent('refresh', this);
  685. },
  686. onDenyColumnLock : function(){
  687. },
  688. initData : function(ds, cm){
  689. if(this.cm){
  690. this.cm.un('columnlockchange', this.onColumnLock, this);
  691. }
  692. Ext.ux.grid.LockingGridView.superclass.initData.call(this, ds, cm);
  693. if(this.cm){
  694. this.cm.on('columnlockchange', this.onColumnLock, this);
  695. }
  696. },
  697. onColumnLock : function(){
  698. this.refresh(true);
  699. },
  700. handleHdMenuClick : function(item){
  701. var index = this.hdCtxIndex,
  702. cm = this.cm,
  703. id = item.getItemId(),
  704. llen = cm.getLockedCount();
  705. switch(id){
  706. case 'lock':
  707. if(cm.getColumnCount(true) <= llen + 1){
  708. this.onDenyColumnLock();
  709. return undefined;
  710. }
  711. cm.setLocked(index, true);
  712. if(llen != index){
  713. cm.moveColumn(index, llen);
  714. this.grid.fireEvent('columnmove', index, llen);
  715. }
  716. break;
  717. case 'unlock':
  718. if(llen - 1 != index){
  719. cm.setLocked(index, false, true);
  720. cm.moveColumn(index, llen - 1);
  721. this.grid.fireEvent('columnmove', index, llen - 1);
  722. }else{
  723. cm.setLocked(index, false);
  724. }
  725. break;
  726. default:
  727. return Ext.ux.grid.LockingGridView.superclass.handleHdMenuClick.call(this, item);
  728. }
  729. return true;
  730. },
  731. handleHdDown : function(e, t){
  732. Ext.ux.grid.LockingGridView.superclass.handleHdDown.call(this, e, t);
  733. if(this.grid.enableColLock !== false){
  734. if(Ext.fly(t).hasClass('x-grid3-hd-btn')){
  735. var hd = this.findHeaderCell(t),
  736. index = this.getCellIndex(hd),
  737. ms = this.hmenu.items, cm = this.cm;
  738. ms.get('lock').setDisabled(cm.isLocked(index));
  739. ms.get('unlock').setDisabled(!cm.isLocked(index));
  740. }
  741. }
  742. },
  743. syncHeaderHeight: function(){
  744. var hrow = Ext.fly(this.innerHd).child('tr', true),
  745. lhrow = Ext.fly(this.lockedInnerHd).child('tr', true);
  746. hrow.style.height = 'auto';
  747. lhrow.style.height = 'auto';
  748. var hd = hrow.offsetHeight,
  749. lhd = lhrow.offsetHeight,
  750. height = Math.max(lhd, hd) + 'px';
  751. hrow.style.height = height;
  752. lhrow.style.height = height;
  753. },
  754. updateLockedWidth: function(){
  755. var lw = this.cm.getTotalLockedWidth(),
  756. tw = this.cm.getTotalWidth() - lw,
  757. csize = this.grid.getGridEl().getSize(true),
  758. lp = Ext.isBorderBox ? 0 : this.lockedBorderWidth,
  759. rp = Ext.isBorderBox ? 0 : this.rowBorderWidth,
  760. vw = (csize.width - lw - lp - rp) + 'px',
  761. so = this.getScrollOffset();
  762. if(!this.grid.autoHeight){
  763. var vh = (csize.height - this.mainHd.getHeight()) + 'px';
  764. this.lockedScroller.dom.style.height = vh;
  765. this.scroller.dom.style.height = vh;
  766. }
  767. this.lockedWrap.dom.style.width = (lw + rp) + 'px';
  768. this.scroller.dom.style.width = vw;
  769. this.mainWrap.dom.style.left = (lw + lp + rp) + 'px';
  770. if(this.innerHd){
  771. this.lockedInnerHd.firstChild.style.width = lw + 'px';
  772. this.lockedInnerHd.firstChild.firstChild.style.width = lw + 'px';
  773. this.innerHd.style.width = vw;
  774. this.innerHd.firstChild.style.width = (tw + rp + so) + 'px';
  775. this.innerHd.firstChild.firstChild.style.width = tw + 'px';
  776. }
  777. if(this.mainBody){
  778. this.lockedBody.dom.style.width = (lw + rp) + 'px';
  779. this.mainBody.dom.style.width = (tw + rp) + 'px';
  780. }
  781. }
  782. });
  783. Ext.ux.grid.LockingColumnModel = Ext.extend(Ext.grid.ColumnModel, {
  784. /**
  785. * Returns true if the given column index is currently locked
  786. * @param {Number} colIndex The column index
  787. * @return {Boolean} True if the column is locked
  788. */
  789. isLocked : function(colIndex){
  790. return this.config[colIndex].locked === true;
  791. },
  792. /**
  793. * Locks or unlocks a given column
  794. * @param {Number} colIndex The column index
  795. * @param {Boolean} value True to lock, false to unlock
  796. * @param {Boolean} suppressEvent Pass false to cause the columnlockchange event not to fire
  797. */
  798. setLocked : function(colIndex, value, suppressEvent){
  799. if (this.isLocked(colIndex) == value) {
  800. return;
  801. }
  802. this.config[colIndex].locked = value;
  803. if (!suppressEvent) {
  804. this.fireEvent('columnlockchange', this, colIndex, value);
  805. }
  806. },
  807. /**
  808. * Returns the total width of all locked columns
  809. * @return {Number} The width of all locked columns
  810. */
  811. getTotalLockedWidth : function(){
  812. var totalWidth = 0;
  813. for (var i = 0, len = this.config.length; i < len; i++) {
  814. if (this.isLocked(i) && !this.isHidden(i)) {
  815. totalWidth += this.getColumnWidth(i);
  816. }
  817. }
  818. return totalWidth;
  819. },
  820. /**
  821. * Returns the total number of locked columns
  822. * @return {Number} The number of locked columns
  823. */
  824. getLockedCount : function() {
  825. var len = this.config.length;
  826. for (var i = 0; i < len; i++) {
  827. if (!this.isLocked(i)) {
  828. return i;
  829. }
  830. }
  831. //if we get to this point all of the columns are locked so we return the total
  832. return len;
  833. },
  834. /**
  835. * Moves a column from one position to another
  836. * @param {Number} oldIndex The current column index
  837. * @param {Number} newIndex The destination column index
  838. */
  839. moveColumn : function(oldIndex, newIndex){
  840. var oldLocked = this.isLocked(oldIndex),
  841. newLocked = this.isLocked(newIndex);
  842. if (oldIndex < newIndex && oldLocked && !newLocked) {
  843. this.setLocked(oldIndex, false, true);
  844. } else if (oldIndex > newIndex && !oldLocked && newLocked) {
  845. this.setLocked(oldIndex, true, true);
  846. }
  847. Ext.ux.grid.LockingColumnModel.superclass.moveColumn.apply(this, arguments);
  848. }
  849. });