I have a treepanel and i try to get node when i selected like http://jsfiddle.net/kTedM/
Ext.create('Ext.tree.Panel', {
title: 'Simple Tree',
width: 200,
height: 200,
store: store,
rootVisible: false,
dockedItems: [{
xtype: 'toolbar',
items: {
text: 'Get Selected nodes',
handler: function(){
var s = this.up('panel').getSelectionModel().getSelection();
if (s[0])
alert(s[0].data.text + ' was selected');
else alert('no selected');
}
}
}],
renderTo: Ext.getBody()
});
But If u follow below step u will see bug.
step1: run code and click get selected nodes u will get correct alert is no selected
step2: Double click in homework node and click get selected nodes u will see
But i see that node's not selected? How to fix that thanks
Actually, the 'homework' node is and should be selected. There's no reason that double-clicking it should deselect it.
The bug is that the fact that this node is selected is not correctly represented visually. Clearly a bug.
It has been fixed by Sencha in Ext4.2. See this update of your fiddle; I've just changed the version to 4.2.0 and there's nothing surprising going on...
So, to answer your very question, I'd say that in order to fix it, you just have to upgrade to the last version. I advice against the very last 4.2.1 that introduces several new bugs, but rather for the 4.2.0.x.
Now, here's some code, because I am forced by SO to post some in order to be allowed to link to the fiddle:
// Same code as you
Ext.onReady(function () {
var store = Ext.create('Ext.data.TreeStore', {
fields: [
{name: 'id', type: 'string'},
{name: 'text', type: 'string'},
{name: 'selected', type: 'string'}
],
root: {
expanded: true,
id: '0',
children: [{
text: "detention",
id: '1',
leaf: true
}, {
text: "homework",
id: '2',
expanded: true,
children: [{
id: '3',
text: "book report",
leaf: true
}, {
id: '4',
text: "alegrbra",
leaf: true,
selected: 'true'
}]
}, {
id: '5',
text: "buy lottery tickets",
leaf: true
}]
}
});
Ext.create('Ext.tree.Panel', {
title: 'Simple Tree',
width: 200,
height: 200,
store: store,
rootVisible: false,
dockedItems: [{
xtype: 'toolbar',
items: {
text: 'Get Selected nodes',
handler: function(){
var s = this.up('panel').getSelectionModel().getSelection();
if (s[0])
alert(s[0].data.text + ' was selected');
else alert('no selected');
}
}
}],
renderTo: Ext.getBody()
});
});
Related
I need to create a child in a tree view how to do that kindly help. I have tried like this but it's not working.
var myLocations = new Ext.Panel({
title: 'my work',
id: 'student',
height: 100,
autoScroll: true,
iconCls: 'myPanel',
// ,autoLoad: { url: 'UserLocDetails.aspx?UserName=' + strUser }
children: [{
text: "Leaf node (<i>no folder/arrow icon</i>)",
title: 'dasdasd',
leaf: true,
id: 'myLoc',
qtitle: 'Sample Tip Title',
qtip: 'Tip body'
}]
});
You need to create a TreeStore in order to store data for a tree, and some component that can display a tree, for example a TreePanel. Try the following code, it is for Ext JS 7.3.0 Classic Material, but can be adopted to other versions:
Ext.define('myTreeStore', {
extend: 'Ext.data.TreeStore',
root: {
expanded: true
},
proxy: {
type: 'memory',
reader: {
type: 'json'
}
},
data: {
children: [{
text: 'Main 1',
leaf: true
}, {
text: 'Main 2',
children: [{
text: 'Sub 21',
leaf: true
},{
text: 'Sub 22',
leaf: true
}]
}, {
text: 'Main 3',
leaf: true
}]
}
})
Ext.application({
name: 'Fiddle',
launch: function () {
const treeStore = Ext.create('myTreeStore');
Ext.create('Ext.tree.Panel', {
rootVisible: false,
renderTo: Ext.getBody(),
title: 'Tree Example',
width: 400,
store: treeStore,
});
}
});
I am using EXTJS and I want to create my TreePanel with one more icon to the right that will be set to indicate something has changed. I am struggling to do this as I am unsure where I can modify these properties. It would be easy with HTML alone but obviously this framework is useful and I need to integrate these changes into it.
Thanks,
Dan
Yes, there is way to handle it in ExtJS framework with renderer method on column.
Here is how I would achieve it using ExtJS 6.0.x:
Ext.create('Ext.container.Viewport', {
layout: 'fit',
items: [{
xtype: 'container',
scrollable: 'y',
flex: 1,
layout: {
type: 'hbox',
alignt: 'stretchmax'
},
items: [{
xtype: 'treepanel',
rootVisible: false,
flex: 1,
store: {
type: 'tree',
parentIdProperty: 'parentId',
root: {
text: 'Navigation Bar',
expanded: true,
children: [{
text: 'Parts',
children: [{
leaf: true,
itemId: 'addPart',
text: 'Add new part',
changed: true
}, {
leaf: true,
itemId: 'manageParts',
text: 'Manage Parts',
changed: false
}, ]
}, {
leaf: true,
itemId: 'announcements',
text: 'Announcements',
changed: true
}]
}
},
columns: [{
text: 'Code',
dataIndex: 'codigo',
align: 'left'
}, {
xtype: 'treecolumn',
text: 'Description',
dataIndex: 'text',
flex: 1
}, {
text: 'Edited',
iconCls: 'x-fa fa-edit',
align: 'center',
flex: 1,
renderer: function (f, grid, record) {
if(record.get('changed') === true) {
return "Changed Icon here"
}
else {
return "Not changed icon here";
}
}
}]
}]
}]
});
With this you can easily manage the data with store and can easily update the data in store. ExtJS will take care of rendering the given configuration for columns.
You can also use actioncolumn to show icons/buttons and handle events with listeners.
Example Fiddle: https://fiddle.sencha.com/#view/editor&fiddle/28qm
I Have solved the problem. You can embed html into the text field in the store.
Ext.define('MyApp.store.Navigation', {
extend: 'Ext.data.TreeStore',
alias: 'store.navigation',
rootData: {
text: 'Navigation Bar',
expanded: true,
children: [
{
text: 'Parts',
children: [
{ leaf:true, itemId:'addPart', text: 'Add new part' },
{ leaf:true, itemId:'manageParts', text: 'Manage Parts <b>here</b>' },
]
},
{
leaf:true, itemId:'announcements', text: 'Announcements'
}
]
},
constructor: function (config) {
// Since records claim the data object given to them, clone the data
// for each instance.
config = Ext.apply({
root: Ext.clone(this.rootData)
}, config);
this.callParent([config]);
}
});
Probably a poor solution but gets the job done.
Is there a way to hide a node (a parent or a child) in a treegrid? I set the visible property to false but it does not disappear: (here is the fiddle link: https://fiddle.sencha.com/#fiddle/jl1)
var tree = Ext.create('Ext.tree.Panel', {
renderTo: Ext.getBody(),
title: 'TreeGrid',
width: 300,
height: 250,
fields: ['name', 'description'],
columns: [{
xtype: 'treecolumn',
text: 'Name',
dataIndex: 'name',
width: 150,
sortable: true
}, {
text: 'Description',
dataIndex: 'description',
flex: 1,
sortable: true
}],
root: {
expanded: true,
children: [{
name: 'Group 1',
expanded: true,
children: [{
name: 'Child 1.1',
description: 'Description 1.1',
leaf: true
},{
name: 'Child 1.2',
description: 'Description 1.2',
leaf: true
}]
}, {
name: 'Group 2',
expanded: true,
children: [{
name: 'Child 2.1',
description: 'Description 2.1',
leaf: true
},{
name: 'Child 2.2',
description: 'Description 2.2',
leaf: true
}]
}]
}
});
var button = Ext.create('Ext.button.Button', {
renderTo: Ext.getBody(),
text: 'Remove group 1',
handler: function() {
var group1 = tree.getRootNode().childNodes[0];
group1.set('visible', false);
}
});
Note: I don't want to remove the node, I want to hide it, to show it again later (I want to do this because the remove/add behaviour on tree grid is very bugged :S) !
Thanks in advance :) !
You should work with tree store. Use filters to hide values from the tree.
I've fixed your fiddle. https://fiddle.sencha.com/#fiddle/jl8
I used filterBy method to fix it. If the function returns true the Record is included to a tree, otherwise it is filtered out.
Here is some more documentation about that topic http://docs.sencha.com/extjs/5.1/5.1.0-apidocs/#!/api/Ext.data.TreeStore
I'm trying to set a different root node in my TreeStore in Ext JS 4.0.7, but I can't seem to do it correctly... I don't know if it's another bug in the framework or if I'm just using the functions incorrectly, so I'm asking for help. Here is the code that I'm working with.
Creating a blank node to use later on
var node = {
id: 'root',
text: 'root',
expanded: true,
children: [{
id: 'child1',
text: 'child1',
leaf: true
},{
id: 'child2',
text: 'child2',
leaf: true
}]
};
The store
var store = Ext.create('Ext.data.TreeStore', {
storeId: 'treestore',
proxy: {
type: 'memory',
reader: {
type: 'json'
}
},
snapshot: node,
root: {
id: 'root',
text: 'root',
expanded: true,
children: [{
id: 'dummy1',
text: 'dummy1',
leaf: true
},{
id: 'dummy2',
text: 'dummy2',
leaf: true
}]
}
});
Tree Panel
Ext.create('Ext.tree.Panel', {
store: store,
renderTo: Ext.getBody(),
height: 600,
width: 600,
id: 'mytree',
tbar: [{
xtype: 'button',
text: 'set child1 as root',
handler: function() {
var store = Ext.getCmp('mytree').store;
store.setRootNode(store.snapshot);
alert(store.getNodeById('child1').data.id); // alerts child1
}
},{
xtype: 'button',
text: 'set dummy1 as root',
handler: function() {
var store = Ext.getCmp('mytree').store;
store.setRootNode(store.snapshot2.copy(null, true));
alert(store.getNodeById('dummy1')); // alerts undefined
}
},{
xtype: 'button',
text: 'set dummy1 with diff copy',
handler: function() {
var store = Ext.getCmp('mytree').store;
store.getRootNode().removeAll();
store.snapshot2.eachChild(function(rec) {
store.getRootNode().appendChild(rec.copy(null, true));
});
alert(store.getNodeById('dummy1').data.id); // alerts dummy1
}
}]
});
Setting snapshot2 to the store's current root node
Ext.getCmp('mytree').store.snapshot2 = Ext.getCmp('mytree').store.getRootNode().copy(null, true);
So when you click the first button, you get the proper value ('child1') in the alert. However, when you click the second button ('set dummy1 as root'), you get undefined in the alert. The third button gives you the proper output ('dummy1'), and manually deep copies each child to the root.
To me, it seems like the copy function or the setRootNode function isn't doing something properly (leaning more toward the former). If I'm specifying a deep copy with copy(null, true), then the deep copy should be taking place, and everything should be fine... but I realize there's a problem with the copy function from the get go (see this thread). That's why I'm thinking it could be with the setRootNode, but that wouldn't make sense if setRootNode works for my created node but not for the deep copied original root node.
Can anyone offer any insight as to what I'm doing wrong? I'd appreciate any help. Thanks!
I think copy has a bug that still hasn't been resolved:
http://www.sencha.com/forum/showthread.php?134844-tree-node-copy%28deep%29-not-working-%284.0.1%29&highlight=tree%20copy
I'm not sure where your problem is in the above code, but I can offer a "better" way - this one works, at least, I think it also does what you're intending here:
Define two nodes - the snapshot and the root
var node = {
id: 'root',
text: 'root',
expanded: true,
children: [{
id: 'child1',
text: 'child1',
leaf: true
},{
id: 'child2',
text: 'child2',
leaf: true
}]
};
var rootNode = {
id: 'root',
text: 'root',
expanded: true,
children: [{
id: 'dummy1',
text: 'dummy1',
leaf: true
},{
id: 'dummy2',
text: 'dummy2',
leaf: true
}]
};
Then, define your store and functions (scrapping snapshot2)
var store = Ext.create('Ext.data.TreeStore', {
storeId: 'treestore',
proxy: {
type: 'memory',
reader: {
type: 'json'
}
},
snapshot: node,
root: rootNode
});
Ext.create('Ext.tree.Panel', {
store: store,
renderTo: Ext.getBody(),
height: 600,
width: 600,
id: 'mytree',
tbar: [{
xtype: 'button',
text: 'set child1 as root',
handler: function() {
var store = Ext.getCmp('mytree').store;
store.setRootNode(store.snapshot);
alert(store.getNodeById('child1').data.id); // alerts child1
}
},'->', {
xtype: 'button',
text: 'set dummy1 as root',
handler: function() {
var store = Ext.getCmp('mytree').store;
store.setRootNode(rootNode);
alert(store.getNodeById('dummy1').data.id); // now alerts dummy1
}
}]
I'm still new to Sencha Touch/ExtJS, and I'm currently exploring the demos and getting started samples. But I stumbled upon this problem where when I insert a nested list on tab panel items I can't navigate the list items anymore.
Here's my code:
Ext.setup({
tabletStartupScreen: 'tablet_startup.png',
phoneStartupScreen: 'phone_startup.png',
icon: 'icon.png',
glossOnIcon: false,
onReady: function(){
// store with data
var data = {
text: 'Groceries',
items: [{
text: 'Drinks',
items: [{
text: 'Water',
items: [{
text: 'Sparkling',
leaf: true
},{
text: 'Still',
leaf: true
}]
},{
text: 'Coffee',
leaf: true
},{
text: 'Espresso',
leaf: true
},{
text: 'Redbull',
leaf: true
},{
text: 'Coke',
leaf: true
},{
text: 'Diet Coke',
leaf: true
}]
},{
text: 'Fruit',
items: [{
text: 'Bananas',
leaf: true
},{
text: 'Lemon',
leaf: true
}]
},{
text: 'Snacks',
items: [{
text: 'Nuts',
leaf: true
},{
text: 'Pretzels',
leaf: true
},{
text: 'Wasabi Peas',
leaf: true
}]
},{
text: 'Empty Category',
items: []
}]
};
Ext.regModel('ListItem', {
fields: [{name: 'text', type: 'string'}]
});
var store = new Ext.data.TreeStore({
model: 'ListItem',
root: data,
proxy: {
type: 'ajax',
reader: {
type: 'tree',
root: 'items'
}
}
});
var nestedList = new Ext.NestedList({
fullscreen: true,
title: 'Groceries',
displayField: 'text',
dock: 'top',
store: store
});
var btnSpecTop = [
{ ui: 'back', text: 'Back'},
{ xtype: 'spacer' },
{ ui: 'default', text: 'Login' }
] // end btnSpecTop
var tapHandler = function (btn, evt) {
alert("Button '" + btn.text + "' tapped.");
}
var dockedItems = [{
xtype: 'toolbar',
dock: 'top',
title: 'Demo',
items: btnSpecTop,
defaults: { handler: tapHandler }
},
{
xtype: 'tabpanel',
layout: 'card',
dock: 'top',
fullscreen: true,
items:[{
title: 'test1',
html: '<p>test 1</p>'
},
{
title: 'test2',
html: '<p>test 2</p>',
dockedItems: nestedList
},
{
title: 'test3',
html: '<p>test 3</p>'
}]
}
]
var appPanel = new Ext.Panel({
id: 'appPanel',
fullscreen: true,
dockedItems: dockedItems
});
} // end onReady
});
Hope someone could lend a hand. Thanks!
This bug is only present on the pre-RC version of Sencha Touch. :)
I don't know which version sencha-touch you are using but in sencha-touch-1.1.0 the navigation is
working very well and there are no errors are thrown to the console,so try it again while observing your
console ,i think there has be a problem