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.

223 lines
9.0 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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-layout-TableLayout'>/**
  19. </span> * @class Ext.layout.TableLayout
  20. * @extends Ext.layout.ContainerLayout
  21. * &lt;p&gt;This layout allows you to easily render content into an HTML table. The total number of columns can be
  22. * specified, and rowspan and colspan can be used to create complex layouts within the table.
  23. * This class is intended to be extended or created via the layout:'table' {@link Ext.Container#layout} config,
  24. * and should generally not need to be created directly via the new keyword.&lt;/p&gt;
  25. * &lt;p&gt;Note that when creating a layout via config, the layout-specific config properties must be passed in via
  26. * the {@link Ext.Container#layoutConfig} object which will then be applied internally to the layout. In the
  27. * case of TableLayout, the only valid layout config property is {@link #columns}. However, the items added to a
  28. * TableLayout can supply the following table-specific config properties:&lt;/p&gt;
  29. * &lt;ul&gt;
  30. * &lt;li&gt;&lt;b&gt;rowspan&lt;/b&gt; Applied to the table cell containing the item.&lt;/li&gt;
  31. * &lt;li&gt;&lt;b&gt;colspan&lt;/b&gt; Applied to the table cell containing the item.&lt;/li&gt;
  32. * &lt;li&gt;&lt;b&gt;cellId&lt;/b&gt; An id applied to the table cell containing the item.&lt;/li&gt;
  33. * &lt;li&gt;&lt;b&gt;cellCls&lt;/b&gt; A CSS class name added to the table cell containing the item.&lt;/li&gt;
  34. * &lt;/ul&gt;
  35. * &lt;p&gt;The basic concept of building up a TableLayout is conceptually very similar to building up a standard
  36. * HTML table. You simply add each panel (or &quot;cell&quot;) that you want to include along with any span attributes
  37. * specified as the special config properties of rowspan and colspan which work exactly like their HTML counterparts.
  38. * Rather than explicitly creating and nesting rows and columns as you would in HTML, you simply specify the
  39. * total column count in the layoutConfig and start adding panels in their natural order from left to right,
  40. * top to bottom. The layout will automatically figure out, based on the column count, rowspans and colspans,
  41. * how to position each panel within the table. Just like with HTML tables, your rowspans and colspans must add
  42. * up correctly in your overall layout or you'll end up with missing and/or extra cells! Example usage:&lt;/p&gt;
  43. * &lt;pre&gt;&lt;code&gt;
  44. // This code will generate a layout table that is 3 columns by 2 rows
  45. // with some spanning included. The basic layout will be:
  46. // +--------+-----------------+
  47. // | A | B |
  48. // | |--------+--------|
  49. // | | C | D |
  50. // +--------+--------+--------+
  51. var table = new Ext.Panel({
  52. title: 'Table Layout',
  53. layout:'table',
  54. defaults: {
  55. // applied to each contained panel
  56. bodyStyle:'padding:20px'
  57. },
  58. layoutConfig: {
  59. // The total column count must be specified here
  60. columns: 3
  61. },
  62. items: [{
  63. html: '&amp;lt;p&amp;gt;Cell A content&amp;lt;/p&amp;gt;',
  64. rowspan: 2
  65. },{
  66. html: '&amp;lt;p&amp;gt;Cell B content&amp;lt;/p&amp;gt;',
  67. colspan: 2
  68. },{
  69. html: '&amp;lt;p&amp;gt;Cell C content&amp;lt;/p&amp;gt;',
  70. cellCls: 'highlight'
  71. },{
  72. html: '&amp;lt;p&amp;gt;Cell D content&amp;lt;/p&amp;gt;'
  73. }]
  74. });
  75. &lt;/code&gt;&lt;/pre&gt;
  76. */
  77. Ext.layout.TableLayout = Ext.extend(Ext.layout.ContainerLayout, {
  78. <span id='Ext-layout-TableLayout-cfg-columns'> /**
  79. </span> * @cfg {Number} columns
  80. * The total number of columns to create in the table for this layout. If not specified, all Components added to
  81. * this layout will be rendered into a single row using one column per Component.
  82. */
  83. <span id='Ext-layout-TableLayout-property-monitorResize'> // private
  84. </span> monitorResize:false,
  85. <span id='Ext-layout-TableLayout-property-type'> type: 'table',
  86. </span>
  87. <span id='Ext-layout-TableLayout-property-targetCls'> targetCls: 'x-table-layout-ct',
  88. </span>
  89. <span id='Ext-layout-TableLayout-cfg-tableAttrs'> /**
  90. </span> * @cfg {Object} tableAttrs
  91. * &lt;p&gt;An object containing properties which are added to the {@link Ext.DomHelper DomHelper} specification
  92. * used to create the layout's &lt;tt&gt;&amp;lt;table&amp;gt;&lt;/tt&gt; element. Example:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;
  93. {
  94. xtype: 'panel',
  95. layout: 'table',
  96. layoutConfig: {
  97. tableAttrs: {
  98. style: {
  99. width: '100%'
  100. }
  101. },
  102. columns: 3
  103. }
  104. }&lt;/code&gt;&lt;/pre&gt;
  105. */
  106. tableAttrs:null,
  107. <span id='Ext-layout-TableLayout-method-setContainer'> // private
  108. </span> setContainer : function(ct){
  109. Ext.layout.TableLayout.superclass.setContainer.call(this, ct);
  110. this.currentRow = 0;
  111. this.currentColumn = 0;
  112. this.cells = [];
  113. },
  114. <span id='Ext-layout-TableLayout-method-onLayout'> // private
  115. </span> onLayout : function(ct, target){
  116. var cs = ct.items.items, len = cs.length, c, i;
  117. if(!this.table){
  118. target.addClass('x-table-layout-ct');
  119. this.table = target.createChild(
  120. Ext.apply({tag:'table', cls:'x-table-layout', cellspacing: 0, cn: {tag: 'tbody'}}, this.tableAttrs), null, true);
  121. }
  122. this.renderAll(ct, target);
  123. },
  124. <span id='Ext-layout-TableLayout-method-getRow'> // private
  125. </span> getRow : function(index){
  126. var row = this.table.tBodies[0].childNodes[index];
  127. if(!row){
  128. row = document.createElement('tr');
  129. this.table.tBodies[0].appendChild(row);
  130. }
  131. return row;
  132. },
  133. <span id='Ext-layout-TableLayout-method-getNextCell'> // private
  134. </span> getNextCell : function(c){
  135. var cell = this.getNextNonSpan(this.currentColumn, this.currentRow);
  136. var curCol = this.currentColumn = cell[0], curRow = this.currentRow = cell[1];
  137. for(var rowIndex = curRow; rowIndex &lt; curRow + (c.rowspan || 1); rowIndex++){
  138. if(!this.cells[rowIndex]){
  139. this.cells[rowIndex] = [];
  140. }
  141. for(var colIndex = curCol; colIndex &lt; curCol + (c.colspan || 1); colIndex++){
  142. this.cells[rowIndex][colIndex] = true;
  143. }
  144. }
  145. var td = document.createElement('td');
  146. if(c.cellId){
  147. td.id = c.cellId;
  148. }
  149. var cls = 'x-table-layout-cell';
  150. if(c.cellCls){
  151. cls += ' ' + c.cellCls;
  152. }
  153. td.className = cls;
  154. if(c.colspan){
  155. td.colSpan = c.colspan;
  156. }
  157. if(c.rowspan){
  158. td.rowSpan = c.rowspan;
  159. }
  160. this.getRow(curRow).appendChild(td);
  161. return td;
  162. },
  163. <span id='Ext-layout-TableLayout-method-getNextNonSpan'> // private
  164. </span> getNextNonSpan: function(colIndex, rowIndex){
  165. var cols = this.columns;
  166. while((cols &amp;&amp; colIndex &gt;= cols) || (this.cells[rowIndex] &amp;&amp; this.cells[rowIndex][colIndex])) {
  167. if(cols &amp;&amp; colIndex &gt;= cols){
  168. rowIndex++;
  169. colIndex = 0;
  170. }else{
  171. colIndex++;
  172. }
  173. }
  174. return [colIndex, rowIndex];
  175. },
  176. <span id='Ext-layout-TableLayout-method-renderItem'> // private
  177. </span> renderItem : function(c, position, target){
  178. // Ensure we have our inner table to get cells to render into.
  179. if(!this.table){
  180. this.table = target.createChild(
  181. Ext.apply({tag:'table', cls:'x-table-layout', cellspacing: 0, cn: {tag: 'tbody'}}, this.tableAttrs), null, true);
  182. }
  183. if(c &amp;&amp; !c.rendered){
  184. c.render(this.getNextCell(c));
  185. this.configureItem(c);
  186. }else if(c &amp;&amp; !this.isValidParent(c, target)){
  187. var container = this.getNextCell(c);
  188. container.insertBefore(c.getPositionEl().dom, null);
  189. c.container = Ext.get(container);
  190. this.configureItem(c);
  191. }
  192. },
  193. <span id='Ext-layout-TableLayout-method-isValidParent'> // private
  194. </span> isValidParent : function(c, target){
  195. return c.getPositionEl().up('table', 5).dom.parentNode === (target.dom || target);
  196. },
  197. <span id='Ext-layout-TableLayout-method-destroy'> destroy: function(){
  198. </span> delete this.table;
  199. Ext.layout.TableLayout.superclass.destroy.call(this);
  200. }
  201. <span id='Ext-layout-TableLayout-property-activeItem'> /**
  202. </span> * @property activeItem
  203. * @hide
  204. */
  205. });
  206. Ext.Container.LAYOUTS['table'] = Ext.layout.TableLayout;</pre>
  207. </body>
  208. </html>