PDA

View Full Version : TreePanel with CheckBox. Hot to uncheck|check neede node?



Forn
4 Oct 2012, 3:47 AM
Hello. On my treepanel component i have chackchange listeners:


wizardGenPrice_treeWarehouse_Checkchange: function(node, checked, eOpts){
if (!node.data.type){
//Disable checked.

}
}


What i must write to dechecked cheked node?
I can't found any suggest method in the documentation.

redraid
4 Oct 2012, 4:19 AM
Try this override:


Ext.override(Ext.tree.View, {
initComponent: function () {
this.addEvents(['beforecheckchange']);
this.callParent(arguments);
},
onCheckChange: function(record){
var checked = record.get('checked');
if (Ext.isBoolean(checked) && this.fireEvent('beforecheckchange', record, checked)) {
checked = !checked;
record.set('checked', checked);
this.fireEvent('checkchange', record, checked);
}
}
});

example:

var store = Ext.create('Ext.data.TreeStore', {
root: {
expanded: true,
children: [
{ text: "detention", leaf: true, checked: false },
{ text: "homework", expanded: true, children: [
{ text: "book report", leaf: true, checked: false },
{ text: "disabled", leaf: true, checked: true}
] },
{ text: "buy lottery tickets", leaf: true, checked: false }
]
}
});

Ext.create('Ext.tree.Panel', {
title: 'Simple Tree',
width: 200,
height: 150,
store: store,
rootVisible: false,
renderTo: Ext.getBody(),
viewConfig: {
listeners: {
beforecheckchange: function (node, checked) {
console.log('beforecheckchange', node);
if (node.get('text') == 'disabled') {
// Disable check change for disabled node
return false;
}
}
}
}
});
demo: http://jsfiddle.net/3c2Jz/1/