Proper way to extend Ext.panel.Panel? - extjs

I am creating a GUI for a webpage using Ext JS 4.1.1. I have tried to create a component ('GeneSearchComponent' below) which I can use in a more complicated layouts. But for some reason I cannot insert an instance of 'GeneSearchComponent' into hpanel. What am I missing in extending the pre-defined 'Ext.panel.Panel' class (and in creating a "widget" of my own)?
If I remove the call to "Ext.create('gene-search-component', ...", everything works; if I put it back in, everything breaks. I wonder why.
(I have not included the definition of 'gene-combobox'. I am pretty convinced that it's not the root cause of my problem.)
Thanks for your time!
Tuomas
Ext.define('GeneSearchComponent', {
extend: 'Ext.panel.Panel',
alias: ['gene-search-component'],
constructor: function(cnfg) {
this.callParent(arguments);
this.initConfig(cnfg);
},
config: {
collapsible: true,
frame: true,
title: 'Search',
bodyPadding: '15 15 15 15',
width: 350,
layout: {
type: 'vbox',
align: 'left'
},
items: [
Ext.widget('gene-combobox', {
id: 'comboboxid'
}),
Ext.create('Ext.Button', {
text: 'Search',
handler: function() {
dosomething();
}})]
},
onRender: function() {
this.callParent(arguments);
}
});
Ext.application({
name: 'FW',
launch: function() {
var bd = Ext.getBody();
var div = Ext.get("search_form");
var hpanel = Ext.create('Ext.panel.Panel', {
id: 'horizontal-panel',
title: "HBoxLayout Panel",
layout: {
type: 'hbox',
align: 'middle'
},
items: [
Ext.create('Ext.container.Container', {
id: 'another-panel',
title: "VBoxLayout Panel",
width: 250,
layout: {
type: 'vbox',
align: 'left'
},
items: [{
xtype: 'panel',
width: 250,
title: ' Panel One',
flex: 2
},{
xtype: 'panel',
width: 250,
title: ' Panel Two',
flex: 1
},{
xtype: 'panel',
width: 250,
title: ' Panel Three',
flex: 1
}]}),
Ext.create('gene-search-component', {
id: 'searchPanel',
})],
renderTo: div,
});
}
});

The problem is that you have not given the gene-search-component the widget namespace when configuring its alias.
alias: 'widget.gene-search-component'
Also to echo the comments on your OP you are doing a lot of unnecessary typing creating components in the way that you are. You should make use of the xtype field rather than using Ext.Create everywhere. I've modified your code to show you how much simpler it could be.
http://jsfiddle.net/hzXx8/

Related

Method for renderTo EXTJS on mainView

I trying renderTo a panel(Ext.panel with title:'titlet' in the end of code) to the mainView ('Foresto.view.main.Main') or to a part of courusel (id:'mapId') But i havn't got a positive result.
So my quistions:
1) How to render panel to the mainview or to a courusel item ('mapId')
2)What mains approaches in Ext JS 6+, modern toolkit, for render object to the mainview or mainview's elements??
Now my code looks like that:
Ext.define('Foresto.view.main.Main', {
extend: 'Ext.form.Panel',
id:"control-panel",
plugins: 'responsive',
responsiveConfig:{
tall:{
tabPosition:'center'
}
},
xtype: 'app-main',
controller:'menuform',
requires: [
'Foresto.view.map.Map',
'Foresto.view.main.ButtonController',
'Foresto.view.forms.LoginRoom'
],
autosize:true,
padding: 0,
id:"bighBox",
header: {
cls: 'header-cls',
title : {
cls : 'header-title-cls',
text : 'FOREST'
}
},
tools: [{
type: 'menu',
handler: function() {
Ext.Viewport.toggleMenu('top');
}
}],
items:[{
xtype: 'carousel',
id: "mainPart",
flex: 1,
defaults: {
border: true,
ui: 'light'
},
items: [{
title: 'MAP',
id:'mapId',
xtype: 'panel',
layout:'vbox',
padding: 0,
items: [{
xtype: 'panel',
title:'PLACEFORMAP'
}]
},{
title: 'REPORTS',
xtype: 'panel',
cls: 'foresBack',
layout: {
type: 'hbox',
align: 'middle',
pack: 'center'
},
items:[{
xtype:'button',
cls:'threethbutton',
ui: 'confirm',
text:'REPORT1',
margin:'10px'
},{
xtype:'button',
cls:'threethbutton',
ui: 'confirm',
text:'REPORT2'
}]
}]
}
],
initialize: function() {
Ext.Viewport.add({
xtype:'button',
id:'pan11111',
text:'KAB',
flex:1,
height: 1000,
width: 100,
items:[{
xtype:'tabpanel',
title:'Projects',
layout:'card',
items:[{
xtype:'panel',
title:'11111'
},{
xtype:'panel',
title:'uuuuu'
}]
}]
});
}
}});
now I edit function for rendering panel on viewport. Panel 'pan11111' is rendering, bu viewport cover all other elements, and I can work only with panel and white board viewport, witch cover all classes: –THIS problem was solved by great clearning of coockies

face to white mark after folding the panel EXTJS

I have button on the first item of carousel on the Main View.
Button is managed by ButtonController and opens Form.
This form have tools: close, hide. When I click on close or hide tool on the forms after, for example closing I see white artifact. This looks like mark of header of Form..
enter image description here
Maybe this can be decided by trivial action?
Thanks
UPD: some code.
part of controller:
Ext.define('Foresto.view.main.ButtonController', {
extend: 'Ext.app.ViewController',
alias: 'controller.comenuform',
layout: 'vbox',
requires: [
'Foresto.view.forms.1',
'Foresto.view.forms.2',
'Foresto.view.forms.3',
'Foresto.view.forms.4'
],
views: ['Foresto.view.main.Main'],
cutForms: function () {
Ext.create('Ext.panel.Panel', {
layout: 'fit',
renderTo: 'mainPart',
autoshow: true,
items: [{
xtype: 'formsType4'
}]
})
},
part of form:
Ext.define('Foresto.view.forms.Formf', {
extend: 'Ext.form.Panel',
title: 'testApp',
header: {
cls: 'header-cls',
},
tools: [
{type: 'minimize',
handler: function(){
this.up("panel").hide();
}},
{type: 'save'},
{type:'close',
handler: function(){
this.up("panel").close();
}},
],
xtype: 'formsType4',
url: 'save-form.php',
defaults: {
xtype: 'selectfield',
labelWrap: true,
afterLabelTextTpl: [
'<span style="color:red;font-weight:normal" data-qtip="Required">*</span>'
]
},
items: [{...
and code of main:
Ext.define('Foresto.view.main.Main', {
extend: 'Ext.form.Panel',
id:'control-panel',
xtype: 'app-main',
controller:'comenuform',
requires: [
'Foresto.view.map.Map',
'Foresto.view.main.ButtonController',
],
padding: 0,
id:"bighBox",
header: {
cls: 'header-cls',
title : {
cls : 'header-title-cls',
text : 'MyApp'
}
},
tools: [{
type: 'menu',
handler: function(me) {
var cp = me.down('panel');
if (cp._hidden)
cp.show(true);
else
cp.hide(true);
}
}],
items:[{
xtype: 'carousel',
id: "mainPart",
flex: 1,
defaults: {
border: true,
ui: 'light'
},
items: [{
layout: {
type: 'vbox',
align: 'middle',
pack: 'center'
},
cls: 'colorful2',
defaults: {
border: true,
ui: 'light',
flex: 1
},
items:[{
xtype:'button',
cls: 'button-cls',
text: 'buttonOfForm4',
id: "RenterId",
margin: 10,
width: 920,
height: 250,
length: 150,
handler: 'renterForms'
... (some other buttons, which call forms too)..

How to render a hidden window?

I have an iframe (fit in a window) to load before showing it.
When I do :
window.show();
window.hide();
The window is not hidden. "window.show()" is used to render the iframe.
The loading of the iframe is about 10 sec.
How can I render the iframe without display the window?
My window :
var win = Ext.create('Ext.window.Window', {
height: '95%',
width: '95%',
modal: true,
header: false,
hideMode:'visibility',
constrain: true,
resizable:false,
itemId:'winIframeItemId....',
id:'winIframeId....',
baseCls: 'x-window-....',
layout: {
type: 'vbox',
align: 'stretch',
pack: 'start'
},
items: [{
xtype: 'container',
layout: {
type: 'hbox',
align: 'middle',
pack: 'end'
},
items: [{
xtype: 'button',
cls: 'x-button-close-window...',
height: 34,
width: 34
...
}]
}, {
xtype: 'container',
itemId:'conIframeWindow',
layout:"fit",
flex: 1,
items: [{
xtype: 'component',
autoScroll: true,
itemId:'IframeTest',
baseCls: 'x-component-w....',
autoEl: {
tag: "iframe",
domain: '....',
frameborder: 0,
src: url
}
}]
}]
});
Windows and menus are typically rendered to the document body. I was able to use the Ext.Component.renderTo configuration to render windows and menus without displaying them.
https://fiddle.sencha.com/#view/editor&fiddle/2f5h
// Render a hidden window.
var window = Ext.create('Ext.window.Window', {
renderTo: Ext.getBody(),
title: 'Window'
});
// Render a hidden menu.
var menu = Ext.create('Ext.button.Button', {
menu: {
items: [{
text: 'Item'
}],
renderTo: Ext.getBody()
},
text: 'Button'
});

How to refresh view panel in Sencha?

This seems elementary, but I need to be able to refresh a view after a Web Service call.
The data on the screen is not tied to a store because it is dynamically built at runtime.
Here is my view:
Ext.define('CAMSApp.view.OpBuyoffView', {
extend: 'Ext.Panel',
alias: ['widget.opbuyoffview'], //ToDo Use I18N
config: {
xtype: 'panel',
cls: 'dialogview formview',
centered: true,
scrollable: 'vertical',
modal: true,
screenId: 'opbuyoffview',
id: 'opBuyoffTableContainer',
layout: {
type: 'vbox',
align: 'center',
},
defaults: {
minHeight: 46
},
items: [
{
xtype: 'toolbar',
docked: 'top',
title: 'Buyoffs',
cls: 'grey-bold-34pt',
ui: 'transparent',
items: [{
xtype: 'button',
cls: 'grey-bold-40pt greyBtn',
text: 'Close',
idForAction: 'opbuyoff-cancel_btn',
}, {
xtype: 'spacer',
}],
},
{ id: 'opBuyoffToolbar',
xtype: 'container',
layout: {
type: 'hbox',
align: 'left',
},
items: [
{
xtype: 'button',
cls: 'blueRoundedBtn',
text: 'Buyoff',
idForUpdate: 'opbuyoff-buyoff_btn',
disabled: true
},
{ xtype: 'spacer',
minWidth: 480
}]
},
{
xtype: 'container',
layout: {
type: 'hbox',
align: 'stretch'
},
defaults: {
xtype: 'label',
style: 'border:1px solid black',
cls: 'opBuyoffTableHeader',
},
id: 'tabOfBuyoffs',
items: [{
html: '',
minWidth: 60
}, {
html: 'Buyoff',
minWidth: 250
}, {
html: 'Partial %',
minWidth: 100
}, {
html: 'Completed',
minWidth: 120
},
{
html: '',
cls: 'opBuyoffTransparent',
minWidth: 50
}
]
}],
listeners: {
initialize: function(me, eOpts) {
CAMSApp.util.I18N.resolveStaticUIBindings(me);
},
show: function (me, eOpts) {
// Publish the screen id event.
log('[OpBuyoff.show]');
CAMSApp.app.fireEvent('setscreenfocus', this);
},
},
}
});
I have tried reading the View and the Container - but neither elements have doLayout() or refresh() functions.
The containers and panels do have a method called update(Ext.AbstractComponent-method-update) which can be used to update a view's HTML content.
Also, you can use XTemplate for creating the items and bind the panel to a store. In that case you won't have to manually remove and add all the elements.
refresh: function() {
// Ext.StoreMgr.get('stream').load();
// here I'd like to reload the app instead
// not just the store
window.location.reload();
}

Aligning a text on an extjs label

I am new to extjs.I am designing a pop up window which basically populates some data from the server.I have used the layout as 'fit' and I am using labels for displaying the data.Here is my code
win = new Ext.window.Window({
title: 'Data point details',
layout: 'fit',
width: 'auto',
height: 500,
modal: false,
closeAction: 'destroy',
layout: {
type: 'table',
// The total column count must be specified here
columns: 2,
rows :10 ,
tdAttrs:
{
style:
{
margin: '160px',
valign: 'top' ,
padding: '8px' ,
'font-size' : '12px'
}
}
},
defaults: {
bodyPadding: 10 ,
},
items: [
{
xtype: 'label',
text: 'Element : ' ,
style:
{
'font-weight':'bold',
'labelAlign' : 'right',
}
},
{
xtype: 'label',
text: elementname
},
{
xtype: 'label',
text: 'Expression: ' ,
style:
{
'font-weight':'bold',
}
},
{
xtype: 'label',
text: s.expressionName
},
{
xtype: 'label',
text: 'Profile: ' ,
style:
{
'font-weight':'bold',
}
},
{
xtype: 'label',
text: s.profileName
},
{
xtype: 'label',
text: 'Time:',
style:
{
'font-weight':'bold',
}
},
{
xtype: 'label',
text: Highcharts.dateFormat('%a, %b %e, %Y, %I:%M %p ', this.x)
},
{
xtype: 'label',
text: 'Value:',
style:
{
'font-weight':'bold',
}
},
{
xtype: 'label',
text: yvalue ,
},
{
xtype: 'box',
style : {
padding: '0px',
height: '90px',
//background : 'white',
},
html: new Ext.XTemplate("<div style=\"height:150px;\">{value}")
.apply({value: me.htmldiv.innerHTML })
},
]
});
win.show();
I want the columns which appear on the left hand side to have their text on the right,but the text is always towards the left for all the cells it seems .Likw for example the label which has the text 'Element' appears to be on the left.I have used labelalign but it does not work.Kindly give suggestions
Just few suggestions until i get to the solution:
You have reduntant comas all over the place. Some older browsers will fail on such thing. Example:
{ 'font-weight':'bold',<<-- here }
win = new Ext.window.Window(... - this is global variable declaration - probably worst thing you can do in JavaScript and way to hell. Use var keyword to declare local variables like so: var win = new Ext.window.Window(...
labelAlign is the way to align label text to the right BUT a) you are applying it through style property (styles which Ext apply to HTML element created by component) and b) labelAlign is property of Labelable components and as strange as it might sound, Label itself is not Labelable. Just don't use Label like this, see below...
Duplicate layout property on Window
When you are asking for help and posting code as part of the question, edit your code so that it doesn't contain exteral dependencies - can be copied and run immediately. It took me nearly half a hour to make your sample working
As i said before, you are using Lable component in the way it is not suppose to be used. Labels are not created directly but by specifying label properties on components implementing Labelable mixin (Fields in most cases). It might sound complicated but is not, take a look at the code:
var wnd = new Ext.window.Window({
title: 'Data point details',
width: 400,
height: 200,
modal: false,
closeAction: 'destroy',
layout: {
type: 'anchor',
align: 'stretch'
},
bodyPadding: 10,
defaults: {
labelAlign: 'right',
labelStyle: {
'font-weight': 'bold'
},
labelWidth: 100
},
items: [{
xtype: 'displayfield',
fieldLabel: 'Element',
value: 'elementname'
}, {
xtype: 'displayfield',
fieldLabel: 'Expression',
value: 's.expressionName' // s.expressionName
}, {
xtype: 'displayfield',
fieldLabel: 'Profile',
value: 's.profileName' // s.profileName
}, {
xtype: 'displayfield',
fieldLabel: 'Time',
value: 'time'
}, {
xtype: 'displayfield',
fieldLabel: 'Value',
value: 'yvalue' // yvalue
}]
});
wnd.show();
You can try it and play with it here. My final suggestion would be to take a look at the official ExtJS documentation and guides which are pretty good - here for example are samples on making forms...
Here is an approach to use css styles inline, not in a separate class. This could be useful if you get css values from your javascript constants:
this.myLabel = Ext.create('Ext.form.Label', {
text: 'My Label Name',
style: {
'text-align': this.defaults.myLabelAlign, // The javascript constant.
'font-size': this.defaults.myLabelStyle // The javascript constant.
}
});

Resources