PDA

View Full Version : Can't prevent treepanel checkbox from being unselected.



xjscrafter
29 Oct 2014, 3:17 PM
In the below sample code, because my event handler returns false, the docs say the checkbox will not become unchecked, but it does not work. Basically I want to prevent the node checkbox from becoming checked. Please help!!!


Ext.define('MyTreeModel', {
extend: 'Ext.data.TreeModel',
proxy: {
type: 'memory'
},
fields: [
{ name: 'id', type: 'string'},
{ name: 'text', type: 'string'},
{ name: 'mounted', type: 'boolean'}
]
});


Ext.onReady(function() {
Ext.create('Ext.container.Viewport', {
renderTo: Ext.getBody(),
width: 700,
height: 500,
layout: 'fit',
items: [{
xtype: 'container',
width: 700,
height: 700,
layout: {
type: 'vbox',
align: 'stretch'
},
items: [{
xtype: 'treepanel',
store: Ext.create('Ext.data.TreeStore', {
model: 'MyTreeModel',
"root": {
"expanded": true,
"children": [
{ "text": "TopNodeOne", "expanded": true, "children": [
{ "text": "SubNodeOne", "expanded": true, "children": [
{ "text": "aaa", "leaf": true, checked: false, mounted: false },
{ "text": "bbb", "leaf": true, checked: false, mounted: false },
{ "text": "ccc", "leaf": true, checked: false, mounted: false }
]},
{ "text": "SubNodeTwo", "expanded": true, "children": [
{ "text": "ddd", "leaf": true, checked: true, mounted: true },
{ "text": "eee", "leaf": true, checked: false, mounted: false },
{ "text": "fff", "leaf": true, checked: false, mounted: false }
]}
]}
]
}
}),
rootVisible: false,
listeners: {
beforeitemclick: function(panel, record, item, index, e, eOpts) {
if(record.get('mounted')) {
return false;
} else {
return true;
}
},
beforecellclick: function(panel, td, cellIndex, record, tr, rowIndex, e, eOpts) {
if(record.get('mounted')) {
return false;
} else {
return true;
}
},
beforedeselect: function(panel, record, index, eOpts) {
if(record.get('mounted')) {
return false;
} else {
return true;
}
},
beforeselect: function(panel, record, index, eOpts) {
if(record.get('mounted')) {
return false;
} else {
return true;
}
}
}
}]
}]
});
});

xjscrafter
30 Oct 2014, 7:37 AM
Any insight into this?

xjscrafter
30 Oct 2014, 12:36 PM
Anyone? It just doesn't work as per the docs.

xjscrafter
30 Oct 2014, 3:34 PM
If I add the following, an extra column of checkboxes is added, and if its beforeselect returns false then its checkboxes are not selected, but I want this to happen on the checkboxes in the tree. Any ideas?


selModel: Ext.create('Ext.selection.CheckboxModel', {mode : 'SIMPLE'})

xjscrafter
31 Oct 2014, 10:02 AM
Any help.