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
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 have a grid which has a column of checkboxes. I have used xtype checkcolumn
for this. follow fiddle here: https://fiddle.sencha.com/#view/editor&fiddle/2ano
Now I want to uncheck checkbox at perticular(in this case 2nd) row on click of given button. I tried getting them using xtypes but no luck.
finally I found a workaround.
store.getAt(1).data.active = false;
grid.getView().refresh();
It works but not sure if its the correct way to do so.
I will be glad for any suggestions.
Thank you.
One way as per your code.
You can use this methods of grid store store.each(), store.clearFilter() and store.filter('active',true).
In this FIDDLE, you can check here uncheck checked columns using record.set('active',false).
var store = Ext.create('Ext.data.Store', {
fields: ['name', 'email', 'phone', 'active'],
data: [{
name: 'Lisa',
email: 'lisa#simpsons.com',
phone: '555-111-1224',
active: false
}, {
name: 'Bart',
email: 'bart#simpsons.com',
phone: '555-222-1234',
active: true
}, {
name: 'Homer',
email: 'homer#simpsons.com',
phone: '555-222-1244',
active: false
}, {
name: 'Marge',
email: 'marge#simpsons.com',
phone: '555-222-1254',
active: false
}]
});
Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
itemId: 'test',
renderTo: Ext.getBody(),
store: store,
buttons: [{
text: 'Un check',
handler: function () {
var store = this.up('grid').getStore();
store.clearFilter();
store.filter('active', true);
store.each(function (rec) {
rec.set('active', false);
});
store.clearFilter();
}
}],
columns: [{
text: 'Name',
dataIndex: 'name'
}, {
text: 'Email',
dataIndex: 'email',
flex: 1
}, {
text: 'Phone',
dataIndex: 'phone'
}, {
xtype: 'checkcolumn',
text: 'Active',
dataIndex: 'active'
}]
});
Another way as per your code.
You can use selModel and selType configs for grid.
In this FIDDLE, I have created a demo using selType and selModel config. it will help you or guide you more about grid checkbox selection.
Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
store: store,
id: 'testGrid',
columns: [{
text: 'Name',
dataIndex: 'name'
}, {
text: 'Email',
dataIndex: 'email',
flex: 1
}, {
text: 'Phone',
dataIndex: 'phone'
}],
renderTo: Ext.getBody(),
selModel: {
checkOnly: false,
//injectCheckbox: 'last',
mode: 'SIMPLE'
},
selType: 'checkboxmodel',
buttons: [{
text: 'Select All',
handler: function () {
Ext.getCmp('testGrid').getSelectionModel().selectAll();
}
}, {
text: 'Deselect All',
handler: function () {
Ext.getCmp('testGrid').getSelectionModel().deselectAll();
}
}]
});
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()
});
});
I have an extjs2 formpanel:
var fsf = new Ext.FormPanel({
labelWidth: 75, // label settings here cascade unless overridden
frame:true,
id: 'formPanel',
title: 'Simple Form with FieldSets',
bodyStyle:'padding:5px 5px 0',
width: 550,
items: [{
xtype:'fieldset',
checkboxToggle:true,
title: 'User Information',
autoHeight:true,
defaults: {width: 210},
defaultType: 'textfield',
collapsed: true,
items :[{
fieldLabel: 'First Name',
name: 'first',
allowBlank:false
},{
fieldLabel: 'Last Name',
name: 'last'
},{
fieldLabel: 'Company',
name: 'company'
}, {
fieldLabel: 'Email',
name: 'email',
vtype:'email'
}
]
},{
xtype:'fieldset',
title: 'Phone Number',
collapsible: true,
autoHeight:true,
defaults: {width: 210},
defaultType: 'textfield',
items :[{
fieldLabel: 'Home',
name: 'home',
value: '(888) 555-1212'
},{
fieldLabel: 'Business',
name: 'business'
},{
fieldLabel: 'Mobile',
name: 'mobile'
},{
fieldLabel: 'Fax',
name: 'fax'
}
]
}],
buttons: [{
text: 'Save',
handler: function(){
var form = Ext.getCmp('formPanel').getForm();
if(form.isValid())
form.submit({
waitMsg:'Loading...',
url: 'RepeatSession.jsp',
success: function(form,action) {
//we have to close the window here!!
},
failure: function(form,action){
Ext.MessageBox.alert('Erro',action.result.data.msg);
}
});
}
},{
text: 'Cancel'
}]
});
and a window:
win = new Ext.Window(
{
layout: 'fit',
width: 500,
height: 300,
modal: true,
closeAction: 'hide',
items: fsf
});
win.show();
As you can see, the form panel is inside the window as an item. I have to close the window after a successful form submission but I have no idea how to access the window object inside my success handler.
How can i hide the window after successful form submission?
Just save a reference to the window or one of its children before creating the form. For example you can use the button paremeter that the handler function gets passed:
handler: function(button, e){
[...]
success: function(form,action) {
button.up('.window').close();
},
Or, as you apparently already have the window in a variable (win), you can just use that to close the window:
win.close();
but that depends on the variable win being available inside the success function, which we cannot assume from the code you gave.
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