RowBody.html 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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-grid-feature-RowBody'>/**
  19. </span> * The rowbody feature enhances the grid's markup to have an additional
  20. * tr -&gt; td -&gt; div which spans the entire width of the original row.
  21. *
  22. * This is useful to to associate additional information with a particular
  23. * record in a grid.
  24. *
  25. * Rowbodies are initially hidden unless you override getAdditionalData.
  26. *
  27. * Will expose additional events on the gridview with the prefix of 'rowbody'.
  28. * For example: 'rowbodyclick', 'rowbodydblclick', 'rowbodycontextmenu'.
  29. *
  30. * # Example
  31. *
  32. * @example
  33. * Ext.define('Animal', {
  34. * extend: 'Ext.data.Model',
  35. * fields: ['name', 'latin', 'desc']
  36. * });
  37. *
  38. * Ext.create('Ext.grid.Panel', {
  39. * width: 400,
  40. * height: 300,
  41. * renderTo: Ext.getBody(),
  42. * store: {
  43. * model: 'Animal',
  44. * data: [
  45. * {name: 'Tiger', latin: 'Panthera tigris',
  46. * desc: 'The largest cat species, weighing up to 306 kg (670 lb).'},
  47. * {name: 'Roman snail', latin: 'Helix pomatia',
  48. * desc: 'A species of large, edible, air-breathing land snail.'},
  49. * {name: 'Yellow-winged darter', latin: 'Sympetrum flaveolum',
  50. * desc: 'A dragonfly found in Europe and mid and Northern China.'},
  51. * {name: 'Superb Fairy-wren', latin: 'Malurus cyaneus',
  52. * desc: 'Common and familiar across south-eastern Australia.'}
  53. * ]
  54. * },
  55. * columns: [{
  56. * dataIndex: 'name',
  57. * text: 'Common name',
  58. * width: 125
  59. * }, {
  60. * dataIndex: 'latin',
  61. * text: 'Scientific name',
  62. * flex: 1
  63. * }],
  64. * features: [{
  65. * ftype: 'rowbody',
  66. * getAdditionalData: function(data, rowIndex, record, orig) {
  67. * var headerCt = this.view.headerCt,
  68. * colspan = headerCt.getColumnCount();
  69. * // Usually you would style the my-body-class in CSS file
  70. * return {
  71. * rowBody: '&lt;div style=&quot;padding: 1em&quot;&gt;'+record.get(&quot;desc&quot;)+'&lt;/div&gt;',
  72. * rowBodyCls: &quot;my-body-class&quot;,
  73. * rowBodyColspan: colspan
  74. * };
  75. * }
  76. * }]
  77. * });
  78. */
  79. Ext.define('Ext.grid.feature.RowBody', {
  80. extend: 'Ext.grid.feature.Feature',
  81. alias: 'feature.rowbody',
  82. rowBodyHiddenCls: Ext.baseCSSPrefix + 'grid-row-body-hidden',
  83. rowBodyTrCls: Ext.baseCSSPrefix + 'grid-rowbody-tr',
  84. rowBodyTdCls: Ext.baseCSSPrefix + 'grid-cell-rowbody',
  85. rowBodyDivCls: Ext.baseCSSPrefix + 'grid-rowbody',
  86. eventPrefix: 'rowbody',
  87. eventSelector: '.' + Ext.baseCSSPrefix + 'grid-rowbody-tr',
  88. getRowBody: function(values) {
  89. return [
  90. '&lt;tr class=&quot;' + this.rowBodyTrCls + ' {rowBodyCls}&quot;&gt;',
  91. '&lt;td class=&quot;' + this.rowBodyTdCls + '&quot; colspan=&quot;{rowBodyColspan}&quot;&gt;',
  92. '&lt;div class=&quot;' + this.rowBodyDivCls + '&quot;&gt;{rowBody}&lt;/div&gt;',
  93. '&lt;/td&gt;',
  94. '&lt;/tr&gt;'
  95. ].join('');
  96. },
  97. // injects getRowBody into the metaRowTpl.
  98. getMetaRowTplFragments: function() {
  99. return {
  100. getRowBody: this.getRowBody,
  101. rowBodyTrCls: this.rowBodyTrCls,
  102. rowBodyTdCls: this.rowBodyTdCls,
  103. rowBodyDivCls: this.rowBodyDivCls
  104. };
  105. },
  106. mutateMetaRowTpl: function(metaRowTpl) {
  107. metaRowTpl.push('{[this.getRowBody(values)]}');
  108. },
  109. <span id='Ext-grid-feature-RowBody-method-getAdditionalData'> /**
  110. </span> * Provides additional data to the prepareData call within the grid view.
  111. * The rowbody feature adds 3 additional variables into the grid view's template.
  112. * These are rowBodyCls, rowBodyColspan, and rowBody.
  113. * @param {Object} data The data for this particular record.
  114. * @param {Number} idx The row index for this record.
  115. * @param {Ext.data.Model} record The record instance
  116. * @param {Object} orig The original result from the prepareData call to massage.
  117. */
  118. getAdditionalData: function(data, idx, record, orig) {
  119. var headerCt = this.view.headerCt,
  120. colspan = headerCt.getColumnCount();
  121. return {
  122. rowBody: &quot;&quot;,
  123. rowBodyCls: this.rowBodyCls,
  124. rowBodyColspan: colspan
  125. };
  126. }
  127. });</pre>
  128. </body>
  129. </html>