ExtJS4: How to pass arguments to initComponent - constructor

I am using Sencha Architect 2. I am trying to generate a generic UI element with a text search and a table displaying the results. Generic means I want to use it for several different type of searches, e.g. for users, or roles or still something else.
So what I definitely like in this context about Sencha Architect 2 is that it always generates classes. Here is my generated class:
Ext.define('ktecapp.view.ObjSearchPanel', {
extend: 'Ext.container.Container',
alias: 'widget.objsearchpanel',
height: 250,
id: 'UserSearchPanel',
itemId: 'UserSearchPanel',
width: 438,
layout: {
columns: 3,
type: 'table'
},
initComponent: function() {
var me = this;
Ext.applyIf(me, {
items: [
{
xtype: 'textfield',
itemId: 'txtSearchText',
fieldLabel: 'Search Text',
colspan: 2
},
{
xtype: 'button',
id: 'searchObj',
itemId: 'searchObj',
text: 'Search',
colspan: 1
},
{
xtype: 'gridpanel',
height: 209,
itemId: 'resultGrid',
width: 430,
store: 'UserDisplayStore',
colspan: 3,
columns: [
{
xtype: 'gridcolumn',
width: 60,
dataIndex: 'ID',
text: 'ID'
},
{
xtype: 'gridcolumn',
width: 186,
dataIndex: 'DISPLAYNAME',
text: 'Displayname'
},
{
xtype: 'gridcolumn',
width: 123,
dataIndex: 'JOBTITLE',
text: 'Job Title'
},
{
xtype: 'actioncolumn',
width: 35,
icon: 'icons/zoom.png',
items: [
{
icon: 'icons/zoom.png',
tooltip: 'Tooltip'
}
]
}
],
viewConfig: {
},
selModel: Ext.create('Ext.selection.CheckboxModel', {
})
}
]
});
me.callParent(arguments);
}
});
The problem I am having is that everything needs to be pretty customizable, dataIndexes of the columns, the store, ...
So how can I get a constructor like function for the class ObjSearchPanel where I pass all that information? In the code above all this looks pretty much hardcoded...
Thanks in advance
Kai

use config,
http://docs.sencha.com/ext-js/4-0/#!/api/Ext.Class-cfg-config
Ext.define('SmartPhone', {
config: {
hasTouchScreen: false,
operatingSystem: 'Other',
price: 500
},
constructor: function(cfg) {
this.initConfig(cfg);
}
});
var iPhone = new SmartPhone({
hasTouchScreen: true,
operatingSystem: 'iOS'
});
iPhone.getPrice(); // 500;
iPhone.getOperatingSystem(); // 'iOS'
iPhone.getHasTouchScreen(); // true;
iPhone.hasTouchScreen(); // true

Actually (in ExtJS 4), when you pass a config object to the constructor, this config object is assigned to this.initialConfig variable and still available to other functions of the class. So you can use it in the initComponent.
You still can find code in ExtJS 3.3 like this Ext.apply(this, Ext.apply(this.initialConfig, config)); in the initComponent of classes. However, use it at your own risk because this is not in the document of ExtJS 4, only found it in the source code.

Related

Combo box and check box in grid for editor in extjs 4?

I design the grid in extjs with editor option. I need the combo box as a column and also need combo box when i edit the grid. The i need delete column as the check box column for both edit and normal grid. Its not working. can any one please help me
Here is the snippet:
this.mcmGridPanel = new Ext.grid.GridPanel({
height: 300,
width: 690,
title: 'Results',
store: store,
multiSelect: true,
x: 0,
y: 170,
columns: [
{ xtype: 'gridcolumn', text: 'FlightNumber', sortable: true, flex: 1, width: 150, dataIndex: 'FlightNumber', hidden: true,
editor: new Ext.form.field.ComboBox({
typeAhead: true,
triggerAction: 'all',
selectOnTab: true,
lazyRender: true,
listClass: 'x-combo-list-small'
})
},
{ xtype: 'gridcolumn', text: 'Origin', sortable: true, width: 150, dataIndex: 'Origin',
editor: {
editor: new Ext.form.field.ComboBox({
typeAhead: true,
triggerAction: 'all',
selectOnTab: true,
lazyRender: true,
listClass: 'x-combo-list-small'
})
}
},
{ xtype: 'gridcolumn', text: 'Destination', sortable: true, width: 150, dataIndex: 'Destination',
editor: {
editor: new Ext.form.field.ComboBox({
typeAhead: true,
triggerAction: 'all',
selectOnTab: true,
lazyRender: true,
listClass: 'x-combo-list-small'
})
}
},
{ xtype: 'datecolumn', text: 'StartDate', width: 80, dataIndex: 'StartAvailability', format: 'Y-m-d',
editor: {
xtype: 'datefield',
allowBlank: false,
format: 'Y-m-d'
}
},
{ header: 'StartTime', text: 'StartTime', width: 60, dataIndex: 'StartAvailabilityTime',
editor: {
xtype: 'timefield',
format: 'H:i',
increment: 15,
allowBlank: false
}
},
{ xtype: 'datecolumn', text: 'EndDate', width: 80, dataIndex: 'EndAvailability', format: 'Y-m-d',
editor: {
xtype: 'datefield',
allowBlank: false,
format: 'Y-m-d'
}
},
{ header: 'EndTime', text: 'EndTime', width: 60, dataIndex: 'EndAvailabilityTime',
editor: {
xtype: 'timefield',
format: 'H:i',
increment: 15,
allowBlank: false
}
},
{
xtype: 'gridcolumn',
text: 'Delete?',
header: 'Delete?',
dataIndex: 'delete',
width: 60,
renderer: function (value, meta, record, rowIndex, colIndex) {
return '<center><input type="checkbox" id="Delete-' + rowIndex + '"/></center>';
},
handler: function() {
},
//disabled: true,
editor: {
xtype: 'checkbox',
cls: 'x-grid-checkheader-editor',
}
}
]
});
I use the following code but Its not working. can any one please help me
I don't see the function that should display the combobox. In order to get this to work automatically, you shoud add the RowEditing plugin.
Try to add this
plugins: [
Ext.create('Ext.grid.plugin.RowEditing', {
clicksToMoveEditor: 1,
autoCancel: false
})
],
Look at this example in the doc. This will help you to get row editing work.
Is your column definition OK?
I got a combobox using this, but I'm aware this is not the full configuration needed:
{
dataIndex: 'name',
flex: 1,
text: 'Name',
field: {
xtype: 'combobox'
},
}
Update
I experienced today a similar problem: my textfields were not rendering.
The culprit was unexpected:
I use a custom template, and the css rules needed for the display were missing. All I had to do was rebuilding the app using sencha cmd sencha app build. This completed the files of the template, and the field of the roweditor displayed correctly.
Chances are that this is also the case with you...

How to make a circle in a customized view class?

I am trying to draw a circle using Sencha's Ext.draw.Component in my customized view class but it is not showing any circle in it. I have pasted the code for reference.
I also tried to define the variable of type component in my Main class but upon doing so the compiler gave an error saying that the type component is unknown.
// Main Class
Ext.define('GS0.view.Main', {
extend: 'Ext.tab.Panel',
xtype: 'main',
requires: [
'Ext.TitleBar',
'Ext.Video',
'Ext.Carousel',
'Ext.Container',
'Ext.draw.Component',
'Ext.Img'
],
config: {
tabBarPosition: 'bottom',
items: [
{
iconCls: 'home',
xtype: 'carousel',
ui : 'dark',
direction: 'horizontal',
items: [
{
xtype: 'draw',
type: 'circle',
radius: 50,
x: 100,
y: 100,
fill: '#2d2d2d'
},
{
xtype: 'img',
src: 'images/nm.jpg'
}
]
}
]
}
});
// Circle Class
Ext.define('GS0.view.CC', {
extend: 'Ext.draw.Component',
xtype: 'cc',
config: {
type: 'circle',
cx: 100,
cy: 100,
r: 25,
fillStyle: 'blue'
}
});
Try modifying you items in the GSO.view.Main
items: [{
iconCls: 'home',
xtype: 'carousel',
ui : 'dark',
direction: 'horizontal',
items: [{
xtype: 'draw',
items:[{
type: 'circle',
fill: '#79BB3F',
radius: 100,
x: 100,
y: 100
}]
},{
xtype: 'img',
src: 'images/nm.jpg'
}]
}]
The circle code should be added as an item to the xtype=draw block.
I think the way I am loading the Main is a problem. here is the code. Can you spot any error. PS please see line Ext.viewport.add(Ext.create(GS0.view.main))
Ext.Loader.setPath({
'Ext': 'touch/src',
'GS0': 'app'
});
//</debug>
Ext.application({
name: 'GS0',
requires: [
'Ext.MessageBox'
],
views: [
'Main'
],
icon: {
'57': 'resources/icons/Icon.png',
'72': 'resources/icons/Icon~ipad.png',
'114': 'resources/icons/Icon#2x.png',
'144': 'resources/icons/Icon~ipad#2x.png'
},
isIconPrecomposed: true,
startupImage: {
'320x460': 'resources/startup/320x460.jpg',
'640x920': 'resources/startup/640x920.png',
'768x1004': 'resources/startup/768x1004.png',
'748x1024': 'resources/startup/748x1024.png',
'1536x2008': 'resources/startup/1536x2008.png',
'1496x2048': 'resources/startup/1496x2048.png'
},
launch: function() {
// Destroy the #appLoadingIndicator element
Ext.fly('appLoadingIndicator').destroy();
// Initialize the main view
Ext.Viewport.add(Ext.create('GS0.view.Main'));
},
onUpdated: function() {
Ext.Msg.confirm(
"Application Update",
"This application has just successfully been updated to the latest version. Reload now?",
function(buttonId) {
if (buttonId === 'yes') {
window.location.reload();
}
}
);
}
});

How to use generated json to build an extjs window?

I use ExtDesigner designed a window, and the generated json is like:
{
xtype: 'window',
height: 477,
width: 666,
layout: 'fit',
title: '添加广告位',
items: [
{
xtype: 'form',
bodyStyle: 'padding: 10px',
title: '',
items: [
{
xtype: 'textfield',
anchor: '100%',
fieldLabel: '名称'
},
{
xtype: 'radiogroup',
anchor: '100%',
fieldLabel: '广告类型',
items: [
{
xtype: 'radio',
boxLabel: '文字'
},
{
xtype: 'radio',
boxLabel: '图片'
}
]
}
]
}
]
}
I copied it but I don't know how to use it. I don't find a method to convert it to an extjs component. How to do it?
PS: I use extjs 2.2
There are two ways to create an ExtJS component.
create the component explicitly, for example: new Ext.Window({...});. This way you get the component right away, meaning the event listeners, the extra methods...etc.
the second way is lazy loading, which is by specifying the xtype of a component in a plain javascript object. This is exactly what you have.
To make the second way work, you need to include your xtype-javascript-object in an ExtJs container, and the container will know how to render it at the appropriate time.
for example :
Ext.onReady(function(){
new Ext.Viewport({
layout : 'fit',
items : [{
xtype: 'window',
height: 477,
width: 666,
layout: 'fit',
title: '添加广告位',
items: [...]
}]
});
});
Think you are looking for something like this. This will show your window in a pop up.
var win = new Ext.Window({
width:400
,id:'autoload-win'
,height:300
,autoScroll:true
});
win.show();

Sencha - How to display images in xtype panel html where image source is load from model

Below is code from Store where i have hardcoded data for testing.
`Ext.regStore('CalendarStore', {
model: 'CalendarModel',
sorters: [{
property: 'id',
direction: 'ASC'
}],
proxy: {
type: 'localstorage',
id: 'calendar-app-store'
},
data: [
{ id: 1, title: 'January', image: 'jan.iPNG'}
, { id: 2, title: 'Febuary'}
, { id: 3, title: 'March'}
, { id: 4, title: 'April'}
, { id: 5, title: 'May'}
, { id: 6, title: 'June'}
, { id: 7, title: 'July'}
, { id: 8, title: 'August'}
, { id: 9, title: 'September'}
, { id: 10, title: 'October'}
, { id: 11, title: 'November'}
, { id: 12, title: 'December'}
]
});`
and i am trying to load image i.e 'jan.PNG' which i have in store and source changes with month.i am able to display month name from {title} but not from {image}.All i get is a ?mark on the app.
I read that if i get ? mark then the src path is incorrect but if i give
'html : '<img style="height: 700px; width: 500px;" src="jan.iPNG "/>' '
or
src="http://www.mypics/jan.iPNG "/>' '
these display fine.
below is the view
'CalendarApp.views.viewCalendar = new Ext.form.FormPanel({
id: 'viewCalendar',
scroll: 'true',
items:[{
xtype: 'textfield',
name: 'title'
// label: 'title'
},
{
xtype: 'panel',
name :'image',
html : '<img style="height: 700px; width:500px;" src="'+'image'+'">'
}],
dockedItems:[CalendarApp.views.calTopToolbar]
});'
Also tried variation src="image"> but the image doesnt display. Help tearing my hair off
First save the image in custom folder where your files are present.
and use below code,
{
xtype: 'panel',
icon: 'jan.png', // specify the path of the image
width:100, // if u want to specify the width for image
height:80, // if u want to specify the height for image
iconMask: false,
handler: jan // if u want to handle the click event
}
another option is u can define the image in html file by
<style>
.NewIcon {
-webkit-mask-box-image: url('../img/new_icon.png');
}
</style>
and specify this New icon in the js file where you want to use it
{
xtype: 'panel',
iconCls: 'NewIcon ',
width:100,
height:80,
iconMask: false,
handler: newicon
}

Sencha - Display images in xtype panel html where image source is load from model

Below is code for Store where i have hardcoded data for testing.
`Ext.regStore('CalendarStore', {
model: 'CalendarModel',
sorters: [{
property: 'id',
direction: 'ASC'
}],
proxy: {
type: 'localstorage',
id: 'calendar-app-store'
},
data: [
{ id: 1, title: 'January', image: 'jan.iPNG'}
, { id: 2, title: 'Febuary'}
, { id: 3, title: 'March'}
, { id: 4, title: 'April'}
, { id: 5, title: 'May'}
, { id: 6, title: 'June'}
, { id: 7, title: 'July'}
, { id: 8, title: 'August'}
, { id: 9, title: 'September'}
, { id: 10, title: 'October'}
, { id: 11, title: 'November'}
, { id: 12, title: 'December'}
]
});`
and i am trying to load image i.e 'jan.iPNG' which i have in store and source changes with month.i am able to display month name from {title} but not from {image}.All i get is a ?mark on the app.
I read that if i get ? mark then the src path is incorrect but if i give
'html : '<img style="height: 700px; width: 500px;" src="jan.iPNG "/>' '
it displays fine.
below is the view
'CalendarApp.views.viewCalendar = new Ext.form.FormPanel({
id: 'viewCalendar',
scroll: 'true',
items:[{
xtype: 'textfield',
name: 'title'
// label: 'title'
},
{
xtype: 'panel',
name :'image',
html : '<img style="height: 700px; width: 500px;" src="{image}"/>'
}],
dockedItems:[CalendarApp.views.calTopToolbar]
});'
First save the image in custom folder where your files are present.
and use below code,
{
xtype: 'panel',
icon: 'jan.png', // specify the path of the image
width:100, // if u want to specify the width for image
height:80, // if u want to specify the height for image
iconMask: false,
handler: jan // if u want to handle the click event
}
another option is u can define the image in html file by
<style>
.NewIcon {
-webkit-mask-box-image: url('../img/new_icon.png');
}
</style>
and specify this New icon in the js file where you want to use it
{
xtype: 'panel',
iconCls: 'NewIcon ',
width:100,
height:80,
iconMask: false,
handler: newicon
}