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.

134 lines
6.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-grid-CheckboxSelectionModel-method-constructor'><span id='Ext-grid-CheckboxSelectionModel'>/**
  19. </span></span> * @class Ext.grid.CheckboxSelectionModel
  20. * @extends Ext.grid.RowSelectionModel
  21. * A custom selection model that renders a column of checkboxes that can be toggled to select or deselect rows.
  22. * @constructor
  23. * @param {Object} config The configuration options
  24. */
  25. Ext.grid.CheckboxSelectionModel = Ext.extend(Ext.grid.RowSelectionModel, {
  26. <span id='Ext-grid-CheckboxSelectionModel-cfg-checkOnly'> /**
  27. </span> * @cfg {Boolean} checkOnly &lt;tt&gt;true&lt;/tt&gt; if rows can only be selected by clicking on the
  28. * checkbox column (defaults to &lt;tt&gt;false&lt;/tt&gt;).
  29. */
  30. <span id='Ext-grid-CheckboxSelectionModel-cfg-header'> /**
  31. </span> * @cfg {String} header Any valid text or HTML fragment to display in the header cell for the
  32. * checkbox column. Defaults to:&lt;pre&gt;&lt;code&gt;
  33. * '&amp;lt;div class=&quot;x-grid3-hd-checker&quot;&gt;&amp;#38;#160;&amp;lt;/div&gt;'&lt;/tt&gt;
  34. * &lt;/code&gt;&lt;/pre&gt;
  35. * The default CSS class of &lt;tt&gt;'x-grid3-hd-checker'&lt;/tt&gt; displays a checkbox in the header
  36. * and provides support for automatic check all/none behavior on header click. This string
  37. * can be replaced by any valid HTML fragment, including a simple text string (e.g.,
  38. * &lt;tt&gt;'Select Rows'&lt;/tt&gt;), but the automatic check all/none behavior will only work if the
  39. * &lt;tt&gt;'x-grid3-hd-checker'&lt;/tt&gt; class is supplied.
  40. */
  41. header : '&lt;div class=&quot;x-grid3-hd-checker&quot;&gt;&amp;#160;&lt;/div&gt;',
  42. <span id='Ext-grid-CheckboxSelectionModel-cfg-width'> /**
  43. </span> * @cfg {Number} width The default width in pixels of the checkbox column (defaults to &lt;tt&gt;20&lt;/tt&gt;).
  44. */
  45. width : 20,
  46. <span id='Ext-grid-CheckboxSelectionModel-cfg-sortable'> /**
  47. </span> * @cfg {Boolean} sortable &lt;tt&gt;true&lt;/tt&gt; if the checkbox column is sortable (defaults to
  48. * &lt;tt&gt;false&lt;/tt&gt;).
  49. */
  50. sortable : false,
  51. <span id='Ext-grid-CheckboxSelectionModel-property-menuDisabled'> // private
  52. </span> menuDisabled : true,
  53. <span id='Ext-grid-CheckboxSelectionModel-property-fixed'> fixed : true,
  54. </span><span id='Ext-grid-CheckboxSelectionModel-property-hideable'> hideable: false,
  55. </span><span id='Ext-grid-CheckboxSelectionModel-property-dataIndex'> dataIndex : '',
  56. </span><span id='Ext-grid-CheckboxSelectionModel-property-id'> id : 'checker',
  57. </span><span id='Ext-grid-CheckboxSelectionModel-method-constructor'><span id='Ext-grid-CheckboxSelectionModel-property-isColumn'> isColumn: true, // So that ColumnModel doesn't feed this through the Column constructor
  58. </span></span>
  59. constructor : function(){
  60. Ext.grid.CheckboxSelectionModel.superclass.constructor.apply(this, arguments);
  61. if(this.checkOnly){
  62. this.handleMouseDown = Ext.emptyFn;
  63. }
  64. },
  65. <span id='Ext-grid-CheckboxSelectionModel-method-initEvents'> // private
  66. </span> initEvents : function(){
  67. Ext.grid.CheckboxSelectionModel.superclass.initEvents.call(this);
  68. this.grid.on('render', function(){
  69. Ext.fly(this.grid.getView().innerHd).on('mousedown', this.onHdMouseDown, this);
  70. }, this);
  71. },
  72. <span id='Ext-grid-CheckboxSelectionModel-method-processEvent'> /**
  73. </span> * @private
  74. * Process and refire events routed from the GridView's processEvent method.
  75. */
  76. processEvent : function(name, e, grid, rowIndex, colIndex){
  77. if (name == 'mousedown') {
  78. this.onMouseDown(e, e.getTarget());
  79. return false;
  80. } else {
  81. return Ext.grid.Column.prototype.processEvent.apply(this, arguments);
  82. }
  83. },
  84. <span id='Ext-grid-CheckboxSelectionModel-method-onMouseDown'> // private
  85. </span> onMouseDown : function(e, t){
  86. if(e.button === 0 &amp;&amp; t.className == 'x-grid3-row-checker'){ // Only fire if left-click
  87. e.stopEvent();
  88. var row = e.getTarget('.x-grid3-row');
  89. if(row){
  90. var index = row.rowIndex;
  91. if(this.isSelected(index)){
  92. this.deselectRow(index);
  93. }else{
  94. this.selectRow(index, true);
  95. this.grid.getView().focusRow(index);
  96. }
  97. }
  98. }
  99. },
  100. <span id='Ext-grid-CheckboxSelectionModel-method-onHdMouseDown'> // private
  101. </span> onHdMouseDown : function(e, t) {
  102. if(t.className == 'x-grid3-hd-checker'){
  103. e.stopEvent();
  104. var hd = Ext.fly(t.parentNode);
  105. var isChecked = hd.hasClass('x-grid3-hd-checker-on');
  106. if(isChecked){
  107. hd.removeClass('x-grid3-hd-checker-on');
  108. this.clearSelections();
  109. }else{
  110. hd.addClass('x-grid3-hd-checker-on');
  111. this.selectAll();
  112. }
  113. }
  114. },
  115. <span id='Ext-grid-CheckboxSelectionModel-method-renderer'> // private
  116. </span> renderer : function(v, p, record){
  117. return '&lt;div class=&quot;x-grid3-row-checker&quot;&gt;&amp;#160;&lt;/div&gt;';
  118. },
  119. <span id='Ext-grid-CheckboxSelectionModel-method-onEditorSelect'> onEditorSelect: function(row, lastRow){
  120. </span> if(lastRow != row &amp;&amp; !this.checkOnly){
  121. this.selectRow(row); // *** highlight newly-selected cell and update selection
  122. }
  123. }
  124. });</pre>
  125. </body>
  126. </html>