-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi All,
is there a posibility to mark (e.g. blue background in the checkbox) a checkbox of an parent treeitem if a part of the child treeitems are selected.
The Microsoft style guild calls this: "mixed-state checkboxes". An example you can see here: http://msdn.microsoft.com/en-us/library/aa511496.aspx
regards,
Gunter
Hi, Gunter
Please refer to the sample:
<zk xmlns:w="client">
<style>
.mixed-state {
margin: 0px;
border: 2px solid #3E48AE;
}
</style>
<script type="text/javascript"><![CDATA[
zk.afterLoad("zul.sel", function () {
var oldSelect = zul.sel.Treeitem.prototype.doSelect_;
zul.sel.Treeitem.prototype.doSelect_ = function (evt) {
oldSelect.apply(this, arguments);
var $dom = jq(evt.domTarget),
row = $dom.hasClass('z-treerow')? $dom[0] : $dom.parents('.z-treerow')[0],
isSelected = jq(row).hasClass('z-treerow-seld'),
isSelfSelected = jq(this.treerow.$n()).hasClass('z-treerow-seld'),
_selectedChild = this._selectedChild,
index, isRecord;
if (!_selectedChild)
_selectedChild = this._selectedChild = [];
index = _selectedChild.indexOf(row);
isRecord = index > -1;
if (isSelected && !isRecord)
_selectedChild.push(row);
else if (!isSelected && isRecord)
_selectedChild.splice(index, 1);
if (_selectedChild.length > 0 && !isSelfSelected)
jq(this.treerow.$n()).find('.z-treerow-img-checkbox').addClass('mixed-state');
else
jq(this.treerow.$n()).find('.z-treerow-img-checkbox').removeClass('mixed-state');
}
});
]]></script>
<tree id="tree" rows="5" multiple="true" checkmark="true" height="400px">
<treecols>
<treecol label="Name"/>
<treecol label="Description"/>
</treecols>
<treechildren>
<treeitem>
<treerow>
<treecell label="Item 1"/>
<treecell label="Item 1 description"/>
</treerow>
</treeitem>
<treeitem>
<treerow>
<treecell label="Item 2"/>
<treecell label="Item 2 description"/>
</treerow>
<treechildren>
<treeitem>
<treerow>
<treecell label="Item 2.1"/>
</treerow>
<treechildren>
<treeitem>
<treerow>
<treecell label="Item 2.1.1"/>
</treerow>
</treeitem>
<treeitem>
<treerow>
<treecell label="Item 2.1.2"/>
</treerow>
</treeitem>
</treechildren>
</treeitem>
<treeitem>
<treerow>
<treecell label="Item 2.2"/>
<treecell label="Item 2.2 is something who cares"/>
</treerow>
</treeitem>
</treechildren>
</treeitem>
<treeitem label="Item 3"/>
</treechildren>
</tree>
</zk>
Regards,
Ben
Asked: 2012-04-10 11:24:09 +0800
Seen: 193 times
Last updated: Apr 11 '12