1 <!DOCTYPE html><html><head><title>Sencha Documentation Project</title><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../prettify.css" type="text/css"><link rel="stylesheet" href="../prettify_sa.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script></head><body onload="prettyPrint()"><pre class="prettyprint"><pre><span id='Ext-layout.container.CheckboxGroup'>/**
2 </span> * @class Ext.layout.container.CheckboxGroup
3 * @extends Ext.layout.container.Container
4 * <p>This layout implements the column arrangement for {@link Ext.form.CheckboxGroup} and {@link Ext.form.RadioGroup}.
5 * It groups the component's sub-items into columns based on the component's
6 * {@link Ext.form.CheckboxGroup#columns columns} and {@link Ext.form.CheckboxGroup#vertical} config properties.</p>
9 Ext.define('Ext.layout.container.CheckboxGroup', {
10 extend: 'Ext.layout.container.Container',
11 alias: ['layout.checkboxgroup'],
14 onLayout: function() {
15 var numCols = this.getColCount(),
16 shadowCt = this.getShadowCt(),
19 shadowItems = shadowCt.items,
20 numItems = items.length,
24 // Distribute the items into the appropriate column containers. We add directly to the
25 // containers' items collection rather than calling container.add(), because we need the
26 // checkboxes to maintain their original ownerCt. The distribution is done on each layout
27 // in case items have been added, removed, or reordered.
29 shadowItems.each(function(col) {
33 // If columns="auto", then the number of required columns may change as checkboxes are added/removed
34 // from the CheckboxGroup; adjust to match.
35 while (shadowItems.length > numCols) {
36 shadowCt.remove(shadowItems.last());
38 while (shadowItems.length < numCols) {
47 numRows = Math.ceil(numItems / numCols);
48 for (i = 0; i < numItems; i++) {
49 if (i > 0 && i % numRows === 0) {
52 shadowItems.getAt(colIndex).items.add(items.getAt(i));
55 for (i = 0; i < numItems; i++) {
56 colIndex = i % numCols;
57 shadowItems.getAt(colIndex).items.add(items.getAt(i));
61 if (!shadowCt.rendered) {
62 shadowCt.render(this.getRenderTarget());
64 // Ensure all items are rendered in the correct place in the correct column - this won't
65 // get done by the column containers themselves if their dimensions are not changing.
66 shadowItems.each(function(col) {
67 var layout = col.getLayout();
68 layout.renderItems(layout.getLayoutItems(), layout.getRenderTarget());
72 shadowCt.doComponentLayout();
76 // We don't want to render any items to the owner directly, that gets handled by each column's own layout
77 renderItems: Ext.emptyFn,
80 <span id='Ext-layout.container.CheckboxGroup-method-getShadowCt'> /**
82 * Creates and returns the shadow hbox container that will be used to arrange the owner's items
85 getShadowCt: function() {
87 shadowCt = me.shadowCt,
88 owner, items, item, columns, columnsIsArray, numCols, i;
91 // Create the column containers based on the owner's 'columns' config
93 columns = owner.columns;
94 columnsIsArray = Ext.isArray(columns);
95 numCols = me.getColCount();
97 for(i = 0; i < numCols; i++) {
102 if (columnsIsArray) {
103 // Array can contain mixture of whole numbers, used as fixed pixel widths, and fractional
104 // numbers, used as relative flex values.
105 if (columns[i] < 1) {
106 item.flex = columns[i];
108 item.width = columns[i];
112 // All columns the same width
118 // Create the shadow container; delay rendering until after items are added to the columns
119 shadowCt = me.shadowCt = Ext.createWidget('container', {
130 <span id='Ext-layout.container.CheckboxGroup-method-getColCount'> /**
131 </span> * @private Get the number of columns in the checkbox group
133 getColCount: function() {
134 var owner = this.owner,
135 colsCfg = owner.columns;
136 return Ext.isArray(colsCfg) ? colsCfg.length : (Ext.isNumber(colsCfg) ? colsCfg : owner.items.length);
140 </pre></pre></body></html>