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
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,
});
}
});
help me understand the tree filtering.
I have input ow
xtype: 'triggerfield',
listeners: {
change: function() {
console.log()
}
}
How can I filter the tree? I need to send a request to the server with a value from the field
You can use filterBy method to do simple or complex filtering on TreeStore:
var store = Ext.create('Ext.data.TreeStore', {
autoload: true,
root: {
expanded: true,
specialProp: 1,
children: [{
text: "detention",
leaf: true,
specialProp: 1
}, {
text: "homework",
expanded: true,
children: [{
text: "book report",
leaf: true,
specialProp: 1
}, {
text: "algebra",
leaf: true,
specialProp: 2
}]
}, {
text: "buy lottery tickets",
leaf: true,
specialProp: 1
}]
}
});
Ext.create('Ext.container.Viewport', {
layout: 'fit',
items: [{
xtype: 'container',
items: [{
xtype: 'treepanel',
id: 'treePanelId',
store: store,
dockedItems: [{
xtype: 'toolbar',
items: [{
xtype: 'button',
text: 'specialProp=1 Filter',
handler: function () {
var treePanel = Ext.getCmp('treePanelId');
treePanel.getStore().filterBy(function (item) {
if (item.get('root') === true) return true;
else if (item.get('specialProp') === 1) return true;
else return false;
});
}
}, {
xtype: 'button',
text: 'Clear filter',
handler: function () {
var treePanel = Ext.getCmp('treePanelId');
treePanel.getStore().clearFilter();
}
}]
}]
}]
}]
});
Example Fiddle: https://fiddle.sencha.com/#view/editor&fiddle/29si
EDIT:
For remote filtering you can do it like following:
var store = Ext.create('Ext.data.TreeStore', {
remoteFilter: true,
proxy: {
type: 'ajax',
url: 'data.json',
reader: {
type: 'json'
}
},
root: {
expanded: true
}
});
Ext.create('Ext.container.Viewport', {
layout: 'fit',
items: [{
xtype: 'container',
items: [{
xtype: 'treepanel',
id: 'treePanelId',
store: store,
dockedItems: [{
xtype: 'toolbar',
items: [{
xtype: 'button',
text: 'specialProp=1 Filter',
handler: function () {
var treePanel = Ext.getCmp('treePanelId');
treePanel.getStore().filter('specialProp', 1);
}
}, {
xtype: 'button',
text: 'Clear filter',
handler: function () {
var treePanel = Ext.getCmp('treePanelId');
treePanel.getStore().clearFilter();
}
}]
}]
}]
}]
});
Remote Sort Fiddle Example: https://fiddle.sencha.com/#view/editor&fiddle/29sq
Take a look at response of request, you can filter on server side with this. Also for ease of understanding I have put params in response to show how filters would be actually appear on http request which need to be processed.
Note: Make sure you send data response in following format:
{ status: 'success', children: [{...}, {...}, ....] }
If you are sending response in other format you will need to process it in store proxy.
ExtJS6: Second instance of TreeStore has no grandchildren.
I have a class, MyStore, which inherits from TreeStore.
Then, I created an instance of MyStore to be displayed in a treepanel.
So far so good.
Then, I created another instance of MyStore to be displayed in another treepanel.
Here comes the problem: the second treepanel does not have grandchild. All it has are it's root node and it's root node's children.
How do I code this so that the 2nd (and succeeding) instance of TreeStore will have grandchildren?
https://fiddle.sencha.com/#fiddle/1ehq
Ext.define('MyStore',{
extend: 'Ext.data.TreeStore',
root: {
expanded: true,
text: 'This is the root node',
children: [
{
text: 'Food',
expanded: true,
children: [
{
text: 'Cake',
leaf: true
},
{
text: 'Ice cream',
leaf: true
}
]
},
{
text: 'Toys',
expanded: true,
children: [
{
text: 'Ball',
leaf: true
},
{
text: 'Bat',
leaf: true
}
]
}
]
}
});
Ext.widget('treepanel',{
title: 'first tree panel',
renderTo: Ext.getBody(),
store: new MyStore()
});
Ext.widget('treepanel',{
title: 'second tree panel',
renderTo: Ext.getBody(),
store: new MyStore()
});
Ext.widget('panel', {
html: 'What happend to the "Food" and "Toys" of the second tree panel? Why did they loose their children?',
renderTo: Ext.getBody(),
});
Use this Fiddle:https://fiddle.sencha.com/#fiddle/1hti
Ext.define('MyStore',{
extend: 'Ext.data.TreeStore'
});
var store1 = Ext.create('MyStore',{
extend: 'Ext.data.TreeStore',
root: {
expanded: true,
text: 'This is the root node',
children: [
{
text: 'Food',
expanded: true,
children: [
{
text: 'Cake',
leaf: true
},
{
text: 'Ice cream',
leaf: true
}
]
},
{
text: 'Toys',
expanded: true,
children: [
{
text: 'Ball',
leaf: true
},
{
text: 'Bat',
leaf: true
}
]
}
]
}
});
var store2 = Ext.create('MyStore',{
extend: 'Ext.data.TreeStore',
root: {
expanded: true,
text: 'This is the root node',
children: [
{
text: 'Food',
expanded: true,
children: [
{
text: 'Cake',
leaf: true
},
{
text: 'Ice cream',
leaf: true
}
]
},
{
text: 'Toys',
expanded: true,
children: [
{
text: 'Ball',
leaf: true
},
{
text: 'Bat',
leaf: true
}
]
}
]
}
});
Ext.widget('treepanel',{
title: 'first tree panel',
renderTo: Ext.getBody(),
store: store1
});
Ext.widget('treepanel',{
title: 'second tree panel',
renderTo: Ext.getBody(),
store: store2
});
Ext.widget('panel', {
html: 'What happend to the "Food" and "Toys" of the second tree panel? Why did they loose their children?',
renderTo: Ext.getBody(),
});
I have a tree panel, and I am trying to add a bellow the selected item.
http://jsfiddle.net/zer8oLo7/
If you click on "Add To Root", it is working.
But. if you click on "Add To Selected", it doesn't work:
Ext.application({
name: 'Fiddle',
launch: function () {
var store = Ext.create('Ext.data.TreeStore', {
root: {
expanded: true,
children: [{
text: "detention",
leaf: true
}, {
text: "homework",
expanded: true,
children: [{
text: "book report",
leaf: true
}, {
text: "algebra",
leaf: true
}]
}, {
text: "buy lottery tickets",
leaf: true
}]
}
});
Ext.create('Ext.tree.Panel', {
//title: 'Simple Tree',
itemId: 'projectTree',
viewConfig: {
plugins: {
ptype: 'treeviewdragdrop'
}
},
id: 'projectTree',
width: 200,
height: 500,
store: store,
renderTo: Ext.getBody(),
dockedItems: [{
xtype: 'toolbar',
dock: 'top',
items: [{
text: 'Add To Selected',
handler: function () {
var treeNode = Ext.getCmp('projectTree').getSelectionModel().getSelection()
treeNode.appendChild({
text: 'Child 4',
leaf: false
});
}
}, {
text: 'Add to root',
handler: function () {
var treeNode = Ext.getCmp('projectTree').getRootNode();
treeNode.appendChild({
text: 'Child 4',
leaf: false
});
}
}]
}],
});
}
});
getSelection() somehow returns an array of nodes, so you need to take only first node:
...
treeNode[0].appendChild({
text: 'Child 4',
leaf: false
});
...
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()
});
});