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.

86 lines
3.1 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-list-Sorter-method-constructor'><span id='Ext-list-Sorter'>/**
  19. </span></span> * @class Ext.list.Sorter
  20. * @extends Ext.util.Observable
  21. * &lt;p&gt;Supporting Class for Ext.list.ListView&lt;/p&gt;
  22. * @constructor
  23. * @param {Object} config
  24. */
  25. Ext.list.Sorter = Ext.extend(Ext.util.Observable, {
  26. <span id='Ext-list-Sorter-cfg-sortClasses'> /**
  27. </span> * @cfg {Array} sortClasses
  28. * The CSS classes applied to a header when it is sorted. (defaults to &lt;tt&gt;[&quot;sort-asc&quot;, &quot;sort-desc&quot;]&lt;/tt&gt;)
  29. */
  30. sortClasses : [&quot;sort-asc&quot;, &quot;sort-desc&quot;],
  31. constructor: function(config){
  32. Ext.apply(this, config);
  33. Ext.list.Sorter.superclass.constructor.call(this);
  34. },
  35. <span id='Ext-list-Sorter-method-init'> init : function(listView){
  36. </span> this.view = listView;
  37. listView.on('render', this.initEvents, this);
  38. },
  39. <span id='Ext-list-Sorter-method-initEvents'> initEvents : function(view){
  40. </span> view.mon(view.innerHd, 'click', this.onHdClick, this);
  41. view.innerHd.setStyle('cursor', 'pointer');
  42. view.mon(view.store, 'datachanged', this.updateSortState, this);
  43. this.updateSortState.defer(10, this, [view.store]);
  44. },
  45. <span id='Ext-list-Sorter-method-updateSortState'> updateSortState : function(store){
  46. </span> var state = store.getSortState();
  47. if(!state){
  48. return;
  49. }
  50. this.sortState = state;
  51. var cs = this.view.columns, sortColumn = -1;
  52. for(var i = 0, len = cs.length; i &lt; len; i++){
  53. if(cs[i].dataIndex == state.field){
  54. sortColumn = i;
  55. break;
  56. }
  57. }
  58. if(sortColumn != -1){
  59. var sortDir = state.direction;
  60. this.updateSortIcon(sortColumn, sortDir);
  61. }
  62. },
  63. <span id='Ext-list-Sorter-method-updateSortIcon'> updateSortIcon : function(col, dir){
  64. </span> var sc = this.sortClasses;
  65. var hds = this.view.innerHd.select('em').removeClass(sc);
  66. hds.item(col).addClass(sc[dir == &quot;DESC&quot; ? 1 : 0]);
  67. },
  68. <span id='Ext-list-Sorter-method-onHdClick'> onHdClick : function(e){
  69. </span> var hd = e.getTarget('em', 3);
  70. if(hd &amp;&amp; !this.view.disableHeaders){
  71. var index = this.view.findHeaderIndex(hd);
  72. this.view.store.sort(this.view.columns[index].dataIndex);
  73. }
  74. }
  75. });
  76. // Backwards compatibility alias
  77. Ext.ListView.Sorter = Ext.list.Sorter;</pre>
  78. </body>
  79. </html>