GeorgeHernandez
2 Nov 2011, 9:19 AM
This is solves a common little problem, so I thought I'd share it. Double-clicking on a tree node will select its children (if any are not selected) or deselect its children (if all were selected). I used the beforeitemdblclick event instead of itemdblclick in order to avoid the auto-collapse of the children.
Ext.define('MyNS.controller.MyController', {
extend: 'Ext.app.Controller',
init: function () {
this.control({
'mytree': {beforeitemdblclick: this.clickChildren}
});
},
clickChildren: function (view, record, item, index, evObj, eOpts) {
var hasUnchecked = false;
record.eachChild(function (n) {
if (!n.data.checked) {
hasUnchecked = true;
}
});
if (hasUnchecked) {
record.eachChild(function (n) {
n.set('checked', true);
});
} else {
record.eachChild(function (n) {
n.set('checked', false);
});
}
return false; // Otherwise will collapse children
}
});
Ext.define('MyNS.controller.MyController', {
extend: 'Ext.app.Controller',
init: function () {
this.control({
'mytree': {beforeitemdblclick: this.clickChildren}
});
},
clickChildren: function (view, record, item, index, evObj, eOpts) {
var hasUnchecked = false;
record.eachChild(function (n) {
if (!n.data.checked) {
hasUnchecked = true;
}
});
if (hasUnchecked) {
record.eachChild(function (n) {
n.set('checked', true);
});
} else {
record.eachChild(function (n) {
n.set('checked', false);
});
}
return false; // Otherwise will collapse children
}
});