1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463
|
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>The source code</title>
<link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../resources/prettify/prettify.js"></script>
</head>
<body onload="prettyPrint();">
<pre class="prettyprint lang-js">/*!
* Ext JS Library 3.4.0
* Copyright(c) 2006-2011 Sencha Inc.
* licensing@sencha.com
* http://www.sencha.com/license
*/
<div id="cls-Ext.grid.PivotGridView"></div>/**
* @class Ext.grid.PivotGridView
* @extends Ext.grid.GridView
* Specialised GridView for rendering Pivot Grid components. Config can be passed to the PivotGridView via the PivotGrid constructor's
* viewConfig option:
<pre><code>
new Ext.grid.PivotGrid({
viewConfig: {
title: 'My Pivot Grid',
getCellCls: function(value) {
return value > 10 'red' : 'green';
}
}
});
</code></pre>
* <p>Currently {@link #title} and {@link #getCellCls} are the only configuration options accepted by PivotGridView. All other
* interaction is performed via the {@link Ext.grid.PivotGrid PivotGrid} class.</p>
*/
Ext.grid.PivotGridView = Ext.extend(Ext.grid.GridView, {
<div id="prop-Ext.grid.PivotGridView-colHeaderCellCls"></div>/**
* The CSS class added to all group header cells. Defaults to 'grid-hd-group-cell'
* @property colHeaderCellCls
* @type String
*/
colHeaderCellCls: 'grid-hd-group-cell',
<div id="cfg-Ext.grid.PivotGridView-title"></div>/**
* @cfg {String} title Optional title to be placed in the top left corner of the PivotGrid. Defaults to an empty string.
*/
title: '',
<div id="cfg-Ext.grid.PivotGridView-getCellCls"></div>/**
* @cfg {Function} getCellCls Optional function which should return a CSS class name for each cell value. This is useful when
* color coding cells based on their value. Defaults to undefined.
*/
<div id="method-Ext.grid.PivotGridView-getColumnHeaders"></div>/**
* Returns the headers to be rendered at the top of the grid. Should be a 2-dimensional array, where each item specifies the number
* of columns it groups (column in this case refers to normal grid columns). In the example below we have 5 city groups, which are
* each part of a continent supergroup. The colspan for each city group refers to the number of normal grid columns that group spans,
* so in this case the grid would be expected to have a total of 12 columns:
<pre><code>
[
{
items: [
{header: 'England', colspan: 5},
{header: 'USA', colspan: 3}
]
},
{
items: [
{header: 'London', colspan: 2},
{header: 'Cambridge', colspan: 3},
{header: 'Palo Alto', colspan: 3}
]
}
]
</code></pre>
* In the example above we have cities nested under countries. The nesting could be deeper if desired - e.g. Continent -> Country ->
* State -> City, or any other structure. The only constaint is that the same depth must be used throughout the structure.
* @return {Array} A tree structure containing the headers to be rendered. Must include the colspan property at each level, which should
* be the sum of all child nodes beneath this node.
*/
getColumnHeaders: function() {
return this.grid.topAxis.buildHeaders();;
},
<div id="method-Ext.grid.PivotGridView-getRowHeaders"></div>/**
* Returns the headers to be rendered on the left of the grid. Should be a 2-dimensional array, where each item specifies the number
* of rows it groups. In the example below we have 5 city groups, which are each part of a continent supergroup. The rowspan for each
* city group refers to the number of normal grid columns that group spans, so in this case the grid would be expected to have a
* total of 12 rows:
<pre><code>
[
{
width: 90,
items: [
{header: 'England', rowspan: 5},
{header: 'USA', rowspan: 3}
]
},
{
width: 50,
items: [
{header: 'London', rowspan: 2},
{header: 'Cambridge', rowspan: 3},
{header: 'Palo Alto', rowspan: 3}
]
}
]
</code></pre>
* In the example above we have cities nested under countries. The nesting could be deeper if desired - e.g. Continent -> Country ->
* State -> City, or any other structure. The only constaint is that the same depth must be used throughout the structure.
* @return {Array} A tree structure containing the headers to be rendered. Must include the colspan property at each level, which should
* be the sum of all child nodes beneath this node.
* Each group may specify the width it should be rendered with.
* @return {Array} The row groups
*/
getRowHeaders: function() {
return this.grid.leftAxis.buildHeaders();
},
/**
* @private
* Renders rows between start and end indexes
* @param {Number} startRow Index of the first row to render
* @param {Number} endRow Index of the last row to render
*/
renderRows : function(startRow, endRow) {
var grid = this.grid,
rows = grid.extractData(),
rowCount = rows.length,
templates = this.templates,
renderer = grid.renderer,
hasRenderer = typeof renderer == 'function',
getCellCls = this.getCellCls,
hasGetCellCls = typeof getCellCls == 'function',
cellTemplate = templates.cell,
rowTemplate = templates.row,
rowBuffer = [],
meta = {},
tstyle = 'width:' + this.getGridInnerWidth() + 'px;',
colBuffer, colCount, column, i, row;
startRow = startRow || 0;
endRow = Ext.isDefined(endRow) ? endRow : rowCount - 1;
for (i = 0; i < rowCount; i++) {
row = rows[i];
colCount = row.length;
colBuffer = [];
//build up each column's HTML
for (var j = 0; j < colCount; j++) {
meta.id = i + '-' + j;
meta.css = j === 0 ? 'x-grid3-cell-first ' : (j == (colCount - 1) ? 'x-grid3-cell-last ' : '');
meta.attr = meta.cellAttr = '';
meta.value = row[j];
if (Ext.isEmpty(meta.value)) {
meta.value = ' ';
}
if (hasRenderer) {
meta.value = renderer(meta.value);
}
if (hasGetCellCls) {
meta.css += getCellCls(meta.value) + ' ';
}
colBuffer[colBuffer.length] = cellTemplate.apply(meta);
}
rowBuffer[rowBuffer.length] = rowTemplate.apply({
tstyle: tstyle,
cols : colCount,
cells : colBuffer.join(""),
alt : ''
});
}
return rowBuffer.join("");
},
<div id="prop-Ext.grid.PivotGridView-Ext.Template"></div>/**
* The master template to use when rendering the GridView. Has a default template
* @property Ext.Template
* @type masterTpl
*/
masterTpl: new Ext.Template(
'<div class="x-grid3 x-pivotgrid" hidefocus="true">',
'<div class="x-grid3-viewport">',
'<div class="x-grid3-header">',
'<div class="x-grid3-header-title"><span>{title}</span></div>',
'<div class="x-grid3-header-inner">',
'<div class="x-grid3-header-offset" style="{ostyle}"></div>',
'</div>',
'<div class="x-clear"></div>',
'</div>',
'<div class="x-grid3-scroller">',
'<div class="x-grid3-row-headers"></div>',
'<div class="x-grid3-body" style="{bstyle}">{body}</div>',
'<a href="#" class="x-grid3-focus" tabIndex="-1"></a>',
'</div>',
'</div>',
'<div class="x-grid3-resize-marker"> </div>',
'<div class="x-grid3-resize-proxy"> </div>',
'</div>'
),
/**
* @private
* Adds a gcell template to the internal templates object. This is used to render the headers in a multi-level column header.
*/
initTemplates: function() {
Ext.grid.PivotGridView.superclass.initTemplates.apply(this, arguments);
var templates = this.templates || {};
if (!templates.gcell) {
templates.gcell = new Ext.XTemplate(
'<td class="x-grid3-hd x-grid3-gcell x-grid3-td-{id} ux-grid-hd-group-row-{row} ' + this.colHeaderCellCls + '" style="{style}">',
'<div {tooltip} class="x-grid3-hd-inner x-grid3-hd-{id}" unselectable="on" style="{istyle}">',
this.grid.enableHdMenu ? '<a class="x-grid3-hd-btn" href="#"></a>' : '', '{value}',
'</div>',
'</td>'
);
}
this.templates = templates;
this.hrowRe = new RegExp("ux-grid-hd-group-row-(\\d+)", "");
},
/**
* @private
* Sets up the reference to the row headers element
*/
initElements: function() {
Ext.grid.PivotGridView.superclass.initElements.apply(this, arguments);
<div id="prop-Ext.grid.PivotGridView-rowHeadersEl"></div>/**
* @property rowHeadersEl
* @type Ext.Element
* The element containing all row headers
*/
this.rowHeadersEl = new Ext.Element(this.scroller.child('div.x-grid3-row-headers'));
<div id="prop-Ext.grid.PivotGridView-headerTitleEl"></div>/**
* @property headerTitleEl
* @type Ext.Element
* The element that contains the optional title (top left section of the pivot grid)
*/
this.headerTitleEl = new Ext.Element(this.mainHd.child('div.x-grid3-header-title'));
},
/**
* @private
* Takes row headers into account when calculating total available width
*/
getGridInnerWidth: function() {
var previousWidth = Ext.grid.PivotGridView.superclass.getGridInnerWidth.apply(this, arguments);
return previousWidth - this.getTotalRowHeaderWidth();
},
<div id="method-Ext.grid.PivotGridView-getTotalRowHeaderWidth"></div>/**
* Returns the total width of all row headers as specified by {@link #getRowHeaders}
* @return {Number} The total width
*/
getTotalRowHeaderWidth: function() {
var headers = this.getRowHeaders(),
length = headers.length,
total = 0,
i;
for (i = 0; i< length; i++) {
total += headers[i].width;
}
return total;
},
/**
* @private
* Returns the total height of all column headers
* @return {Number} The total height
*/
getTotalColumnHeaderHeight: function() {
return this.getColumnHeaders().length * 21;
},
/**
* Inherit docs
* @private
* @param {HTMLElement} el
*/
getCellIndex : function(el) {
if (el) {
var match = el.className.match(this.colRe),
data;
if (match && (data = match[1])) {
return parseInt(data.split('-')[1], 10);
}
}
return false;
},
/**
* @private
* Slight specialisation of the GridView renderUI - just adds the row headers
*/
renderUI : function() {
var templates = this.templates,
innerWidth = this.getGridInnerWidth();
return templates.master.apply({
body : templates.body.apply({rows:' '}),
ostyle: 'width:' + innerWidth + 'px',
bstyle: 'width:' + innerWidth + 'px'
});
},
/**
* @private
* Make sure that the headers and rows are all sized correctly during layout
*/
onLayout: function(width, height) {
Ext.grid.PivotGridView.superclass.onLayout.apply(this, arguments);
var width = this.getGridInnerWidth();
this.resizeColumnHeaders(width);
this.resizeAllRows(width);
},
<div id="method-Ext.grid.PivotGridView-refresh"></div>/**
* Refreshs the grid UI
* @param {Boolean} headersToo (optional) True to also refresh the headers
*/
refresh : function(headersToo) {
this.fireEvent('beforerefresh', this);
this.grid.stopEditing(true);
var result = this.renderBody();
this.mainBody.update(result).setWidth(this.getGridInnerWidth());
if (headersToo === true) {
this.updateHeaders();
this.updateHeaderSortState();
}
this.processRows(0, true);
this.layout();
this.applyEmptyText();
this.fireEvent('refresh', this);
},
/**
* @private
* Bypasses GridView's renderHeaders as they are taken care of separately by the PivotAxis instances
*/
renderHeaders: Ext.emptyFn,
/**
* @private
* Taken care of by PivotAxis
*/
fitColumns: Ext.emptyFn,
/**
* @private
* Called on layout, ensures that the width of each column header is correct. Omitting this can lead to faulty
* layouts when nested in a container.
* @param {Number} width The new width
*/
resizeColumnHeaders: function(width) {
var topAxis = this.grid.topAxis;
if (topAxis.rendered) {
topAxis.el.setWidth(width);
}
},
/**
* @private
* Sets the row header div to the correct width. Should be called after rendering and reconfiguration of headers
*/
resizeRowHeaders: function() {
var rowHeaderWidth = this.getTotalRowHeaderWidth(),
marginStyle = String.format("margin-left: {0}px;", rowHeaderWidth);
this.rowHeadersEl.setWidth(rowHeaderWidth);
this.mainBody.applyStyles(marginStyle);
Ext.fly(this.innerHd).applyStyles(marginStyle);
this.headerTitleEl.setWidth(rowHeaderWidth);
this.headerTitleEl.setHeight(this.getTotalColumnHeaderHeight());
},
/**
* @private
* Resizes all rendered rows to the given width. Usually called by onLayout
* @param {Number} width The new width
*/
resizeAllRows: function(width) {
var rows = this.getRows(),
length = rows.length,
i;
for (i = 0; i < length; i++) {
Ext.fly(rows[i]).setWidth(width);
Ext.fly(rows[i]).child('table').setWidth(width);
}
},
/**
* @private
* Updates the Row Headers, deferring the updating of Column Headers to GridView
*/
updateHeaders: function() {
this.renderGroupRowHeaders();
this.renderGroupColumnHeaders();
},
/**
* @private
* Renders all row header groups at all levels based on the structure fetched from {@link #getGroupRowHeaders}
*/
renderGroupRowHeaders: function() {
var leftAxis = this.grid.leftAxis;
this.resizeRowHeaders();
leftAxis.rendered = false;
leftAxis.render(this.rowHeadersEl);
this.setTitle(this.title);
},
<div id="method-Ext.grid.PivotGridView-setTitle"></div>/**
* Sets the title text in the top left segment of the PivotGridView
* @param {String} title The title
*/
setTitle: function(title) {
this.headerTitleEl.child('span').dom.innerHTML = title;
},
/**
* @private
* Renders all column header groups at all levels based on the structure fetched from {@link #getColumnHeaders}
*/
renderGroupColumnHeaders: function() {
var topAxis = this.grid.topAxis;
topAxis.rendered = false;
topAxis.render(this.innerHd.firstChild);
},
/**
* @private
* Overridden to test whether the user is hovering over a group cell, in which case we don't show the menu
*/
isMenuDisabled: function(cellIndex, el) {
return true;
}
});</pre>
</body>
</html>
|