PDA

View Full Version : Check Tree item click event



Julia_Rakitina
18 Oct 2012, 11:12 PM
I have little problem :( Did not find solution yet. My user interface has Check Tree for controlling opened tabs( hide/show them oh check/uncheck). For navigation on tabs I use Check Tree itemclick in all checked tabs. But I need to check checkbox on itemclick event either. I have fired event ''checkchange", but it does not actually check node. What is the solution? Please help :)


var tree = Ext.create('Ext.tree.Panel', {
store: store,
rootVisible: false,
useArrows: true,
frame: true,
listeners : {
itemclick:function(node, rec){
var name=rec.get('id');
var records = tree.getView().getChecked();
var name_of_tab='#'+name;
tree.getView().fireEvent('checkchange',rec, true);
names = [];


Ext.Array.each(records, function(rec){
names.push(rec.get('id'));
});
if (include(names,name)==true){
Ext.getCmp('main').child(name_of_tab).tab.setVisible(true);
Ext.getCmp('main').setActiveTab(Ext.getCmp('main').child(name_of_tab));
}
},


checkchange : function(rec, check){


console.info(check);
var records = tree.getView().getChecked();
var name=rec.get('id');
names = [];


Ext.Array.each(records, function(rec){
names.push(rec.get('id'));
});


var name_of_tab='#'+name;


if (include(names,name)==true){
Ext.getCmp('main').child(name_of_tab).tab.setVisible(true);
Ext.getCmp('main').setActiveTab(Ext.getCmp('main').child(name_of_tab));
var store_load = Ext.data.StoreManager.get(name);
console.info(name);
store_load.load();
}
else{
Ext.getCmp('main').child(name_of_tab).tab.hide();
if (Ext.getCmp('main').getActiveTab()==Ext.getCmp('main').child(name_of_tab)){
Ext.getCmp('main').setActiveTab(Ext.getCmp('main').child('#main_page'));
}
};
}
}


});

VDP
19 Oct 2012, 12:00 AM
Don't know of I'm understanding correctly but I think you just want to be able to click on the item to check/uncheck the checkbox.

You can just add this line to the itemclick handler:


rec.set('checked',!rec.get('checked'));

this will check/uncheck and automatically fire the necessary events.

Here is a fiddle (http://jsfiddle.net/Vandeplas/qWygj/). I commented out a lot of not working or irrelevant code just for the example..

Julia_Rakitina
19 Oct 2012, 12:09 AM
Yes! Thank you so much! :D

tonyhhkx
18 Jun 2013, 2:40 AM
Edit: sorry i wrong :)