I have form panel as a menu item. The problem is that it constantly looses focus and standard navigation controls like tab are not working. Is there some kind of config to make this work? Notice i extend Ext.panel.Panel instead of Ext.form.Panel. When i use the second one i get origin.on is not a function. Here is code:
this.tbar = [{
xtype: 'tbfill'
}, {
xtype: 'tbseparator'
}, {
xtype: 'button',
text: 'Wyszukiwanie',
iconCls: 'icon-magnifier',
menu: {
focusOnToFront: true,
items: [{
xtype: 'decision_quicksearch',
title: 'Panel wyszukiwania',
iconCls: 'icon-magnifier',
}]
},
listeners: {
afterrender: function () {
//register this btn to quicksearch panel so we can hide menu when search button is clicked
Ext.apply(this.menu.items.items[0], {
parentComponent: this
});
}
}
}];
And the form:
Ext.define('GSIP.view.decisions.DecisionQuickSearchPanel' ,{
extend: 'Ext.form.Panel',
alias : 'widget.decision_quicksearch',
layout:'anchor',
title:'Wyszukiwanie decyzji',
frame:true,
width:300,
defaults: {
anchor: '100%'
},
style: {
marginLeft: 'auto',
marginRight: 'auto'
},
bodyPadding:20,
initComponent: function() {
this.addEvents('quicksearch');
this.items = this.createForm();
this.buttons = [{
text:'Szukaj',
iconCls:'icon-magnifier',
scope:this,
handler:this.processForm
}],
this.callParent(arguments);
},
createForm:function() {
var items = [{
xtype:'textfield',
fieldLabel:'Znak',
labelWidth:40,
name:'sign'
},{
xtype:'textfield',
fieldLabel:'Numer',
labelWidth:40,
name:'number'
},{
xtype:'textfield',
fieldLabel:'Rok',
labelWidth:40,
name:'suffix',
}];
return items;
},
processForm:function() {
var result = this.buildFilter();
this.fireEvent('quicksearch', result);
this.parentComponent.hideMenu();
},
buildFilter:function() {
var sign = this.down('textfield[name=sign]').getValue();
var number = this.down('textfield[name=number]').getValue();
var suffix = this.down('textfield[name=suffix]').getValue();
var result = new Array();
var res = {
name:'documents.sign',
valuesType:'string',
filterType:'like',
values:[{id:1, value:sign}]
};
result.push(res);
var res = {
name:'documents.number',
valuesType:'string',
filterType:'like',
values:[{id:1, value:number}]
};
result.push(res);
var res = {
name:'documents.suffix',
valuesType:'string',
filterType:'like',
values:[{id:1, value:suffix}]
};
result.push(res);
return result;
}
});
I have accomplished a similar functionality but in a different way.
What I did is simply made the button generate an Ext.Window with no header and limited border and positioned it under the button on open. You can then use MouseOut events to close the window and it will operate just like a menu or you could put the header on the bottom and place a close tool and have the window "pin".
buttonClick: function (btn, e, opts) {
var popUpWindow = Ext.create('Ext.window.Window', {
width: 450,
maxHeight: 400,
resizable: false,
closable: false,
title: 'Report Filters',
headerPosition: 'bottom',
border: false,
draggable: false,
bodyStyle: 'background:white;padding:5px;',
items: [
//...your form
]
});
popUpWindow.showAt(btn.getBox(false).x - 3, btn.getBox(false).y - 7);
}
Here is what i ended up with. It seems that this is exactly as if i was using menu but using method provided by ViaoV
var me = this;
this.popUpWindow = Ext.create('Ext.window.Window', {
resizable: false,
closable: false,
constrainHeader: true,
title: 'Panel wyszukiwania',
iconCls: 'icon-magnifier',
border: false,
draggable: false,
items: [{
xtype: 'decision_quicksearch',
listeners: {
afterrender:function(me) {
Ext.getDoc().on('mousedown', function(o) {
console.log('mousedown');
if (!o.within(me.getEl())) {
me.parentComponent.toggle(false);
}
})
// me.getEl().on('blur', function() {
// console.log('blur');
// me.parentComponent.toggle(false);
// });
}
},
}]
});
this.tbar = [{
xtype:'tbfill'
}, {
xtype:'tbseparator'
}, {
xtype:'button',
text:'Wyszukiwanie',
iconCls:'icon-magnifier',
enableToggle:true,
menu: { },
listeners:{
afterrender:function() {
//register this btn to quicksearch panel so we can hide menu when search button is clicked
Ext.apply(me.popUpWindow, {
parentComponent:this
});
},
toggle: function(btn, pressed) {
if (pressed) me.popUpWindow.showAt(btn.getBox(false).x - 3, btn.getBox(false).y + btn.getBox(false).height);
else me.popUpWindow.hide();
}
}
}];
EDIT: After some testing the solution i ended up with is not a good one. I have comboboxes in my panel which are defined by boundlist as another dom, so when i pick item from cbox !o.within(me.getEl()) evaluates to true and hides my panel. I really need the functionality when the user clicks elsewhere the window hides.
Related
I'm new using Ext JS and I need to add a button in my Viewport.
I have tried adding it as an item but it doesn't work when I click on it:
items: [ {
xtype: 'datepicker',
width: 211
},
{
xtype: 'datepicker',
width: 211
},
{
xtype: 'button',
text: 'Search',
width: 211
},
],
So then, in the official documentation I have found another way to add it:
Ext.create('Ext.Button', {
text : 'Button',
renderTo : Ext.getBody(),
listeners: {
click: function() {
// this == the button, as we are in the local scope
this.setText('I was clicked!');
},
mouseover: function() {
// set a new config which says we moused over, if not already set
if (!this.mousedOver) {
this.mousedOver = true;
alert('You moused over a button!\n\nI wont do this again.');
}
}
}
});
But I want it in the west region I defined in my Viewport and I have no idea about how to achieve this since I'm completely new at Ext JS.
My code:
function init() {
Ext.application({
name: 'MyApp',
launch: function() {
Ext.create('Ext.data.Store', {
storeId:'prices',
fields:['name', 'priceNight', 'totalPrice', 'Check-in', 'Check-out'],
data:{'items':[
]},
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'items'
}
}
});
Ext.create('Ext.container.Viewport', {
layout: 'border',
items: [{
title: 'West',
region: 'west',
margins: '0 5 0 5',
flex: .3,
collapsible: true,
split: true,
titleCollapse: true,
items: [
{
xtype: 'datepicker',
width: 211
},
{
xtype: 'datepicker',
width: 211
},
{
//I want the button here.
},
],
}, {
title: 'Center',
region: 'center',
collapsible: false,
items: {
// I want to add it just there
xtype: 'grid',
store: Ext.data.StoreManager.lookup('prices'),
columns: [
],
}
}]
});
}
});
}
I would like the button here:
Any ideas?
Thank you in advance!
I have just figured out how to do it! I'm going to post here what I did so maybe it will result helpful for some people:
It's just simple as invocating it using a variable.
Button code:
var button = Ext.create('Ext.Button', {
text : 'Button',
renderTo : Ext.getBody(),
listeners: {
click: function() {
// this == the button, as we are in the local scope
this.setText('I was clicked!');
},
mouseover: function() {
// set a new config which says we moused over, if not already set
if (!this.mousedOver) {
this.mousedOver = true;
alert('You moused over a button!\n\nI wont do this again.');
}
}
}
});
In your viewport you just have to add it as an item:
...
items: [
{
items: button //button is the variable that we defined when we created the button
}
]
...
Final result:
I hope this will help someone who is having the same question as me :)
I'm keep facing with a issue to choice exact component with scope. As you'll notice below I've created 2 different functions inside gridpanel. One of those creates a Ext.MessageBox for confirm. And other function creates a Ext.window.Window depends on button click of MessageBox.
The thing here is; It should destroy related component with cancel and no buttons. Both buttons always point to gridpanel because of var me = this state and destroys the gridpanel itself.
How can I point destroy method directly to related component?
Ext.define('MyApp.FooGrid', {
extend: 'Ext.grid.Panel',
reference: 'fooGrid',
getGridMenu: function () {
// Here is the 'Update' function; with right-click user being able to see `contextmenu`
var me = this;
var ret = [
{
text: 'Update',
listeners: {
click: me.onUpdate,
scope: me
}
}
];
return me.callParent().concat(ret);
},
onUpdate: function () {
var me = this,
gridRec = this.getSelectionModel().getSelection(); // Here being able to retrieve row data.
Ext.MessageBox.confirm(translations.confirm, translations.confirmChange, me.change, me);
return gridRec;
},
change: function (button) {
var me = this;
var selectedRec = me.onUpdate();
var selectedRecEmail = selectedRec[0].data.email; //Retrieves selected record's email with right-click action
if (button === "yes") {
return new Ext.window.Window({
alias: 'updateWin',
autoShow: true,
title: translations.update,
modal: true,
width: 350,
height: 200,
items: [
{
xtype: 'container',
height: 10
},
{
xtype: 'textfield',
width: 300,
readOnly: true,
value: selectedRecEmail //Display selected record email
},
{
xtype: 'textfield',
width: 300,
fieldLabel: translations.newPassword
}
],
dockedItems: [
{
xtype: 'toolbar',
dock: 'bottom',
items: [
{
xtype: 'tbfill'
},
{
xtype: 'button',
text: translations.cancel,
listeners: {
click: function () {
me.destroy(); // Here is the bug: When user clicks on this button; should destroy current window but it destroys 'gridpanel' itself
}
}
},
{
xtype: 'button',
text: translations.save,
listeners: {
click: function () {
console.log("I'll save you!");
}
}
}
]
}
]
});
} else {
console.log('this is no!');
me.destroy(); // Another bug raises through here: If user will click on No then 'messagebox' should destroy. This one is destroys the gridpanel as well.
}
}
});
How can I point destroy method directly to related component?
Firstly on confirmation box button's(No) click, you don't need to destroy it will automatically hide the box whenever you click into No.
And for update window instead of using me.destroy() you need to use directly button.up('window').destroy() so it will only destroy your update window not the grid.
And also you don't need to again call me.onUpdate() inside of change function otherwise it will again show the confirmation box. You can directly get selected record on the change function like this me.getSelection().
In this Fiddle, I have created a demo using your code and I have put my efforts to get result.
CODE SNIPPET
Ext.application({
name: 'Fiddle',
launch: function () {
Ext.create('Ext.data.Store', {
storeId: 'demostore',
fields: ['name', 'email', 'phone'],
data: [{
name: 'Lisa',
email: 'lisa#simpsons.com',
phone: '555-111-1224'
}, {
name: 'Bart',
email: 'bart#simpsons.com',
phone: '555-222-1234'
}, {
name: 'Homer',
email: 'homer#simpsons.com',
phone: '555-222-1244'
}, {
name: 'Marge',
email: 'marge#simpsons.com',
phone: '555-222-1254'
}]
});
Ext.create('Ext.grid.Panel', {
title: 'Demo GRID',
store: 'demostore',
columns: [{
text: 'Name',
dataIndex: 'name'
}, {
text: 'Email',
dataIndex: 'email',
flex: 1
}, {
text: 'Phone',
dataIndex: 'phone'
}],
height: 200,
listeners: {
itemcontextmenu: function (grid, record, item, index, e, eOpts) {
e.stopEvent();
grid.up('grid').getGridMenu().showAt(e.getXY());
}
},
renderTo: Ext.getBody(),
getGridMenu: function () {
var me = this;
if (!me.contextMenu) {
me.contextMenu = Ext.create('Ext.menu.Menu', {
width: 200,
items: [{
text: 'Update',
handler: me.onUpdate,
scope: me
}]
});
}
return me.contextMenu;
},
onUpdate: function () {
var me = this;
Ext.MessageBox.confirm('Confirmation ', 'Are your sure ?', me.change, me);
},
change: function (button) {
var me = this,
selectedRecEmail = me.getSelection()[0].data.email; //Retrieves selected record's email with right-click action
if (button === "yes") {
return new Ext.window.Window({
autoShow: true,
title: 'Update',
modal: true,
width: 350,
height: 200,
items: [{
xtype: 'tbspacer',
height: 10
}, {
xtype: 'textfield',
width: 300,
readOnly: true,
value: selectedRecEmail //Display selected record email
}, {
xtype: 'textfield',
inputType:'password',
width: 300,
fieldLabel: 'New Password'
}],
dockedItems: [{
xtype: 'toolbar',
dock: 'bottom',
items: [{
xtype: 'tbfill'
}, {
xtype: 'button',
text: 'cancel',
listeners: {
click: function (btn) {
btn.up('window').destroy(); // Here is the bug: When user clicks on this button; should destroy current window but it destroys 'gridpanel' itself
}
}
}, {
xtype: 'button',
text: 'save',
listeners: {
click: function () {
console.log("I'll save you!");
}
}
}]
}]
});
}
}
});
}
});
In ExtJS, on a menu toolbar button, I am trying to remove the current panel in my center window, then recreate it with the new selection. I do not understand the proper way to do this. So far when I click the menu item, it removes whatever is currently there successfully, then it will add the new panel successfully. The problem is the 2nd time I hit the button I get the following error:
REGISTERING DUPLICATE COMPONENT ID 'mainportalID'.
I realize its telling me I already used this ID, but then what would be the correct way to remove the current panel, and replace with a new one?
Here is my view controller:
selectMenuButton: function (button, e) {
console.log('select menu button section was hit')
console.log(button);
console.log(e);
var optionString = button.text;
var myDetailsPanel = Ext.getCmp('navview');
console.log(myDetailsPanel);
var count = myDetailsPanel.items.items.length;
if (count > 0) {
myDetailsPanel.items.each(function (item, index, len) {
myDetailsPanel.remove(item, false);
});
}
myDetailsPanel.add({
xtype: optionString
});
}
var myStore = Ext.create('ExtApplication1.store.PositionsStore');
var gridSummary = Ext.create('Ext.grid.Panel', {
store: myStore,
width: 600,
title: 'my first grid',
columns: [
{
text: 'AcctNum',
dataIndex: 'AcctNum',
width: 100
},
{
text: 'AcctShortCode',
dataIndex: 'AcctShortCode',
flex: 1
},
{
text: 'Exchange',
dataIndex: 'Exchange',
width: 200
}
]
});
This is my view
Ext.define('ExtApplication1.view.main.MainPortal', {
extend: 'Ext.panel.Panel',
xtype: 'mainportal',
alias: 'widget.mainportal',
id: 'mainportalID',
html: 'user... this is the main portal window',
autoScroll: true,
bodyPadding: 10,
items: [
gridSummary
]
});
adjusted panel
Ext.define('ExtApplication1.view.main.MainPortal', {
extend: 'Ext.panel.Panel',
xtype: 'mainportal',
alias: 'widget.mainportalAlias',
reference: 'gridtextfield',
//id: 'mainportalID',
html: 'user... this is the main portal window',
autoScroll: true,
bodyPadding: 10,
items: [
gridSummary
]
});
adjusted view controller
onComboboxSelect: function (combo, record, eOpts) {
console.log('new listener was hit');
//return selected Item
var selectedValue = record.get('ClientName');
var selectedCID = record.get('ClientID');
//find the grid that was created
var me = this;
console.log(me);
var xxx = this.lookupReference('gridtextfield');
debugger;
//debugger;
var mainPortalView = Ext.getCmp('mainportalID');
var targetGrid = mainPortalView.down('grid');
//find the store associated with that grid
var targetStore = targetGrid.getStore();
//load store
targetStore.load({
params: {
user: 'stephen',
pw: 'forero',
cid: selectedCID
}
//callback: function (records) {
// Ext.each(records, function (record) {
// console.log(record);
// });
// console.log(targetStore);
//}
});
},
added listeners to MainPortal.js
var myStore = Ext.create('ExtApplication1.store.PositionsStore');
var gridSummary = Ext.create('Ext.grid.Panel', {
store: myStore,
width: 600,
title: 'my first grid',
columns: [
{
text: 'AcctNum',
dataIndex: 'AcctNum',
width: 100
},
{
text: 'AcctShortCode',
dataIndex: 'AcctShortCode',
flex: 1
},
{
text: 'Exchange',
dataIndex: 'Exchange',
width: 200
}
],
listeners: {
destroy: function () {
debugger;
}
}
});
Ext.define('ExtApplication1.view.main.MainPortal', {
extend: 'Ext.panel.Panel',
xtype: 'mainportal',
alias: 'widget.mainportalAlias',
//id: 'mainportalID',
itemId: 'mainportalID',
html: 'user... this is the main portal window',
autoScroll: true,
bodyPadding: 10,
items: [
gridSummary
],
listeners: {
destroy: function () {
debugger;
}
}
});
I've defined DragZone as:
var menuItems = panel.query('.menuitem');
Ext.each(menuItems, function (component) {
component.DragZone = Ext.create('Ext.dd.DragZone', component.getEl(), {
getDragData: function (e) {
var compEl = component.getEl(),
cloneEl;
cloneEl = compEl.dom.cloneNode(true);
cloneEl.id = Ext.id();
return {
ddel: cloneEl,
repairXY: Ext.fly(e.getTarget()).getXY(),
componentClone: component.cloneConfig()
};
},
getRepairXY: function () {
return this.dragData.repairXY;
},
ddGroup: 'auGroup'
});
});
Where menus are menuitems from panel:
xtype: 'panel',
title: 'Geometry Controls',
items: [
{
xtype: 'menu',
floating: false,
itemId: 'geometryControlsMenu',
defaults: {
height: 20
},
items: [
{
xtype: 'menuitem',
itemId: 'angles',
text: 'Angles',
iconCls: 'icon-apgo'
},
{
xtype: 'menuitem',
itemId: 'coordinatePlane',
text: 'Coordinate Plane',
iconCls: 'icon-apgo'
}
Dragging is working but I have problems with displaying dragging items, it look like it has been croped:
But if I'll change dragsource from menuitem to menu itself:
var menuItems = panel.query('.menu');
displaying works ok:
How could I fix this?
component.DragZone.resizeFrame= true;
I have created 3 panels,2 buttons(Prev,next) in Extjs and added to viewport.
At a time only one panel should visible (by default first panel).
On click of next button it should display next panel,then if i click on "prev" button it should display the previous panel.
Now i have wrote a code for panels and its working as ,panels are not navigating to left and right properly.
Here is my code :
Ext.application({
name: 'HelloExt',
requires: [
'Ext.util.Point'
],
launch: function() {
var button =Ext.create('Ext.Button', {
text: 'Toggle Containers',
handler: function () {
if (this.clickCount==1) {
containerPanel1.getEl().scrollRight;
containerPanel2.getEl().slideIn('t', 'toggle');
this.clickCount=2;
} else {
this.clickCount = 1;
containerPanel1.getEl().slideIn('t', 'toggle');
containerPanel2.getEl().scrollLeft;
}
},
renderTo: Ext.getBody()
});
var containerPanel1 = Ext.create('Ext.panel.Panel', {
renderTo: Ext.getBody(),
draggable: {
insertProxy: false,
startDrag: function(e) {
var el = Ext.get(this.getEl());
el.dd = new Ext.dd.DDProxy(el.dom.id, 'group');
this.x = el.getLeft(true);
this.y = el.getTop(true);
},
afterDrag: function(e) {
this.x = el.getLeft(true);
this.y = el.getTop(true);
this.fireEvent('itemdrag', this);
}
},
width:400,
height:550,
layout: 'column',
bodyStyle:{'background-color':'blue'},
margin:'30 0 0 20',
suspendLayout: true ,
defaults :{
xtype: 'panel',
margin:'30 0 0 0',
height: 450,
columnWidth: 0.2
},
items: [
{
html: 'Child Panel 1',
},
{
html: 'Child Panel 2',
},
{
html: 'Child Panel 3',
},
{
html: 'Child Panel 4',
},
{
html: 'Child Panel 5',
}
]
});
containerPanel1.draggable;
var containerPanel2 = Ext.create('Ext.panel.Panel', {
renderTo: Ext.getBody(),
draggable: {
insertProxy: false,
startDrag: function(e) {
var el = Ext.get(this.getEl());
el.dd = new Ext.dd.DDProxy(el.dom.id, 'group');
this.x = el.getLeft(true);
this.y = el.getTop(true);
},
afterDrag: function(e) {
this.x = el.getLeft(true);
this.y = el.getTop(true);
this.fireEvent('itemdrag', this);
}
},
width:400,
height:550,
layout: 'column',
bodyStyle:{'background-color':'green'},
margin:'30 0 0 20',
suspendLayout: true ,
defaults :{
xtype: 'panel',
margin:'30 0 0 0',
height: 300,
columnWidth: 0.2
},
items: [
{
html: 'Child Panel 1',
},
{
html: 'Child Panel 2',
},
{
html: 'Child Panel 3',
},
{
html: 'Child Panel 4',
},
{
html: 'Child Panel 5',
}
]
});
containerPanel2.draggable;
containerPanel2.getEl().hide();
Ext.create('Ext.container.Viewport', {
layout: 'column',
items: [containerPanel1,containerPanel2,button]
});
}
});
Please help me..Thanks
I was just building a similar project, so here's an example snippet you could use. Notice that you can change the amount and order of panels and the code will still work. The click handler simply looks for the visible panel first, and then depending on the direction attempts to either go forward or backward.
Ext.define('MyApp.view.MyViewport1', {
extend: 'Ext.container.Viewport',
id: 'switchPanels',
initComponent: function() {
var me = this;
Ext.applyIf(me, {
items: [
{
xtype: 'panel',
height: 100,
html: 'this is panel 1',
title: 'My Panel A'
},
{
xtype: 'panel',
height: 100,
hidden: true,
html: 'this is panel 2',
title: 'My Panel B'
},
{
xtype: 'panel',
height: 100,
hidden: true,
html: 'this is panel 3',
title: 'My Panel C'
},
{
xtype: 'container',
switchPanel: function(forward) {
var p = Ext.ComponentQuery.query('panel(true){isVisible()}')[0]; // visible panel
var n = forward ? p.nextSibling('panel(true)') : p.previousSibling('panel(true)'); // closest sibling
if (n) { // don't let go past the last one
p.hide();
n.show();
}
else {
console.log("can't go past the " + (forward ? 'end' : 'beginning'));
}
},
id: 'buttons',
items: [
{
xtype: 'button',
handler: function(button, event) {
button.up().switchPanel(false);
},
text: 'Prev'
},
{
xtype: 'button',
handler: function(button, event) {
button.up().switchPanel(true);
},
text: 'Next'
}
]
}
]
});
me.callParent(arguments);
}
});
You need to use card(Wizard) layout for this. please refer simple sample example below.
Im sure this will help you to resolve your problem.
var active = 0;
var main = Ext.create('Ext.panel.Panel', {
renderTo: Ext.getBody(),
width: 200,
height: 200,
layout: 'card',
tbar: [{
text: 'Next',
handler: function(){
var layout = main.getLayout();
++active;
layout.setActiveItem(active);
active = main.items.indexOf(layout.getActiveItem());
}
}],
items: [{
title: 'P1'
}, {
title: 'P2'
}, {
title: 'P3',
listeners: {
beforeactivate: function(){
return false;
}
}
}]
});
Please refer card(wizard) layout in the below link.
http://docs.sencha.com/extjs/4.2.0/#!/example/layout-browser/layout-browser.html
Thanks