Aligning a text on an extjs label - extjs

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.
}
});

Related

How to get grid (any container) reference in Sencha cmd application?

I have a simple grid with two(add and remove) buttons as docked item in sencha cmd application. I want to delete the selected row.
I have grid defined in my view as
xtype:'app-main',
viewModel: {
type: 'main'
},
layout: 'absolute',
autoScroll : true,
resizable:true,
items: [
{
xtype: 'gridpanel',
x: 10,
y: 10,
autoScroll : true,
renderTo: document.body,
//height: 300,
width: 300,
title: 'Grid Panel',
store: 'peopleStore',
columns: [
{
xtype: 'gridcolumn',
dataIndex: 'id',
text: 'Id'
},
{
xtype: 'gridcolumn',
dataIndex: 'title',
text: 'Title'
},
{
xtype: 'gridcolumn',
dataIndex: 'body',
text: 'Body'
}
],
dockedItems: [{
xtype: 'toolbar',
items:[
{
xtype: 'button',
x: 330,
y: 10,
scale: 'medium',
text: 'Add New Record',
handler: function() {
var UserStore = Ext.getStore('peopleStore');
UserStore.add({title: 'asd', body:'asdasd'});
UserStore.sync();
UserStore.load();
}
},
{
xtype: 'button',
scale: 'medium',
text: 'Reset Records',
handler: function() {
//delete code will go here
}
}]
}]}]
With this stackoverflow question extjs how to get a grid
I know code will be some thing like
grid.getView().getSelectionModel().getSelection()[0];
if (selection) {
UserStore.remove(selection);
}
But can someone tell me how to get reference to "grid" ?
Grabs the first parent (relative to the button) that is a grid:
xtype: 'button',
...
handler: function(button) {
var grid = button.up('gridpanel');
console.log("my grid", grid);
}
Grabs the first parent (relative to the button) that is a grid and has itemId "myGrid" (to prevent ambiguity):
xtype: 'gridpanel',
itemId: 'myGrid',
...
xtype: 'button',
...
handler: function(button) {
var grid = button.up('gridpanel #myGrid');
console.log("myGrid", grid);
}
I would heavily suggest looking up selectors in ExtJS (for ExtJS <= 5) and references in ViewControllers (for ExtJS 5). There are pros/cons to both so I would recommend reading about both of them (though both do very similar things). My solution uses selectors.
Here are some resources:
http://docs.sencha.com/extjs/5.0/application_architecture/view_controllers.html
http://training.figleaf.com/tutorials/senchacomplete/chapter2/lesson5/2.cfm
http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.dom.Query (complete selector syntax list)

Flex Property - Restart the row

I have a fieldcontainer which has several components. Each components has flex property as well. What I want to know that how can we break the row? As you can see the screen shot, 'FREE ARTICLE' field should start beginning of the new row but I don't know how can I specify this.
items: new Ext.Panel({
items: [
{
xtype: 'fieldset',
title: 'Artikel Sorgulama',
defaultType: 'textfield',
layout: 'anchor',
defaults: {
anchor: '100%'
},
height: '86px',
items: [
{
xtype: 'fieldcontainer',
layout: 'hbox',
defaultType: 'textfield',
fieldDefaults: {
labelAlign: 'top'
},
items: [
{
xtype: 'textfield',
id: 'articleNo',
flex: 1,
tabIndex: 1,
fieldLabel: 'ARTİKEL NO',
fieldStyle: 'text-align: right; font-size: 12pt',
margins: '0 10 0 0',
enableKeyEvents: true,
listeners: {
specialkey: function (field, e) {
if (field.getValue() != 'null') {
if (e.getKey() === e.ENTER || e.TAB) {
//articles.proxy.extraParams = {'article': field.getValue()};
articles.load({
params: {'article': field.getValue()},
callback: function () {
Ext.getCmp('articleDesc').setValue(articles.data.items[0].data['ART_DESC']);
}
});
}
}
},
focus: function (e) {
e.setValue('');
Ext.getCmp('articleDesc').setValue("");
articles.loadData([], false);
}
}
},
{
xtype: 'textfield',
id: 'articleDesc',
flex: 3,
fieldLabel: 'ARTİKEL TANIMI',
fieldStyle: 'font-size: 12pt',
readOnly: true
},
{
xtype: 'textfield',
fieldLabel: 'FREE ARTICLE',
flex: 0
}
]
}
]
},
You would need to use nested box layouts. The field container have a vbox layout. The first item in the fieldcontainer should be a container with an hbox layout (like your current code). The second item of the fieldcontainer should be the 3rd field (which will appear underneath due to the vbox layout).
Just don't add your free article field to the field container, but to the parent fieldset instead:
items: [
{
xtype: 'fieldset',
// ...
items: [
{
xtype: 'fieldcontainer',
layout: 'hbox',
// ...
}, {
xtype: 'textfield',
fieldLabel: 'FREE ARTICLE'
}
]
}
]

Reduce the height of a titlebar - Sencha

I have a container with a few different items stacked in. I also would like to have two title bars inside the container BUT with height reduced to 10 points. I have tried to reduce the size using setHeight() with a lesser number but I can't seem to achieve that. Am I missing something obvious?
Is there a way I can reduce the height of a toolbar/titlebar in Sencha Touch? Help!
UPDATE: Here is the code I use for a toolbar...
Ext.define('MyApp.view.CookingSteps', {
extend: 'Ext.Container',
alias: 'widget.CookingSteps',
config: {
height: '',
html: '',
id: 'CookingSteps',
itemId: 'CookingSteps',
style: '',
layout: {
type: 'vbox'
},
items: [
{
xtype: 'toolbar',
docked: 'top',
height: 50,
html: '<b><center>AdBanner Goes Here',
style: 'background: gray;',
styleHtmlContent: true
},
{
xtype: 'container'
},
{
xtype: 'fieldset',
title: '',
items: [
{
xtype: 'textfield',
label: '',
placeHolder: 'Username'
},
{
xtype: 'textfield',
label: '',
placeHolder: 'Passphrase'
}
]
},
{
xtype: 'toolbar',
docked: 'top',
height: 20,
minHeight: '20',
title: 'Login'
},
{
xtype: 'container',
items: [
{
xtype: 'button',
centered: true,
ui: 'confirm',
width: 283,
text: 'Go Ahead :)'
}
]
}
]
}
});
I want the toolbar with title 'Login' with a reduce height.. Any help would be greatly appreciated. Thank you in advance. :)
If you need to adjust toolbar size use minHeight option with units in toolbar config. Here is a toolbar example with a 2x of current font size height.
{
xtype: 'toolbar',
docked: 'top',
minHeight: '2em',
}

Scrollable panel in sencha touch

i had made a panel with number of buttons in it like this,
Ext.define('BeLocal.view.Test', {
extend: 'Ext.Panel',
config: {
fullScreen: true,
height: 482,
width: 324,
scrollable: 'vertical',
items: [
{
xtype: 'button',
text: 'MyButton1'
},
{
xtype: 'button',
top: '30%',
text: 'MyButton2'
},
{
xtype: 'button',
top: '50%',
text: 'MyButton3'
},
{
xtype: 'button',
top: '96%',
text: 'MyButton4'
},
{
xtype: 'button',
top: '110%',
text: 'MyButton5'
}
]
}
});
i can show only 3 buttons now.
i want this panel scrollable so that i can show all the buttons by scrolling it down, i had set property scrollable: 'vertical' , but it doesn't work.
When i remove position of all buttons like top:50% scroll works properly, but i want all the buttons on proper position.
how can i fix this problem ?
As per the documentation:
http://docs.sencha.com/touch/2-1/#!/api/Ext.Button-cfg-top
top : Number/String
The absolute top position of this Component; must be a valid CSS length value, e.g: 300, 100px, 30%, etc. Explicitly setting this value will make this Component become 'floating', which means its layout will no longer be affected by the Container that it resides in.
Try setting style config:
items: [{
xtype: 'button',
text: 'MyButton1'
},{
xtype: 'button',
style:'margin-top: 10%;',
text: 'MyButton2'
},{
xtype: 'button',
style:'margin-top: 50%;',
text: 'MyButton3'
},{
xtype: 'button',
style:'margin-top: 96%;',
text: 'MyButton4'
},{
xtype: 'button',
style:'margin-top: 110%;',
text: 'MyButton5'
}]
Seems to works for me.

Proper way to extend Ext.panel.Panel?

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/

Resources