TableChunker.html 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>The source code</title>
  6. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  7. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  8. <style type="text/css">
  9. .highlight { display: block; background-color: #ddd; }
  10. </style>
  11. <script type="text/javascript">
  12. function highlight() {
  13. document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
  14. }
  15. </script>
  16. </head>
  17. <body onload="prettyPrint(); highlight();">
  18. <pre class="prettyprint lang-js"><span id='Ext-view-TableChunker'>/**
  19. </span> * Produces optimized XTemplates for chunks of tables to be
  20. * used in grids, trees and other table based widgets.
  21. */
  22. Ext.define('Ext.view.TableChunker', {
  23. singleton: true,
  24. requires: ['Ext.XTemplate'],
  25. metaTableTpl: [
  26. '{%if (this.openTableWrap)out.push(this.openTableWrap())%}',
  27. '&lt;table class=&quot;' + Ext.baseCSSPrefix + 'grid-table ' + Ext.baseCSSPrefix + 'grid-table-resizer&quot; border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; {[this.embedFullWidth(values)]}&gt;',
  28. '&lt;tbody&gt;',
  29. '&lt;tr class=&quot;' + Ext.baseCSSPrefix + 'grid-header-row&quot;&gt;',
  30. '&lt;tpl for=&quot;columns&quot;&gt;',
  31. '&lt;th class=&quot;' + Ext.baseCSSPrefix + 'grid-col-resizer-{id}&quot; style=&quot;width: {width}px; height: 0px;&quot;&gt;&lt;/th&gt;',
  32. '&lt;/tpl&gt;',
  33. '&lt;/tr&gt;',
  34. '{[this.openRows()]}',
  35. '{row}',
  36. '&lt;tpl for=&quot;features&quot;&gt;',
  37. '{[this.embedFeature(values, parent, xindex, xcount)]}',
  38. '&lt;/tpl&gt;',
  39. '{[this.closeRows()]}',
  40. '&lt;/tbody&gt;',
  41. '&lt;/table&gt;',
  42. '{%if (this.closeTableWrap)out.push(this.closeTableWrap())%}'
  43. ],
  44. constructor: function() {
  45. Ext.XTemplate.prototype.recurse = function(values, reference) {
  46. return this.apply(reference ? values[reference] : values);
  47. };
  48. },
  49. embedFeature: function(values, parent, x, xcount) {
  50. var tpl = '';
  51. if (!values.disabled) {
  52. tpl = values.getFeatureTpl(values, parent, x, xcount);
  53. }
  54. return tpl;
  55. },
  56. embedFullWidth: function(values) {
  57. var result = 'style=&quot;width:{fullWidth}px;';
  58. // If there are no records, we need to give the table a height so that it
  59. // is displayed and causes q scrollbar if the width exceeds the View's width.
  60. if (!values.rowCount) {
  61. result += 'height:1px;';
  62. }
  63. return result + '&quot;';
  64. },
  65. openRows: function() {
  66. return '&lt;tpl for=&quot;rows&quot;&gt;';
  67. },
  68. closeRows: function() {
  69. return '&lt;/tpl&gt;';
  70. },
  71. metaRowTpl: [
  72. '&lt;tr class=&quot;' + Ext.baseCSSPrefix + 'grid-row {[this.embedRowCls()]}&quot; {[this.embedRowAttr()]}&gt;',
  73. '&lt;tpl for=&quot;columns&quot;&gt;',
  74. '&lt;td class=&quot;{cls} ' + Ext.baseCSSPrefix + 'grid-cell ' + Ext.baseCSSPrefix + 'grid-cell-{columnId} {{id}-modified} {{id}-tdCls} {[this.firstOrLastCls(xindex, xcount)]}&quot; {{id}-tdAttr}&gt;',
  75. '&lt;div {unselectableAttr} class=&quot;' + Ext.baseCSSPrefix + 'grid-cell-inner {unselectableCls}&quot; style=&quot;text-align: {align}; {{id}-style};&quot;&gt;{{id}}&lt;/div&gt;',
  76. '&lt;/td&gt;',
  77. '&lt;/tpl&gt;',
  78. '&lt;/tr&gt;'
  79. ],
  80. firstOrLastCls: function(xindex, xcount) {
  81. if (xindex === 1) {
  82. return Ext.view.Table.prototype.firstCls;
  83. } else if (xindex === xcount) {
  84. return Ext.view.Table.prototype.lastCls;
  85. }
  86. },
  87. embedRowCls: function() {
  88. return '{rowCls}';
  89. },
  90. embedRowAttr: function() {
  91. return '{rowAttr}';
  92. },
  93. openTableWrap: undefined,
  94. closeTableWrap: undefined,
  95. getTableTpl: function(cfg, textOnly) {
  96. var tpl,
  97. tableTplMemberFns = {
  98. openRows: this.openRows,
  99. closeRows: this.closeRows,
  100. embedFeature: this.embedFeature,
  101. embedFullWidth: this.embedFullWidth,
  102. openTableWrap: this.openTableWrap,
  103. closeTableWrap: this.closeTableWrap
  104. },
  105. tplMemberFns = {},
  106. features = cfg.features || [],
  107. ln = features.length,
  108. i = 0,
  109. memberFns = {
  110. embedRowCls: this.embedRowCls,
  111. embedRowAttr: this.embedRowAttr,
  112. firstOrLastCls: this.firstOrLastCls,
  113. unselectableAttr: cfg.enableTextSelection ? '' : 'unselectable=&quot;on&quot;',
  114. unselectableCls: cfg.enableTextSelection ? '' : Ext.baseCSSPrefix + 'unselectable'
  115. },
  116. // copy the default
  117. metaRowTpl = Array.prototype.slice.call(this.metaRowTpl, 0),
  118. metaTableTpl;
  119. for (; i &lt; ln; i++) {
  120. if (!features[i].disabled) {
  121. features[i].mutateMetaRowTpl(metaRowTpl);
  122. Ext.apply(memberFns, features[i].getMetaRowTplFragments());
  123. Ext.apply(tplMemberFns, features[i].getFragmentTpl());
  124. Ext.apply(tableTplMemberFns, features[i].getTableFragments());
  125. }
  126. }
  127. metaRowTpl = new Ext.XTemplate(metaRowTpl.join(''), memberFns);
  128. cfg.row = metaRowTpl.applyTemplate(cfg);
  129. metaTableTpl = new Ext.XTemplate(this.metaTableTpl.join(''), tableTplMemberFns);
  130. tpl = metaTableTpl.applyTemplate(cfg);
  131. // TODO: Investigate eliminating.
  132. if (!textOnly) {
  133. tpl = new Ext.XTemplate(tpl, tplMemberFns);
  134. }
  135. return tpl;
  136. }
  137. });
  138. </pre>
  139. </body>
  140. </html>