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.

945 lines
33 KiB

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