PageRenderTime 51ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/ext-4.0.2a/docs/source/Sortable.html

https://github.com/ppound/content_model_viewer
HTML | 257 lines | 226 code | 31 blank | 0 comment | 0 complexity | 6629435885cde8f19225b9587cf9ed31 MD5 | raw file
  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="../prettify/prettify.css" type="text/css" rel="stylesheet" />
  7. <script type="text/javascript" src="../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-util-Sortable'>/**
  19. </span> * @class Ext.util.Sortable
  20. A mixin which allows a data component to be sorted. This is used by e.g. {@link Ext.data.Store} and {@link Ext.data.TreeStore}.
  21. **NOTE**: This mixin is mainly for internal library use and most users should not need to use it directly. It
  22. is more likely you will want to use one of the component classes that import this mixin, such as
  23. {@link Ext.data.Store} or {@link Ext.data.TreeStore}.
  24. * @markdown
  25. * @docauthor Tommy Maintz &lt;tommy@sencha.com&gt;
  26. */
  27. Ext.define(&quot;Ext.util.Sortable&quot;, {
  28. <span id='Ext-util-Sortable-property-isSortable'> /**
  29. </span> * @property isSortable
  30. * @type Boolean
  31. * Flag denoting that this object is sortable. Always true.
  32. */
  33. isSortable: true,
  34. <span id='Ext-util-Sortable-property-defaultSortDirection'> /**
  35. </span> * The default sort direction to use if one is not specified (defaults to &quot;ASC&quot;)
  36. * @property defaultSortDirection
  37. * @type String
  38. */
  39. defaultSortDirection: &quot;ASC&quot;,
  40. requires: [
  41. 'Ext.util.Sorter'
  42. ],
  43. <span id='Ext-util-Sortable-property-'> /**
  44. </span> * The property in each item that contains the data to sort.
  45. * @type String
  46. */
  47. <span id='Ext-util-Sortable-method-initSortable'> /**
  48. </span> * Performs initialization of this mixin. Component classes using this mixin should call this method
  49. * during their own initialization.
  50. */
  51. initSortable: function() {
  52. var me = this,
  53. sorters = me.sorters;
  54. <span id='Ext-util-Sortable-property-sorters'> /**
  55. </span> * The collection of {@link Ext.util.Sorter Sorters} currently applied to this Store
  56. * @property sorters
  57. * @type Ext.util.MixedCollection
  58. */
  59. me.sorters = Ext.create('Ext.util.AbstractMixedCollection', false, function(item) {
  60. return item.id || item.property;
  61. });
  62. if (sorters) {
  63. me.sorters.addAll(me.decodeSorters(sorters));
  64. }
  65. },
  66. <span id='Ext-util-Sortable-method-sort'> /**
  67. </span> * &lt;p&gt;Sorts the data in the Store by one or more of its properties. Example usage:&lt;/p&gt;
  68. &lt;pre&gt;&lt;code&gt;
  69. //sort by a single field
  70. myStore.sort('myField', 'DESC');
  71. //sorting by multiple fields
  72. myStore.sort([
  73. {
  74. property : 'age',
  75. direction: 'ASC'
  76. },
  77. {
  78. property : 'name',
  79. direction: 'DESC'
  80. }
  81. ]);
  82. &lt;/code&gt;&lt;/pre&gt;
  83. * &lt;p&gt;Internally, Store converts the passed arguments into an array of {@link Ext.util.Sorter} instances, and delegates the actual
  84. * sorting to its internal {@link Ext.util.MixedCollection}.&lt;/p&gt;
  85. * &lt;p&gt;When passing a single string argument to sort, Store maintains a ASC/DESC toggler per field, so this code:&lt;/p&gt;
  86. &lt;pre&gt;&lt;code&gt;
  87. store.sort('myField');
  88. store.sort('myField');
  89. &lt;/code&gt;&lt;/pre&gt;
  90. * &lt;p&gt;Is equivalent to this code, because Store handles the toggling automatically:&lt;/p&gt;
  91. &lt;pre&gt;&lt;code&gt;
  92. store.sort('myField', 'ASC');
  93. store.sort('myField', 'DESC');
  94. &lt;/code&gt;&lt;/pre&gt;
  95. * @param {String|Array} sorters Either a string name of one of the fields in this Store's configured {@link Ext.data.Model Model},
  96. * or an Array of sorter configurations.
  97. * @param {String} direction The overall direction to sort the data by. Defaults to &quot;ASC&quot;.
  98. */
  99. sort: function(sorters, direction, where, doSort) {
  100. var me = this,
  101. sorter, sorterFn,
  102. newSorters;
  103. if (Ext.isArray(sorters)) {
  104. doSort = where;
  105. where = direction;
  106. newSorters = sorters;
  107. }
  108. else if (Ext.isObject(sorters)) {
  109. doSort = where;
  110. where = direction;
  111. newSorters = [sorters];
  112. }
  113. else if (Ext.isString(sorters)) {
  114. sorter = me.sorters.get(sorters);
  115. if (!sorter) {
  116. sorter = {
  117. property : sorters,
  118. direction: direction
  119. };
  120. newSorters = [sorter];
  121. }
  122. else if (direction === undefined) {
  123. sorter.toggle();
  124. }
  125. else {
  126. sorter.setDirection(direction);
  127. }
  128. }
  129. if (newSorters &amp;&amp; newSorters.length) {
  130. newSorters = me.decodeSorters(newSorters);
  131. if (Ext.isString(where)) {
  132. if (where === 'prepend') {
  133. sorters = me.sorters.clone().items;
  134. me.sorters.clear();
  135. me.sorters.addAll(newSorters);
  136. me.sorters.addAll(sorters);
  137. }
  138. else {
  139. me.sorters.addAll(newSorters);
  140. }
  141. }
  142. else {
  143. me.sorters.clear();
  144. me.sorters.addAll(newSorters);
  145. }
  146. if (doSort !== false) {
  147. me.onBeforeSort(newSorters);
  148. }
  149. }
  150. if (doSort !== false) {
  151. sorters = me.sorters.items;
  152. if (sorters.length) {
  153. //construct an amalgamated sorter function which combines all of the Sorters passed
  154. sorterFn = function(r1, r2) {
  155. var result = sorters[0].sort(r1, r2),
  156. length = sorters.length,
  157. i;
  158. //if we have more than one sorter, OR any additional sorter functions together
  159. for (i = 1; i &lt; length; i++) {
  160. result = result || sorters[i].sort.call(this, r1, r2);
  161. }
  162. return result;
  163. };
  164. me.doSort(sorterFn);
  165. }
  166. }
  167. return sorters;
  168. },
  169. onBeforeSort: Ext.emptyFn,
  170. <span id='Ext-util-Sortable-method-decodeSorters'> /**
  171. </span> * @private
  172. * Normalizes an array of sorter objects, ensuring that they are all Ext.util.Sorter instances
  173. * @param {Array} sorters The sorters array
  174. * @return {Array} Array of Ext.util.Sorter objects
  175. */
  176. decodeSorters: function(sorters) {
  177. if (!Ext.isArray(sorters)) {
  178. if (sorters === undefined) {
  179. sorters = [];
  180. } else {
  181. sorters = [sorters];
  182. }
  183. }
  184. var length = sorters.length,
  185. Sorter = Ext.util.Sorter,
  186. fields = this.model ? this.model.prototype.fields : null,
  187. field,
  188. config, i;
  189. for (i = 0; i &lt; length; i++) {
  190. config = sorters[i];
  191. if (!(config instanceof Sorter)) {
  192. if (Ext.isString(config)) {
  193. config = {
  194. property: config
  195. };
  196. }
  197. Ext.applyIf(config, {
  198. root : this.sortRoot,
  199. direction: &quot;ASC&quot;
  200. });
  201. //support for 3.x style sorters where a function can be defined as 'fn'
  202. if (config.fn) {
  203. config.sorterFn = config.fn;
  204. }
  205. //support a function to be passed as a sorter definition
  206. if (typeof config == 'function') {
  207. config = {
  208. sorterFn: config
  209. };
  210. }
  211. // ensure sortType gets pushed on if necessary
  212. if (fields &amp;&amp; !config.transform) {
  213. field = fields.get(config.property);
  214. config.transform = field ? field.sortType : undefined;
  215. }
  216. sorters[i] = Ext.create('Ext.util.Sorter', config);
  217. }
  218. }
  219. return sorters;
  220. },
  221. getSorters: function() {
  222. return this.sorters.items;
  223. }
  224. });</pre>
  225. </body>
  226. </html>