PDA

View Full Version : Finding Treenode and have them selected



seawade
21 Feb 2012, 9:29 AM
Hi!

I'm trying to find a tree node with either name is ABC or ID (id of my data from sql) is 1.

tree is rendered with:


Ext.define('Sample.model.Category', {
extend: 'Ext.data.Model',

idProperty: 'id',

fields: [
{
name: 'id',
type: 'int'
},
{
name: 'name',
type: 'string'
},

And its store.

Tree is:


xtype: 'treepanel',
height: 553,
itemId: 'CategoryTree',
margin: '5 0 0 0',
maxHeight: 553,
minHeight: 553,
collapsed: false,
store: 'StoresCategories',
viewConfig: {
rootVisible: false
},
columns: [
{
xtype: 'treecolumn',
dataIndex: 'name',
flex: 1,
text: 'Name'
},
{
xtype: 'gridcolumn',
dataIndex: 'status',
text: 'Value'
}

After rendered, how do I find a node with either name of ABC or better yet ID of 1. (also do I need to have ID as gridcolumn dataIndex to find by id or model def good enough?) I'm trying to select category of an item preselected to be submitted along with form data.

I'm trying following without success..

var record = abstractcomponent.getRootNode().findChild('name','ABC',true);
abstractcomponent.getSelectionModel().select(record);

Thank you in advance, any pointers are greatly appreciated!

mitchellsimoens
21 Feb 2012, 11:36 AM
The TreeStore has a getNodeById. Is that what you would need?

seawade
21 Feb 2012, 12:19 PM
Hi!

Thank you for your reply!
I'm trying with..

var record = abstractcomponent.getStore().getNodeById(1);

record is always null, I'm trying to get the top node to test.

abstractcomponent is onTreepanelAfterRender: function

of course.. without success! :-) I must be doing wrong, if you can punch me to the direction please..
Model of this treestore has idProperty: set to 'id' which is populated (i'm checking from designer/json viewer).
But I did not put ID as one of the treepanel's grid column (tree is treegrid).
I am assuming this is not a problem? as long as the store has id even though not displayed from tree?

(this is another issue) Another thing I am kind of suspecting is that tree.expandAll() only opens partially. I think I'm calling it too quick after render? (call from afterrender of treepanel) Or do I need to call multiple times to open all sub nodes?

Thank you in advance!!

seawade
21 Feb 2012, 1:07 PM
Just in case,

I post how I set up tree


Ext.define('Sample.view.ui.MyTreePanel2', {
extend: 'Ext.tree.Panel',

height: 553,
itemId: 'CategoryTree',
margin: '5 0 0 0',
maxHeight: 553,
minHeight: 553,
collapsed: false,
store: 'StoresCategories',

initComponent: function() {
var me = this;

Ext.applyIf(me, {
viewConfig: {
rootVisible: false
},
columns: [
{
xtype: 'treecolumn',
dataIndex: 'name',
flex: 1,
text: 'Name'
},
{
xtype: 'gridcolumn',
dataIndex: 'status',
text: 'Value'
}
]
});

me.callParent(arguments);
}

});



extend: 'Ext.data.Model',

idProperty: 'id',

fields: [
{
name: 'id',
type: 'int'
},
{
name: 'name',
type: 'string'
},
{
name: 'sort',
type: 'int'
},
{
name: 'status',
type: 'int'
},
{
name: 'leaf',
type: 'boolean'
}
]
});

vietits
21 Feb 2012, 6:41 PM
Let try with 'load' event instead of 'afterrender'.