Showing a Tab without explicity clicking on tab icon - extjs

I am currently working on an application im using Sencha Touch 1.
I have 2 items in my TabPanel. Search and Alarm.
The Search tab on clicking gives a list of 4 .
When the user clicks on the 4th item in the list he should automatically be directed to Alarm Tab without manually clicking on the tab.
Is there any function that I could use to do so .
Im a beginner at Sencha touch.Suggestions are welcome .
This is my app.js
ToolbarDemo=new Ext.Application({
name:'ToolbarDemo',
launch:function(){
ToolbarDemo.views.Viewport=new Ext.TabPanel({
fullscreen:true,
defaults:
{
html:'',
styleHtmlContent:true,
} ,
tabBar:
{
dock:'bottom',
layout:{
pack:'center'
}
},
items:[
/*
{
xtype:'homecard'
},
*/
{
xtype:'searchcard'
},
/*
{
xtype:'actioncard'
},
*/ {
xtype:'settingscard'
},
{
xtype:'morecard'
},
] ,
});
}
});
And searchcard has following code (searchcard.js)
Ext.regModel('Contact',{
fields:['firstName','lastName']
});
//create a store
var liststore = new Ext.data.Store({
model:'Contact',
getGroupString:function(record){
return record.get('firstName')[0];
},
data:[
{firstName:'Network Summary'},
{firstName: 'Alarms and Alerts'},
]
});
detailpanel=new Ext.Panel({
layout:'fit',
id:'detailpanel',
html:'HELLO ',
});
listpanel =new Ext.List({
id:'indexlist',
store:liststore, //take data from store created above
itemTpl:'{firstName}',
indexBar:true , //property of list
onItemDisclosure:function(record)
{
mainpanel.setActiveItem('detailpanel');
}
});
mainpanel=new Ext.Panel({
id:'mainpanel',
layout:'card',
items:[
listpanel,detailpanel
],
});
ToolbarDemo.views.Searchcard= Ext.extend(Ext.Panel,{
title:'Search',
iconCls:'search',
badgeText:'1',
layout:'fit',
//items:[listpanel],
initComponent: function() {
Ext.apply(this, {
items:[mainpanel],
});
ToolbarDemo.views.Searchcard.superclass.initComponent.apply(this, arguments);
}
}) ;
Ext.reg('searchcard',ToolbarDemo.views.Searchcard);
And my alarms tab has the following code (morecard.js)
Ext.regModel('Contact',{
fields:['firstName','lastName']
});
var liststore = new Ext.data.Store({
model:'Contact',
getGroupString:function(record){
return record.get('firstName')[0];
},
data:[
{firstName:'Critical Alarms'},
{firstName: 'Major alarms'},
{firstName: 'Minor alarms'},
{firstName: 'Alerts'},
]
});
detailpanel=new Ext.Panel({
id:'detailpanel',
tpl:'HELLO ',
});
listpanel_my =new Ext.List({
id:'indexlist',
store:liststore, //take data from store created above
itemTpl:'{firstName}',
indexBar:true , //property of list
onItemDisclosure:function(record)
{
// ToolbarDemo.views.Viewport.setActiveItem('detailpanel');
}
});
ToolbarDemo.views.Morecard = Ext.extend(Ext.Panel, {
title: "Alarms",
iconCls: "more",
cardSwitchAnimation: 'slide',
initComponent: function() {
Ext.apply(this, {
items:[listpanel_my] ,
});
ToolbarDemo.views.Morecard.superclass.initComponent.apply(this, arguments);
}
});
Ext.reg('morecard', ToolbarDemo.views.Morecard);
i spefically want when i click list item named Alarms and Alerts in Search Tab (searchard.js) after that I automatically want my Alarms tab to be active and show its items (Major Alarms, minor Alarms etc)

Your TabPanel has a method called setActiveItem(item) where item is a number.
Also refer to the Sencha Touch Docs regarding this method. Container is the superclass of TabPanel.

Related

How to solve this error "Uncaught TypeError: Cannot call method 'getForm' of undefined "

I tried to add edit button functionality in grid panel. I want to open an edit window on edit button click for updating grid row record using Ext Window Form which contains fields like (Shift Name, Time, Total, Requirement, Note). The window form is created, but the row values that I have selected in grid are not set in form fields.
I tried to use this code:
Ext.getCmp('shiftWindow').getForm().setValues(selection[0].data);
but it's giving the following error
Uncaught TypeError: Cannot call method 'getForm' of undefined
Here is my code:
var shiftWindow = Ext.create('Ext.window.Window', {
title: 'Edit Shift',
resizable: false,
id: 'shiftwindow',
width: 465, //bodyPadding: 5, modal: true, store: shiftStorePlanner,
items: {
xtype: 'form',
id: 'idFormShift',
bodyPadding: 10,
items: shiftViewModelPlannerData
},
buttons: [{
text: 'Save',
cls: 'planner-save-button',
overCls: 'planner-save-button-over',
handler: function () {
var wi = this.up('.window')
var form = Ext.getCmp('idFormShift');
if (form.isValid()) {
shiftTimemappingarray = [];
getShiftTime();
//this.up('.window').close();
}
}
}, {
text: 'Cancel',
handler: function () {
this.up('.window').close();
}
}]
});
var host1 = Ext.getCmp('plannershifteditor');
var selection = host1._shiftPlannerGrid.getSelectionModel().getSelection();
if (selection.length === 0) {
return;
}
selection[0].data.ShiftName = selection[0].data.ShiftName.replace('(ARCHIVED)', '').trim(); //if edit Archive record then text name show without (ARCHIVED)
//shiftWindow.getForm().setValues(selection[0].data);
Ext.getCmp('shiftWindow').getForm().setValues(selection[0].data);
//Ext.getCmp('shiftWindow').setValue(selection[0].data);
shiftWindow.show();
There's no getForm method in the window. You can get the form using shiftWindow.down('form'). Here's the snippet:
shiftWindow.down('form').form.setValues(selection[0].data)

Dynamically Add contextmenu to Ext.tree.TreePanel

I am trying to add dynamically created contextmenu's to an Ext.tree.TreePanel object. The menus will all be different depending on user selections.
I can create the menu outside the treePanel descriptor but how can I append the dynamically created menu to the Ext.tree.TreePanel? The documentation seems to indicate that treePanel.on(nameOfMenuHere) would append the menu but it returns as undefined.
var menu1 = new Ext.menu.Menu({
id: 'menu1',
items: [{
id: 'menu1-item1',
text: 'Menu 1 - Item 1'
},
{
id: 'menu1-item2',
text: 'Menu 1 - Item 2'
}],
listeners: {
itemclick: function (item) {
switch (item.id) {
case 'menu1-item1':
var n = item.parentMenu.contextNode;
if (n.parentNode) {
alert(n.parentNode.text);
alert("node ID: " + n.id + ", node text: " + n.text); //Ext ID and text of selected node
}
break;
}
}
}
});
userLayerTree.on(menu1);
use the listener itemcontextmenu within the tree panel. something like this should work.
var tpanel = {
xtype : 'treepanel',
width: 250,
.........
..........
listeners : {
itemcontextmenu: showLyrContextMenu
}
}
and then create the function to create and show your menu
function showLyrContextMenu(view, record, item, index, event){
lyrTreeContextMenu = new Ext.menu.Menu({
id : 'lyrcontxtmenu',
.......
items: items
});
lyrTreeContextMenu.showAt(event.getXY());
event.stopEvent();
}

Need solution for Multi Select in Extjs tree

Am complete stranger to Extjs. I have a requirement to allow multi select in the Extjs tree. Below piece of code is doing single select. i need to change the code to make it multi select with semi-colon between selected ids. Can anyone please change the code as per the requirement. Also if you could tell me to which field or variable the selected value of the tree is written into. Thanks in advance
Ext.onReady(function() {
Ext.QuickTips.init();
var str='';
var switch_flag = '';
var approvals = '';
var active_mode = '';
var json = null;
Ext.Ajax.request({
url: 'Dmscategorytree/ajax/Message',
method: 'POST',
params:{
lifecycle_id: str,
switch_flag: switch_flag,
approvals: approvals,
active_mode: active_mode
},
success: function(response, options) {
var path='';
var id='';
var text='';
json=response.responseText;
alert(json);
json = json.replace(/"/g,'\"');
json=Ext.util.JSON.decode(json);
var flag=true;
var myloader = new Ext.tree.TreeLoader();
myloader.load = function(node, cb,scope) {
if(this.clearOnLoad){
while(node.firstChild){
node.removeChild(node.firstChild);
}
}
if(this.doPreload(node)){
this.runCallback(cb, scope || node, [node]);
}
cb();
}
var tree = new Ext.tree.TreePanel({
animate:true,
autoScroll:true,
//loader: new Tree.TreeLoader({dataUrl:'get-nodes.php'}),
containerScroll: true,
border: false,
loader:myloader,
rootVisible: false,
listeners:{
checkchange:function(node){
if(flag){
toggleCheck(tree.root,false,node.id);
path=node.attributes.value;
id=node.attributes.ID;
text=node.attributes.text;
path=path.replace(/\^/g,'/');
}
}
}
});
function SelectToParent()
{
try
{
parent.window.opener.callParent(path,id);
parent.window.opener.focus();
parent.window.close();
}
catch(e){
alert('got exception');
window.close();
}
}
function toggleCheck(node,isCheck,nodeId)
{
flag=false;
if(node)
{
var args=[isCheck];
node.cascade(function(){
c=args[0];
if(nodeId!=this.id){
this.ui.toggleCheck(c);
this.attributes.checked=c;
}
},null,args);
}
flag=true;
return true;
}
var root = new Ext.tree.AsyncTreeNode({
text: 'Ext JS',
draggable:false, // disable root node dragging
id:'src',
children: json
});
tree.setRootNode(root);
var topbar = new Ext.Toolbar({
region : 'north',
height:30,
margins: '0 0 0 5',
items:[
{
xtype: 'box',
id: 'title',
autoEl: {
html: '#label.chooseCat#'
}
,width:525
},
{
text: '#label.Done#',
id: 'doneBtn',
tooltip: 'Done',
handler: SelectToParent
}
]
});
topbar.render('tree');
tree.render('tree');
tree.getRootNode().expand();
}
});
});
Please refer the following links,
pass two id s in extjs 4 tree multiSelect and pass one id in single click
Multiselect Tree & Drag and Drop
Drag and Drop between Grid and “multiselect” control in EXTJS
Demo

Drag and Drop from Grid to Tree and backwards

Since a few days now I try to change an ExtJs ['Grid to Tree Drag and Drop' Example][1] to work in both directions. But all I get is an 'almost' working application.
Now it works as far as I can drag an item from grid to tree, within tree, within grid but if i drag it from tree to grid, it doesn't drop. It just shows the green hook.
I also tried to differ the ddGroup from tree and grid, but then nothing works anymore.
This is too much for an ExtJs beginner.
// Stücklisten Grid
stuecklistengrid = Ext.extend(Ext.grid.GridPanel, {
initComponent:function() {
var config = {
store:itemPartStore
,columns:[{
id:'PART_ITE_ID'
,header:"PART_ITE_ID"
,width:200, sortable:true
,dataIndex:'PART_ITE_ID'
},{
header:"IS_EDITABLE"
,width:100
,sortable:true
,dataIndex:'IS_EDITABLE'
},{
header:"IS_VISIBLE"
,width:100
,sortable:true
,dataIndex:'IS_VISIBLE'
}]
,viewConfig:{forceFit:true}
}; // eo config object
// apply config
Ext.apply(this, Ext.apply(this.initialConfig, config));
this.bbar = new Ext.PagingToolbar({
store:this.store
,displayInfo:true
,pageSize:10
});
// call parent
stuecklistengrid.superclass.initComponent.apply(this, arguments);
} // eo function initComponent
,onRender:function() {
// call parent
stuecklistengrid.superclass.onRender.apply(this, arguments);
// load the store
this.store.load({params:{start:0, limit:10}});
} // eo function onRender
});
Ext.reg('examplegrid', stuecklistengrid);
// Stücklisten Tree
var CheckTree = new Ext.tree.TreePanel({
root:{ text:'root', id:'root', expanded:true, children:[{
text:'Folder 1'
,qtip:'Rows dropped here will be appended to the folder'
,children:[{
text:'Subleaf 1'
,qtip:'Subleaf 1 Quick Tip'
,leaf:true
}]
},{
text:'Folder 2'
,qtip:'Rows dropped here will be appended to the folder'
,children:[{
text:'Subleaf 2'
,qtip:'Subleaf 2 Quick Tip'
,leaf:true
}]
},{
text:'Leaf 1'
,qtip:'Leaf 1 Quick Tip'
,leaf:true
}]},
loader:new Ext.tree.TreeLoader({preloadChildren:true}),
enableDD:true,
ddGroup:'grid2tree',
id:'tree',
region:'east',
title:'Tree',
layout:'fit',
width:300,
split:true,
collapsible:true,
autoScroll:true,
listeners:{
// create nodes based on data from grid
beforenodedrop:{fn:function(e) {
// e.data.selections is the array of selected records
if(Ext.isArray(e.data.selections)) {
// reset cancel flag
e.cancel = false;
// setup dropNode (it can be array of nodes)
e.dropNode = [];
var r;
for(var i = 0; i < e.data.selections.length; i++) {
// get record from selectons
r = e.data.selections[i];
// create node from record data
e.dropNode.push(this.loader.createNode({
text:r.get('PART_ITE_ID')
,leaf:true
,IS_EDITABLE:r.get('IS_EDITABLE')
,IS_VISIBLE:r.get('IS_VISIBLE')
}));
}
// we want Ext to complete the drop, thus return true
return true;
}
// if we get here the drop is automatically cancelled by Ext
}}
}
});
// Stücklisten Container
var itemPartList = new Ext.Container({
id: 'itemPartList',
title: 'Stücklisten',
border:false,
layout:'border',
items:[CheckTree, {
xtype:'examplegrid'
,id:'SLgrid'
,title:'Grid'
,region:'center'
,layout:'fit'
,enableDragDrop:true
,ddGroup:'grid2tree'
,listeners: {
afterrender: {
fn: function() {
// This will make sure we only drop to the view scroller element
SLGridDropTargetEl2 = Ext.getCmp('SLgrid').getView().scroller.dom;
SLGridDropTarget2 = new Ext.dd.DropTarget(SLGridDropTargetEl2, {
ddGroup : 'grid2tree',
notifyDrop : function(ddSource, e, data){
var records = ddSource.dragData.selections;
Ext.each(records, ddSource.grid.store.remove,
ddSource.grid.store);
Ext.getCmp('SLgrid').store.add(records);
return true
}
});
}
}
}
}]
});
You need to implement the onNodeDrop event of the grid. See http://docs.sencha.com/ext-js/4-1/#!/api/Ext.grid.header.DropZone-method-onNodeDrop

Getting strange error this.grid is undefined ext-all-debug.js (line 47393)

I have an editor grid
Grid.Selection = Ext.extend(Ext.grid.EditorGridPanel, {
layout:'fit',
border:false,
stateful:false,
initComponent: function() {
Ext.apply(this, {
// {{{
store: new Ext.data.SimpleStore({
id: 0,
fields: [ ...],
data: []
})
,cm: new Ext.grid.ColumnModel({
// specify any defaults for each column
defaults: {
sortable: true // columns are not sortable by default
},
columns: [
rowNumberer,
combo1,
combo2,
combo3,
itemDeleter]
})
// }}}
,plugins: new Ext.ux.plugins.GridValidator()
,viewConfig: {forceFit: true}
,sm: itemDeleter
,height: 150
,frame: true
,clicksToEdit: 1
,tbar: [{
text: 'Add New Association'
,id: 'addBtnGrid'
,iconCls: 'icon-plus'
,listeners: {
click: {scope: this,fn: this.addRecord,buffer: 200}
}
}]
}); // eo apply
// call parent
Grid.Selection.superclass.initComponent.apply(this, arguments);
} // eo function initComponent
// }}}
// {{{
,onRender: function() {
// call parent
Grid.Selection.superclass.onRender.apply(this, arguments);
} // eo function onRender
// }}}
// {{{
,addRecord: function() {
record = this.store.recordType;
rec = new record({
...
});
this.stopEditing();
this.store.insert(0, rec);
**this.getView().refresh(); // GETTING ERROR ON THIS LINE**
this.getSelectionModel().selectRow(0);
this.startEditing(0, 0);
} // eo function addRecord
,reset: function() {
this.store.removeAll();
this.addRecord();
}
}); // eo extend
// register xtype
Ext.reg('selectionGrid', Grid.Selection);
I add this grid to a form.
When I display the form I reset the grid which removes all records from the store and add a single new record.
But when this.getView().refresh(); is called I get
this.grid is undefined
this.grid.stopEditing(true); ext-all-debug.js (line 47393)
The item deleter plugin [http://code.google.com/p/extensive/s...eleter.js?r=13] is also calling
grid.getView().refresh() but it works.
I will be highly grateful if somebody can guide me.
The problem was due to the fact that the grid was not completely rendered before I was calling getView().refresh().
The solution was to call the above method after the grid was rendered.

Resources