How can I Increase space between fields in EXTJS - extjs

I have a window where I have items as in below image.I want give gap between fileds
code:
new Ext.Window({
title : bundle.getMsg('add.camera'),
id:'win-add-camera',
closable:true,
autoHeight:true,
modal:true,
defaults : {
labelWidth: 60,
labelAlign: 'left',
margin: '0 0 20 0'
},
items: [{
xtype:'form',
layoutConfig: {
trackLabels: true
},
id: 'form-camera',
autoHeight:true,
autoScroll:true,
items:[
{
layout:'column',
items:[
{
columnWidth: .50,
bodyPadding:30,
margin: '0 0 20 0',
layout: 'form',
defaults:{anchor:'80%'},
items: [ {
id:'cam-name-id',
fieldLabel : bundle.getMsg('camera.name'),
name : 'cameraName',
margin: '0 0 20 0',
xtype:'textfield',
width:450,
emptyText : bundle.getMsg('enter.camName'),
maxLength:10,
enforceMaxLength:true
,required:true,
},
{
id:'url-id',
fieldLabel : bundle.getMsg('url'),
name : 'cameraWebUrl',
xtype:'textfield',
width:450,
margin: '0 0 20 0',
emptyText : bundle.getMsg('enter.url')
,
maxLength:10,enforceMaxLength:true,required:true,
},
{
id:'place-id',
fieldLabel : bundle.getMsg('place.name'),
maxLength:35,
name : 'cameraPlaceName',
xtype:'textfield',
width:450,
emptyText : bundle.getMsg('enter.place'),required:true
},
{
id:'latitude-id',
fieldLabel :bundle.getMsg('lattitude'),
name : 'cameraLatitude',xtype:'textfield',
width:450,emptyText :bundle.getMsg('enter.lattitude'), growMax: 500,required:true
},
{
id:'longitude-id',
fieldLabel : bundle.getMsg('longitude'),
name : 'cameraLongitude',xtype:'textfield',
width:450,emptyText : bundle.getMsg('enter.long'),required:true
},
{
xtype:'combo',
id: 'camera-combo-id',
name:'cameraStatus',
store : new Ext.data.ArrayStore({
data:[["Enable","1"],["Disable","2"]],
fields : ['cameraStatus','no']
}),
fieldLabel : bundle.getMsg('camera.status'),
displayField :'cameraStatus',
emptyText : bundle.getMsg('advice.select'),
valueField : 'no',
selectOnFocus:true,
allowBlank: false,
autoSelect:false,
mode:'local',
listeners:{
'select': function(){
camera_status_combo_value=Ext.getCmp('camera-combo-id').getValue();
camera_status_combo_value_name = Ext.getCmp('camera-combo-id').getRawValue();
alert(camera_status_combo_value)
alert(camera_status_combo_value_name)
},
'afterrender':function(){
this.getStore().load();
}
}
},
{
xtype : 'combo',
id: 'police-station-name-id',
name:'policeStationName',
width:450,
store : police_station_store,
fieldLabel : bundle.getMsg('policestation'),required:true,
displayField :'policeStationName',
emptyText : bundle.getMsg('selectpolicestation'),
valueField : 'gid',
triggerAction:"all",
selectOnFocus:true,
forceSelection: true,
queryMode : 'local',
listeners:{
'select': function(){
police_stn_id=Ext.getCmp('police-station-name-id').getValue();
police_station_combo=Ext.getCmp('police-station-name-id').getValue();
},
'afterrender':function(){
this.getStore().load();
}
}
},

I got the solution
I have written below line in between fields
{
xtype: 'tbspacer',
height:10
},
and also we can add instead of above code
{
height:10
}
both will work !
Before Adding this code:
after adding the code:

You need to set margin for the fields.
Check this fiddle - https://fiddle.sencha.com/#fiddle/md1
The fiddle is in 5.1 but the config is available in 4.x as well.

Use layout:'hbox' for every row.
But, looks like you should use type: 'label' instead of setting label right in the textfield component.
Here is a fiddle for you: https://fiddle.sencha.com/#fiddle/md3
My layout:
layout: {
type: 'vbox',
align: 'stretch'
},
width: 400,
defaults: {
layout: 'hbox',
margin: 10
},
items: [{
items: [{
xtype: 'label',
text: 'Market',
forId: 'test-1',
flex: 1
}, {
xtype: 'combo',
inputId: 'test-1',
allowBlank: false,
store: store,
queryMode: 'local',
displayField: 'MarketName',
forceSelection: true,
valueField: 'Id',
flex: 3
}]
}, {
items: [{
xtype: 'label',
text: 'Name',
forId: 'test-2',
flex: 1
}, {
xtype: 'textfield',
inputId: 'test-2',
flex: 3
}]
}],

Related

extjs how to pass parameters from container to a nested container

I have two js files, the maincomp and the nestedcomp. nestedcomp would be used as a reusable component and that is why I need to send parameters to it. This maincomp file:
Ext.define('mycomponents.maincomp', {
extend: 'Ext.window.Window',
itemId: 'maincomp',
xtype: 'maincomp',
modal: true,
bodyPadding: 10,
height: 350,
width: 270,
closeAction: 'destroy',
resizable: false,
renderTo: Ext.getBody(),
requires: [
'mycomponents.nestedcomponent'
],
layout: {
type: 'table',
columns: 1
},
items: [
{
xtype: 'textfield',
fieldLabel: 'Name',
name: 'name',
labelAlign : 'right',
width: 265,
allowBlank: false
},
{
xtype: 'textfield',
fieldLabel: 'Age',
name: 'age',
labelAlign : 'right',
width: 265,
allowBlank: false
}
{
xtype: 'nestedcomp'
}
]
});
and this is my nestedcomp file:
Ext.define('mycomponents.nestedcomponent', {
extend: 'Ext.container.Container',
id: 'nestedcomp',
xtype: 'nestedcomp',
items: [
{
xtype: 'textfield',
fieldLabel: 'Address',
name: 'address',
id: 'address',
labelAlign : 'right',
width: 265,
allowBlank: false
}
],
constructor: function (config) {
this.callParent(arguments);
this.initConfig(config);
return this;
},
initComponent: function () {
}
});
Maybe this is very naive question but the thing is I have no idea on how to pass parameters from maincomp to nestedcomp. I went into the official documentation, and google for an answer, but I was unable to find a solution in order to achieve this, so my question is how to pass parameters from one component into its nested components?
I mostly pass extra parameters to nested component in initComponent:
Ext.define('mycomponents.maincomp', {
extend: 'Ext.window.Window',
itemId: 'maincomp',
xtype: 'maincomp',
modal: true,
bodyPadding: 10,
height: 350,
width: 270,
closeAction: 'destroy',
resizable: false,
renderTo: Ext.getBody(),
requires: [
'mycomponents.nestedcomponent'
],
layout: {
type: 'table',
columns: 1
},
initComponent: function () {
this.items = [
{
xtype: 'textfield',
fieldLabel: 'Name',
name: 'name',
labelAlign : 'right',
width: 265,
allowBlank: false
},
{
xtype: 'textfield',
fieldLabel: 'Age',
name: 'age',
labelAlign : 'right',
width: 265,
allowBlank: false
},
{
xtype: 'nestedcomp',
abc: this.xyz
}
];
this.callParent(arguments);
}
});
Or i just do something method on this view in ViewController like form.loadRecord(r), form.setValues(v) where form is the Ext.form.Panel after view is rendered.

"Ext.getCmp(...) is undefined" in different function

I have Extjs code in view, this is it:
createPanelMC: function() {
this.requiredSign = '<span style="color:red;font-weight:bold" data-qtip="Required">*</span>';
var panel = Ext.create('Ext.form.Panel', {
defaultType: 'textfield',
name: 'nodebPanel',
width: '100%',
layout: {
type: 'auto',
align: 'stretch'
},
items: [{
xtype : 'fieldset',
name : 'modlayanan',
title : 'Data Pelanggan',
layout : 'column',
width : '95%',
margin : '10',
items: [{
xtype : 'textfield',
name : 'nomor',
id : 'nomor',
fieldLabel : 'PSTN',
emptyText : 'Nomor...',
margin : '10 0 0 0',
width : 350,
labelWidth : 100,
afterLabelTextTpl: this.requiredSign
}, {
xtype : 'textfield',
fieldLabel : 'Speedy',
name : 'speedy',
id : 'speedy',
margin : '10 0 10 20',
width : 350,
labelWidth : 100
},
this.createTreePaketExist()
]
}],
dockedItems: [ {
xtype: 'toolbar',
name: 'tbpaketmc',
dock: 'bottom',
items: [ {
text: '<< Back',
action: 'doBack'
},'->', {
text: 'Submit',
action: 'doSubmit'
}
]
}
]
});
return panel;
},
i call nomor dan speedy in this.createTreePaketExist() . This is the this.createTreePaketExist() code:
createTreePaketExist: function() {
var nopstn= Ext.getCmp('nomor').getValue();
var speedy= Ext.getCmp('speedy').getValue();
var storeTree = Ext.create('Ext.data.TreeStore', {
proxy: {
type: 'ajax',
method: 'POST',
url: 'data/newoss_get_paket.php',
params: {
nopstn:nopstn
,speedy:speedy
}
}
});
var groupProduct = Ext.create('Ext.tree.Panel', {
store : storeTree,
name : 'treeProduct',
rootVisible : false,
useArrows : true,
layout :'fit',
margin : '0 0 0 0',
autoScroll : true,
height : 150,
width : '93%',
listeners:
{
checkchange: function(node, checked, eOpts){
node.eachChild(function(n) {
node.cascadeBy(function(n){
n.set('checked', checked);
});
});
p = node.parentNode;
var pChildCheckedCount = 0;
p.suspendEvents();
p.eachChild(function(c) {
if (c.get('checked')) pChildCheckedCount++;
p.set('checked', !!pChildCheckedCount);
});
p.resumeEvents();
}
}
});
return groupProduct;
},
but it gave an error: Ext.getCmp(...) is undefined. Help me, thanks.
Ext.getCmp() is not recommended to use in ExtJS code. Instead you should use
Ext.ComponentQuery.query('#nomor')
Where nomor is id of element.
But To resolve your problem try to call this:
Ext.ComponentQuery.query('textfield[name="nomor"]')
or
Ext.getCmp('#nomor')
if this will not help you then the problem in your code structure. May be piece of code that represents getCmp('nomor') is loaded and invoked before piece of code that represents your nomor code. This problem may occur if you do not use MVC
The createTreePaketExist will be called during component initialisation, it's unlikely the textfields are actually rendered or even initialised properly at this point, best to use the listeners. You could use refs in your controller to get a reference to these fields automatically or you could listen to the afterrender event and then reference the fields.
I have created a fiddle here that shows how to load the store on form submit, you could also do this on the textfield's change events.
Here is the code for reference:
Ext.application({
name: 'Fiddle',
launch: function() {
var panel = Ext.create('Ext.form.Panel', {
renderTo: Ext.getBody(),
defaultType: 'textfield',
name: 'nodebPanel',
width: '100%',
layout: {
type: 'auto',
align: 'stretch'
},
items: [{
xtype: 'fieldset',
name: 'modlayanan',
title: 'Data Pelanggan',
layout: 'column',
width: '95%',
margin: '10',
items: [{
xtype: 'textfield',
name: 'nomor',
id: 'nomor',
fieldLabel: 'PSTN',
emptyText: 'Nomor...',
margin: '10 0 0 0',
width: 350,
labelWidth: 100,
afterLabelTextTpl: this.requiredSign
}, {
xtype: 'textfield',
fieldLabel: 'Speedy',
name: 'speedy',
id: 'speedy',
margin: '10 0 10 20',
width: 350,
labelWidth: 100
}]
}],
dockedItems: [{
xtype: 'toolbar',
name: 'tbpaketmc',
dock: 'bottom',
items: [{
text: '<< Back',
action: 'doBack'
}, '->', {
text: 'Submit',
action: 'doSubmit',
bindForm: true,
handler: function() {
var nopstn = Ext.getCmp('nomor').getValue();
var speedy = Ext.getCmp('speedy').getValue();
if (nopstn != '' && speedy != '') {
var store = Ext.ComponentQuery.query('#treeProduct')[0].getStore();
console.log(store);
store.load({
params: {
nopstn: nopstn,
speedy: speedy
}
});
}
}
}]
}]
});
var storeTree = Ext.create('Ext.data.TreeStore', {
autoLoad: false,
proxy: {
type: 'ajax',
method: 'POST',
url: 'data/newoss_get_paket.php'
}
});
var groupProduct = Ext.create('Ext.tree.Panel', {
renderTo: Ext.getBody(),
store: storeTree,
itemId: 'treeProduct',
name: 'treeProduct',
rootVisible: false,
useArrows: true,
layout: 'fit',
margin: '0 0 0 0',
autoScroll: true,
height: 150,
width: '93%',
listeners: {
checkchange: function(node, checked, eOpts) {
node.eachChild(function(n) {
node.cascadeBy(function(n) {
n.set('checked', checked);
});
});
p = node.parentNode;
var pChildCheckedCount = 0;
p.suspendEvents();
p.eachChild(function(c) {
if (c.get('checked')) pChildCheckedCount++;
p.set('checked', !! pChildCheckedCount);
});
p.resumeEvents();
}
}
});
}
});

Aligning a textfield to right in a container

I am trying to align a textfield to the right
From : _____________ To:____________
**Textbox here** **Textbox here**
I use column layout for from and to inputs, but I cannot get the textbox align to the right in each column.
Ext.define('AY.view.Temperature', {
requires: "Ext.form.field.ComboBox",
extend: 'Ext.form.Panel',
alias: 'widget.tempForm',
title: 'Temperature Convertor',
layout: 'column',
autoShow: true,
initComponent: function() {
this.items = [
{
xtype: 'form',
bodyStyle : Ext.isIE
? 'padding:5px 5px 5px 5px;'
: 'padding:5px 5px 5px;',
// border: 'true',
items: [
{
xtype:'combo',
fieldLabel: 'From',
store: tempTypes,
queryMode: 'local',
displayField: 'name',
valueField: 'abbr',
renderTo: Ext.getBody()
},
{
xtype: 'tbspacer',
height: 10
},
{
xtype: 'panel',
layout: {
type:'hbox',
align: 'middle'
},
items:[
{
xtype: 'tbfill',
flex: 1
},
{
xtype: 'textfield',
hideLabel: true,
ctCls : 'spaces',
name: 'from',
flex: 2,
allowBlank: 'false'
}
]
}
]
},
{
xtype :'form',
items: [
{
xtype: 'combo',
fieldLabel: 'To',
store: tempTypes,
queryMode: 'local',
displayField: 'name',
valueField: 'abbr',
renderTo: Ext.getBody()
},
{
xtype: 'textfield',
name: 'to',
hideLable: true,
readOnly: 'true'
}
]
}]
/*buttons:[{
text: 'convert',
handler: function(){
// convertTemp()
}
}]*/
//console.log("Here it is "+tempTypes);
this.callParent(arguments);
}
How do I introduce empty space before the textfield?
Like so (see the fiddle):
Ext.create('Ext.form.Panel', {
title: 'Simple Form',
bodyPadding: 5,
width: 350,
layout: 'anchor',
defaults: {
anchor: '100%'
},
title: 'Temperature Convertor',
autoShow: true,
items: [
{
xtype: 'combo',
fieldLabel: 'From',
queryMode: 'local',
displayField: 'name',
valueField: 'abbr'
}, {
xtype: 'tbspacer',
height: 10
}, {
xtype: 'fieldcontainer',
anchor: '100%',
layout: {
type: 'hbox'
},
items: [{
xtype: 'container',
width: 105, // need to match the fieldLabel width
height: 10
}, {
xtype: 'textfield',
flex: 1,
ctCls: 'spaces',
name: 'from',
allowBlank: 'false'
}]
} // rest of the form...
],
renderTo: Ext.getBody()
});
Note: You must not nest forms in other forms! And renderTo: Ext.getBody() must not be used for nested items!

how to pass combo box data to textfield

Im working with combo box. How do I get the ID of the selected data to be pass on the other textfield...
here is my sample code.
this is my combo box field
{
fieldLabel: 'Country',
name: 'idCountry',
xtype: 'combo',
margin: '0 0 10',
labelAlign: 'right',
validateBlank: true,
displayField: 'countryName',
valueField: 'idCountry',
store: 'country.Country',
},
and this is the code for textfield that I want the idCountry to be stored.
{
fieldLabel: 'Country Id',
name: 'temp_id_countrt',
xtype: 'textfield',
margin: '0 0 10',
labelAlign: 'right',
validateBlank: true,
},
thanks and Regards.. Gar
config: {
idCountry: null,
},
constructor : function (config) {
this.initConfig(config);
this.callParent(arguments);
},
{
xtype: 'textfield',
name : 'id',
fieldLabel: 'Country Id',
value: this.getidCountry()
},

Two Grids on Same Page Extjs 4

I am using this
Ext.define('Wifi.view.widget', {
extend: 'Ext.grid.Panel',
xtype: 'customerlist',
selModel: {
selType: 'cellmodel'
},
height: 380,
width: 700,
viewConfig: {
stripeRows: true
},
initComponent: function() {
Ext.apply(this, {
// Each grid will create its own store now when it is initialized.
store: Ext.create('Wifi.store.Customers'),
plugins: Ext.create('Ext.grid.plugin.CellEditing'),
columns: [{
text: 'Column Name', // Two line header! Test header height synchronization!
locked : false,
width : 200,
sortable : false,
dataIndex: 'columnName'
},{
text : 'Display Name',
width : 200,
sortable : true,
dataIndex: 'displayName',
editor: {
xtype: 'textfield'
}
},{
text : 'Column Width',
width : 150,
sortable : true,
dataIndex: 'columnWidth',
editor: {
xtype: 'numberfield'
}
},{
text : 'Column Type',
width : 100,
sortable : true,
dataIndex: 'columnType',
editor: {
xtype: 'ColumnTypeCombo'
}
}]
});
this.callParent(arguments);
}
});
grid on the same page..
Ext.define('Wifi.view.ViewPortletConfig', {
extend: 'Ext.container.Viewport',
requires: ['Wifi.view.ViewDetailCombo'],
initComponent: function() {
var me = this;
Ext.apply(me, {
items: [
{
region: 'center',
layout:'column',
items : [
{
columnWidth: 1/2,
title: 'Table 1 Column Details',
border:true,
margin:'5 5 5 5',
items:[
{
xtype : 'toolbar',
height:35,
width:700,
border:true,
frame:true,
items: [
'->',
'Select Table: ',
{
margin:'0 50 0 0',
xtype : 'ViewDetailCombo'
}
]
},
{
xtype : 'customerlist'
}
]
},{
columnWidth: 1/2,
title: 'Table 2 Column Details',
border:true,
margin:'5 5 5 5',
items:[
{
xtype : 'toolbar',
height:35,
width:700,
border:true,
frame:true,
items: [
'->',
'Select Table: ',
{
margin:'0 50 0 0',
xtype : 'ViewDetailCombo'
},
]
},
{xtype : 'customerlist'}
]
}
]
}
]
});
me.callParent(arguments);
}
});
Only first grid store is loaded on the change of combo boxes of table 1 and table 2. Can somebody guide me, where is the problem. Thanks in advance.
You have your widget alias wrong. It should look like this:
alias: 'widget.customerlist'
Not xtype! You use xtype: 'customerlist' like you are in both Table N Columns which is a reference to the widget alias 'widget.customerlist'. The definition for the widget needs to change.

Resources