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; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-layout-container-CheckboxGroup'>/**
19 </span> * @class Ext.layout.container.CheckboxGroup
20 * @extends Ext.layout.container.Container
21 * <p>This layout implements the column arrangement for {@link Ext.form.CheckboxGroup} and {@link Ext.form.RadioGroup}.
22 * It groups the component's sub-items into columns based on the component's
23 * {@link Ext.form.CheckboxGroup#columns columns} and {@link Ext.form.CheckboxGroup#vertical} config properties.</p>
26 Ext.define('Ext.layout.container.CheckboxGroup', {
27 extend: 'Ext.layout.container.Container',
28 alias: ['layout.checkboxgroup'],
31 onLayout: function() {
32 var numCols = this.getColCount(),
33 shadowCt = this.getShadowCt(),
36 shadowItems = shadowCt.items,
37 numItems = items.length,
41 // Distribute the items into the appropriate column containers. We add directly to the
42 // containers' items collection rather than calling container.add(), because we need the
43 // checkboxes to maintain their original ownerCt. The distribution is done on each layout
44 // in case items have been added, removed, or reordered.
46 shadowItems.each(function(col) {
50 // If columns="auto", then the number of required columns may change as checkboxes are added/removed
51 // from the CheckboxGroup; adjust to match.
52 while (shadowItems.length > numCols) {
53 shadowCt.remove(shadowItems.last());
55 while (shadowItems.length < numCols) {
64 numRows = Math.ceil(numItems / numCols);
65 for (i = 0; i < numItems; i++) {
66 if (i > 0 && i % numRows === 0) {
69 shadowItems.getAt(colIndex).items.add(items.getAt(i));
72 for (i = 0; i < numItems; i++) {
73 colIndex = i % numCols;
74 shadowItems.getAt(colIndex).items.add(items.getAt(i));
78 if (!shadowCt.rendered) {
79 shadowCt.render(this.getRenderTarget());
81 // Ensure all items are rendered in the correct place in the correct column - this won't
82 // get done by the column containers themselves if their dimensions are not changing.
83 shadowItems.each(function(col) {
84 var layout = col.getLayout();
85 layout.renderItems(layout.getLayoutItems(), layout.getRenderTarget());
89 shadowCt.doComponentLayout();
93 // We don't want to render any items to the owner directly, that gets handled by each column's own layout
94 renderItems: Ext.emptyFn,
97 <span id='Ext-layout-container-CheckboxGroup-method-getShadowCt'> /**
99 * Creates and returns the shadow hbox container that will be used to arrange the owner's items
102 getShadowCt: function() {
104 shadowCt = me.shadowCt,
105 owner, items, item, columns, columnsIsArray, numCols, i;
108 // Create the column containers based on the owner's 'columns' config
110 columns = owner.columns;
111 columnsIsArray = Ext.isArray(columns);
112 numCols = me.getColCount();
114 for(i = 0; i < numCols; i++) {
119 if (columnsIsArray) {
120 // Array can contain mixture of whole numbers, used as fixed pixel widths, and fractional
121 // numbers, used as relative flex values.
122 if (columns[i] < 1) {
123 item.flex = columns[i];
125 item.width = columns[i];
129 // All columns the same width
135 // Create the shadow container; delay rendering until after items are added to the columns
136 shadowCt = me.shadowCt = Ext.createWidget('container', {
147 <span id='Ext-layout-container-CheckboxGroup-method-getColCount'> /**
148 </span> * @private Get the number of columns in the checkbox group
150 getColCount: function() {
151 var owner = this.owner,
152 colsCfg = owner.columns;
153 return Ext.isArray(colsCfg) ? colsCfg.length : (Ext.isNumber(colsCfg) ? colsCfg : owner.items.length);