TableLayout.html 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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-TableLayout'>/**
  19. </span> * Component layout for {@link Ext.view.Table}
  20. * @private
  21. *
  22. */
  23. Ext.define('Ext.view.TableLayout', {
  24. extend: 'Ext.layout.component.Auto',
  25. alias: ['layout.tableview'],
  26. type: 'tableview',
  27. beginLayout: function(ownerContext) {
  28. var me = this;
  29. me.callParent(arguments);
  30. // Grab ContextItem for the driving HeaderContainer and the table only if their is a table to size
  31. if (me.owner.table.dom) {
  32. ownerContext.tableContext = ownerContext.getEl(me.owner.table);
  33. // Grab a ContextItem for the header container
  34. ownerContext.headerContext = ownerContext.context.getCmp(me.headerCt);
  35. }
  36. },
  37. calculate: function(ownerContext) {
  38. var me = this;
  39. me.callParent(arguments);
  40. if (ownerContext.tableContext) {
  41. if (ownerContext.state.columnWidthsSynced) {
  42. if (ownerContext.hasProp('columnWidthsFlushed')) {
  43. ownerContext.tableContext.setHeight(ownerContext.tableContext.el.dom.offsetHeight, false);
  44. } else {
  45. me.done = false;
  46. }
  47. } else {
  48. if (ownerContext.headerContext.hasProp('columnWidthsDone')) {
  49. ownerContext.context.queueFlush(me);
  50. ownerContext.state.columnWidthsSynced = true;
  51. }
  52. // Either our base class (Auto) needs to measureContentHeight
  53. // if we are shrinkWrapHeight OR we need to measure the table
  54. // element height if we are not shrinkWrapHeight
  55. me.done = false;
  56. }
  57. }
  58. },
  59. measureContentHeight: function(ownerContext) {
  60. // Only able to produce a valid contentHeight if we have flushed all column widths to the table (or there's no table at all).
  61. if (!ownerContext.headerContext || ownerContext.hasProp('columnWidthsFlushed')) {
  62. return this.callParent(arguments);
  63. }
  64. },
  65. flush: function() {
  66. var me = this,
  67. context = me.ownerContext.context,
  68. columns = me.headerCt.getGridColumns(),
  69. i = 0, len = columns.length,
  70. el = me.owner.el,
  71. tableWidth = 0,
  72. colWidth;
  73. // So that the setProp can trigger this layout.
  74. context.currentLayout = me;
  75. // Set column width corresponding to each header
  76. for (i = 0; i &lt; len; i++) {
  77. colWidth = columns[i].hidden ? 0 : context.getCmp(columns[i]).props.width;
  78. tableWidth += colWidth;
  79. // Grab the col and set the width.
  80. // CSS class is generated in TableChunker.
  81. // Select composites because there may be several chunks.
  82. el.select(me.getColumnSelector(columns[i])).setWidth(colWidth);
  83. }
  84. el.select('table.' + Ext.baseCSSPrefix + 'grid-table-resizer').setWidth(tableWidth);
  85. // Now we can measure contentHeight if necessary (if we are height shrinkwrapped)
  86. me.ownerContext.setProp('columnWidthsFlushed', true);
  87. },
  88. finishedLayout: function(){
  89. var me = this,
  90. first;
  91. me.callParent(arguments);
  92. // In FF, in some cases during a resize or column hide/show, the &lt;td&gt; cells in
  93. // the grid won't respond to the new width set in the &lt;th&gt; at the top. So we
  94. // force a reflow of the table which seems to correct it. Related to EXTJSIV-6410
  95. if (Ext.isGecko) {
  96. first = me.headerCt.getGridColumns()[0];
  97. if (first) {
  98. first = me.owner.el.down(me.getColumnSelector(first));
  99. if (first) {
  100. first.setStyle('display', 'none');
  101. first.dom.scrollWidth;
  102. first.setStyle('display', '');
  103. }
  104. }
  105. }
  106. },
  107. getColumnSelector: function(column) {
  108. return 'th.' + Ext.baseCSSPrefix + 'grid-col-resizer-' + column.id;
  109. }
  110. });</pre>
  111. </body>
  112. </html>