i have a question.
probably it will be a easy solution.
how can i get the Values of the textfields, when i click the Save Button???
Ext.define('MyApp.view.main.MyForm', {
extend: 'Ext.Window',
layout: 'column',
.
.
.
defaults: {
layout: 'form',
xtype: 'container',
defaultType: 'textfield',
labelWidth: 150,
width: 300
},
items: [{
items: [
{ fieldLabel: 'FirstName', allowBlank: false },
{ fieldLabel: 'LastName', allowBlank: false },
]
}, {
items: [
{ fieldLabel: 'Street' },
{ fieldLabel: 'Town' },
]
}],
buttons: [
{ text: 'Save', handler: function(){ alert('Saved!'); } },
]
});
You must use form field container, for example - Ext.form.Panel.
Then you can use getForm() and then getValues(), also check your fields - isValid() for checking allowBlank.
var formPanel = Ext.create('Ext.form.Panel', {
name: 'myfieldform',
defaults: {
layout: 'form',
xtype: 'container',
defaultType: 'textfield',
labelWidth: 150,
width: 300
},
items: [{
items: [
{
fieldLabel: 'FirstName',
allowBlank: false
},
{
fieldLabel: 'LastName',
allowBlank: false
},
]
}, {
items: [
{ fieldLabel: 'Street' },
{ fieldLabel: 'Town' },
]
}]
});
Ext.define('MyApp.view.main.MyForm', {
...
items: [
formPanel
],
buttons: [
{
text: 'Save',
handler: function(btn) {
var form = btn.up().up().down('[name="myfieldform"]').getForm(),
values;
if (!form || !form.isValid())
{
alert('Check your form please!');
return;
}
values = form.getValues();
for(var name in values) {
alert(values[name]);
}
}
}
]
});
Sencha Fiddle Example
Your handler function will have the button and the event options in it's signature. Use the button and the "Up" function to get the form element and retrieve the record model attached to the form (assuming you are using models).
handler: function(btn, eOpts){
var form = btn.up('form');
form.getForm().updateRecord();
var record = form.getForm().getRecord();
alert('Saved!');
}
If you are not using a model and just want the values add an itemId to each field in your form and again use the up function with a "#" to retrieve a specific component. Then simply use the getValue method.
items: [
{ fieldLabel: 'FirstName', itemId: 'firstnamefield', allowBlank: false },
{ fieldLabel: 'LastName', itemId: 'lastnamefield', allowBlank: false },
]
handler: function(btn, eOpts){
var firstNameField = btn.up('#firstnamefield');
var firstNameValue = firstNameField.getValue();
alert('Saved!');
}
Seriously, why go with the up.up.down approach, if you can get to the thing straight away?
var form = Ext.ComponentQuery.query('[name="myfieldform"]').getForm()[0];
Or
values = Ext.ComponentQuery.query('[name="myfieldform"]').getForm()[0].getValues();
In other words, take above answer and make it like this:
var formPanel = Ext.create('Ext.form.Panel', {
name: 'myfieldform',
defaults: {
layout: 'form',
xtype: 'container',
defaultType: 'textfield',
labelWidth: 150,
width: 300
},
items: [{
items: [
{
fieldLabel: 'FirstName',
allowBlank: false
},
{
fieldLabel: 'LastName',
allowBlank: false
},
]
}, {
items: [
{ fieldLabel: 'Street' },
{ fieldLabel: 'Town' },
]
}]
});
Ext.define('MyApp.view.main.MyForm', {
...
items: [
formPanel
],
buttons: [
{
text: 'Save',
handler: function(btn) {
var form = Ext.ComponentQuery.query('[name="myfieldform"]').getForm()[0];
if (!form || !form.isValid())
{
alert('Check your form please!');
return;
}
values = form.getValues();
for(var name in values) {
alert(values[name]);
}
}
}
]
});
Related
I created a table using extjs where it is having three columns name, email and cars. In extjs we are having a default sorting method. here i want to add search method for all these three columns so that i can also search using the name, email and cars.
What change i need to do for the below code
The expected output is i need to get search filter option under each columns.
Ext.define('ViewerModel', {
extend: 'Ext.app.ViewModel',
alias: 'viewmodel.viewermodel',
stores: {
mystore: {
fields: ['name', 'email', 'cars'],
data: {
'items': [{
'name': 'Lisa',
"email": "lisa#simpsons.com"
}, {
'name': 'Bart',
"email": "bart#simpsons.com"
}, {
'name': 'Homer',
"email": "homer#simpsons.com"
}, {
'name': 'Marge',
"email": "marge#simpsons.com"
}]
},
proxy: {
type: 'memory',
reader: {
type: 'json',
rootProperty: 'items'
}
}
}
}
});
Ext.define('APP.HorizontalBox', {
extend: 'Ext.container.Container',
requires: ['Ext.layout.container.HBox'],
xtype: 'layout-horizontal-box',
width: 750,
height: 300,
layout: {
type: 'hbox',
align: 'stretch'
},
bodyPadding: 10,
defaults: {
frame: true,
bodyPadding: 10
},
viewModel: {
type: 'viewermodel'
},
items: [{
xtype: 'grid',
title: 'Grid: click on the grid rows',
itemId: 'myGridItemId',
flex: 1.2,
margin: '0 10 0 0',
bind: {
store: '{mystore}',
selection: '{users}'
},
columns: [{
text: 'Name',
dataIndex: 'name',
flex: 0.5
}, {
text: 'Email',
dataIndex: 'email',
flex: 1
}, {
text: 'Cars',
dataIndex: 'cars',
flex: 1
}],
dockedItems: [{
xtype: 'toolbar',
dock: 'top',
items: [{
xtype: 'button',
padding: '2 5 2 5',
text: 'Edit item',
handler: function (btn) {
var grid = btn.up('grid');
var selectedRow = grid.getSelectionModel().getSelection()[0];
var janela = Ext.create('APP.MyWindow', {
animateTarget: btn.getEl(),
//EDITED
viewModel: {
data: {
users: selectedRow
}
}
}).show();
}
}]
}],
}, {
xtype: 'form',
title: 'View',
itemId: 'panelbindItemId',
flex: 1,
margin: '0 10 0 0',
defaults: {
labelWidth: 50
},
items: [{
xtype: 'displayfield',
margin: '20 0 0 0',
fieldLabel: 'Name',
bind: '{users.name}'
}, {
xtype: 'displayfield',
fieldLabel: 'Email',
bind: '{users.email}'
}]
}]
});
Ext.define('APP.MyWindow', {
extend: 'Ext.window.Window',
alias: 'widget.mywindow',
reference: 'windowreference',
title: 'MyWindow | Edit record',
closable: true,
modal: true,
padding: '10px',
height: 150,
layout: 'fit',
initComponent: function () {
var me = this;
Ext.apply(me, {
items: [{
xtype: 'form',
layout: 'anchor',
defaults: {
padding: '5 0 5 0'
},
items: [{
xtype: 'textfield',
margin: '10 0 0 0',
fieldLabel: 'Name',
bind: '{users.name}'
}, {
xtype: 'textfield',
fieldLabel: 'Email',
bind: '{users.email}'
}]
}]
});
me.callParent(arguments);
}
});
Ext.application({
name: 'Fiddle',
launch: function () {
Ext.create('APP.HorizontalBox', {
renderTo: document.body,
width: 750,
height: 400,
title: 'Title'
});
}
});
You can do it in the afterrender event of grid (Refer this post.) For example:
listeners: {
afterrender: function () {
var menu = Ext.ComponentQuery.query('grid')[0].headerCt.getMenu();
menu.add([{
text: 'Search',
iconCls: 'x-fa fa-home',
handler: function () {
console.log("Search Item");
}
}]);
}
}
Check this Fiddle.
What you are searching for is the FiltersFeature, and the usage is as follows:
xtype:'grid',
...
features:[{
ftype: 'filters',
local: true,
filters: [{
type: 'string',
dataIndex: 'name'
}, {
... (one definition for every column you want to allow filtering one)
}]
}]
Please note that you have to add a requires and maybe even load Ext.ux, as can be found in the last comment.
Other readers please be aware that FiltersFeature is ExtJS4 specific, and has been moved around for ExtJS 5 and 6.
You can also use this code where it will search the data using the date.
listeners: {
afterrender: function () {
var menu = Ext.ComponentQuery.query('grid')[0].headerCt.getMenu();
menu.add([{
xtype:'datefield',
name:'date1',
fieldLabel:'Filter By',
format: 'y-m-d',
listeners:{
renderer: Ext.util.Format.dateRenderer('y-m-d'),
field:{ xtype:'datefield',
autoSync:true,
allowBlank:false,
editor: new Ext.form.DateField(
{format: 'y-m-d'}) }
}
}
how to show data in form panel after click one of data in pop up in grid view, I have try another way but always wrong,
this is my grid panel :
var tt = Ext.define('Rendering.view.beli.dataSupplier', {
extend: 'Ext.form.Panel',
//extend: 'Ext.window.Window',
// xtype: 'beligrid',
alias : 'widget.contatoform',
frame: true,
// id: 'detailPanelis',
title: 'Company data',
bodyPadding: 5,
layout: 'column',
requires: [
'Ext.grid.*',
'Ext.form.*',
'Ext.layout.container.Column'
],
initComponent: function() {
this.items = [
{
columnWidth: 0.65,
xtype: 'gridpanel',
reference: 'customerGrid',
store: 'BeliStore',
columns : [{
text: 'Nama',
dataIndex: 'namaSupplier',
flex: 1
}, {
text: 'Alamat',
dataIndex: 'address',
flex: 1
}],
listeners: {
scope: this,
selectionchange: 'onSelectionChanges'
}
}];
//];
// });
this.callParent(arguments);
},
onSelectionChanges: function(model, records) {
//alert('yuhuuuu');
var editt = Ext.create('Rendering.view.beli.bg_beli');
var c = editt.onSelectionChange(model, records);
}
});
the function for to send data to form panel is
listeners: {
scope: this,
selectionchange: 'onSelectionChanges'
}
this is function of onSelectionChanges :
onSelectionChanges: function(model, records) {
//alert('yuhuuuu');
var editt = Ext.create('Rendering.view.beli.bg_beli');
var c = editt.onSelectionChange(model, records);
}
and form panel :
var tt = Ext.define('Rendering.view.beli.bg_beli', {
extend: 'Ext.form.Panel',
xtype: 'beligrid',
controller: 'binding-dynamic',
frame: true,
title: 'Company data',
bodyPadding: 5,
layout: 'column',
requires: [
'Ext.grid.*',
'Ext.form.*',
'Ext.layout.container.Column'
],
// In this example, configuration is applied at initComponent time
// because it depends on profileInfo object that is generated for the
// FormGrid instance.
initComponent: function() {
//Ext.apply(this, {
this.items = [
{
columnWidth: 0.65,
xtype: 'gridpanel',
store: 'BeliStore',
columns : [{
text: 'Nama',
dataIndex: 'namaSupplier',
flex: 1
}, {
text: 'Alamat',
dataIndex: 'address',
flex: 1
}],
listeners: {
scope: this,
selectionchange: 'onSelectionChange'
}
},{
columnWidth: 0.35,
margin: '20 0 0 10',
xtype: 'form',
title:'Company detailsss',
layout: 'anchor',
defaultType: 'textfield',
items: [
{
name : 'id_supplier',
fieldLabel: 'id',
hidden:true
},{
fieldLabel: 'Nama Supplier',
name: 'namaSupplier'
},{
fieldLabel: 'email',
name: 'email'
},{
fieldLabel: 'alamat',
name: 'address'
},{
xtype: 'button',
text: 'YUY',
action: 'add'
}]
}];
//];
// });
this.callParent(arguments);
},
onSelectionChange: function(model, records) {
alert('asdasd');
console.log(records);
var rec = records[0];
console.log(rec);
if (rec) {
var c = this.getForm().loadRecord(rec);
// this.getBeliStoreStore().load();
console.log(this.getForm().loadRecord(rec));
}
}
});
I send data from grid to form panel, and the function that accepted data in form panel is :
onSelectionChange: function(model, records) {
alert('asdasd');
console.log(records);
var rec = records[0];
console.log(rec);
if (rec) {
var c = this.getForm().loadRecord(rec);
// this.getBeliStoreStore().load();
console.log(this.getForm().loadRecord(rec));
}
}
please help, I have looking for to any reference but I don't get answer yet, thanks before
My suggestion is modify the call for event this.onSelectionChange or like that this.on('selectionchange',this.onSelectionChange) it is another way for call events in extjs
initComponent: function() {
var me = this ;
this.items = [
{
columnWidth: 0.65,
xtype: 'gridpanel',
reference: 'customerGrid',
store: 'BeliStore',
columns : [{
text: 'Nama',
dataIndex: 'namaSupplier',
flex: 1
}, {
text: 'Alamat',
dataIndex: 'address',
flex: 1
}],
listeners: {
scope: this,
selectionchange: me.onSelectionChanges
}
}];
//];
// });
this.callParent(arguments);
}
OR
initComponent: function() {
var me = this ;
var grid = Ext.create('Ext.grid.Panel', {
reference: 'customerGrid',
store: 'BeliStore',
columns : [{
text: 'Nama',
dataIndex: 'namaSupplier',
flex: 1
}, {
text: 'Alamat',
dataIndex: 'address',
flex: 1
}
]});
me.items = [
{
columnWidth: 0.65,
grid
}];
grid.on('selectionchange',me.onSelectionChange)
this.callParent(arguments);
}
http://docs.sencha.com/extjs/4.2.5/#!/example/build/KitchenSink/ext-theme-neptune/#form-grid
This is my popup with tabs.
I need to give a value from record to gridpanel in tab 2 in store to get attributes from server side by category_id. Searched answer in official documentation and didn't find.
Can help me somebody?
Ext.define('desk.view.CategoryPopup', {
extend: 'Ext.window.Window',
alias: 'widget.categorypopup',
title: 'Change Category',
layout: 'fit',
autoShow: true,
bdoyPadding: 10,
initComponent: function(){
this.items = [{
xtype: 'tabpanel',
items: [
{
xtype: 'form',
title: 'Add / Edit / Delete Category',
items: [
{
xtype: 'textfield',
name: 'name',
fieldLabel: 'Parent Category'
},
{
xtype: 'textfield',
name: 'new',
fieldLabel: 'New Category'
},
{
xtype: 'textfield',
name: 'id',
fieldLabel: 'Category ID',
hidden: true
},
{
xtype: 'textfield',
name: 'parent',
fieldLabel: 'Parent ID',
hidden: true
}
],
bodyPadding: 10
},
{
xtype: 'gridpanel',
alias: 'widget.categoryattr',
title: 'Attributes',
height: 350,
buttons: [{'text': 'Add attribute', 'action' : 'add-attribute'}],
columns: [
{
name: 'Name',
dataIndex: 'name'
}
],
width: 300,
store: Ext.widget('categoryattributes')
}
]
}];
this.buttons = [
{
text: 'Update',
action: 'add'
},
{
text: 'Delete',
action: 'delete'
}
];
this.callParent(arguments);
}
})
This is function in controller
editCategories: function(grid, record){
var view = Ext.widget('categorypopup');
view.down('form').loadRecord(record);
}
you need something like this:
editCategories: function(grid, record){
var view = Ext.widget('categorypopup');
view.down('form').loadRecord(record);
Ext.Ajax.request({
url: '/api/category/'+ record.getId() +'/attributes', //example url insert your webservice
success: function(response){
var attributes = Ext.decode(response.responseText);
view.down('grid').getStore().loadData(attributes);
}
});
}
you will need a store with a model for your grid.
I have an actioncolumn in a grid. I used to open a window after i clicked on this but now do we want to open a new tab in the tabpanel instead of the windows. This is the tab i want to generate when someone clicks on the actionpanel:
Ext.define('MyApp.view.MyTabPanel2', {
extend: 'Ext.tab.Panel',
alias: 'widget.mytabpanel2',
closable: true,
title: 'Report {name}',
activeTab: 1,
initComponent: function() {
var me = this;
Ext.applyIf(me, {
dockedItems: [
{
xtype: 'toolbar',
dock: 'top',
items: [
{
xtype: 'textfield',
fieldLabel: 'Reference',
labelAlign: 'top'
},
{
xtype: 'datefield',
fieldLabel: 'From',
labelAlign: 'top'
},
{
xtype: 'datefield',
fieldLabel: 'To',
labelAlign: 'top'
},
{
xtype: 'tbfill'
},
{
xtype: 'button',
text: 'Open report'
},
{
xtype: 'button',
text: 'Save report'
},
{
xtype: 'button',
text: 'Export report'
},
{
xtype: 'button',
text: 'Refresh data'
}
]
}
],
items: [
{
xtype: 'gridpanel',
title: 'Grid',
forceFit: true,
store: 'resultStore',
columns: [
{
xtype: 'gridcolumn',
dataIndex: 'ccuDesignation',
text: 'CCU Designation'
},
{
xtype: 'gridcolumn',
dataIndex: 'carrierName',
text: 'Carrier Name'
},
{
xtype: 'gridcolumn',
dataIndex: 'dataPackageName',
text: 'Data package name'
},
{
xtype: 'gridcolumn',
dataIndex: 'bytesRx',
text: 'bytesRX'
},
{
xtype: 'gridcolumn',
dataIndex: 'bytesTx',
text: 'bytesTX'
}
],
viewConfig: {
}
},
{
xtype: 'panel',
title: 'Chart',
dockedItems: [
{
xtype: 'chart',
height: 250,
animate: true,
insetPadding: 20,
store: 'resultStore',
dock: 'top',
axes: [
{
type: 'Category',
fields: [
'ccuDesignation'
],
position: 'bottom',
title: 'CCU Designation'
},
{
type: 'Numeric',
fields: [
'bytesTx'
],
position: 'left',
title: 'Bytes'
},
{
type: 'Numeric',
fields: [
'bytesRx'
],
position: 'left',
title: 'Bytes'
}
],
series: [
{
type: 'line',
xField: 'x',
yField: [
'bytesTx'
],
smooth: 3
},
{
type: 'line',
xField: 'x',
yField: [
'bytesRx'
],
smooth: 3
}
],
legend: {
}
}
]
}
]
});
me.callParent(arguments);
}
});
i have read this at sencha:
// tab generation code
var index = 0;
while(index < 3){
addTab(index % 2);
}
function addTab (closable) {
++index;
tabs.add({
title: 'New Tab ' + index,
iconCls: 'tabs',
html: 'Tab Body ' + index + '<br/><br/>' + Ext.example.bogusMarkup,
closable: !!closable
}).show();
}
Ext.createWidget('button', {
renderTo: 'addButtonCt',
text: 'Add Closable Tab',
handler: function () {
addTab(true);
},
iconCls:'new-tab'
});
Ext.createWidget('button', {
renderTo: 'addButtonCt',
text: 'Add Unclosable Tab',
handler: function () {
addTab(false);
},
iconCls:'new-tab',
style: 'margin-left: 8px;'
});
But i don't have the var tabs in my script. So how can i add the tab to this:
Ext.define('MyApp.view.MyViewport', {
extend: 'Ext.container.Viewport',
layout: {
type: 'border'
},
initComponent: function() {
var me = this;
Ext.applyIf(me, {
items: [
{
xtype: 'tabpanel',
id: 'tabs',
activeTab: 1,
region: 'center',
items: [
{
xtype: 'gridpanel',
title: 'Reports',
forceFit: true,
store: 'ReportsStore',
columns: [
{
xtype: 'gridcolumn',
dataIndex: 'Name',
text: 'Name'
},
{
xtype: 'gridcolumn',
dataIndex: 'Type',
text: 'Type'
},
{
xtype: 'gridcolumn',
dataIndex: 'Description',
text: 'Description'
},
{
xtype: 'actioncolumn',
dataIndex: 'queryFields',
items: [
{
handler: function(view, rowIndex, colIndex, item, e) {
addTab;
alert('clicked');
},
altText: 'Open report',
icon: 'img/report-arrow.png',
tooltip: 'Open report'
}
]
}
],
viewConfig: {
},
dockedItems: [
{
xtype: 'toolbar',
dock: 'bottom',
items: [
{
xtype: 'tbfill'
},
{
xtype: 'button',
iconCls: 'addReport',
text: 'Add report',
listeners: {
click: {
fn: me.onButtonClick,
scope: me
}
}
}
]
}
]
}
]
}
]
});
me.callParent(arguments);
},
onButtonClick: function(button, e, options) {
Ext.create('MyApp.view.addReport').show();
}
});
var tabs = Ext.getCmp('tabs');
function addTab (closable) {
alert('yes');
tabs.add(Ext.create('MyApp.view.MyTabPanel2'));
}
How can i do this? I work with extjs designer 2
In that first view you've shown above, you are creating another tabpanel not an individual tab. If you tried to insert that into the tabpanel that you defined in your viewport you would have a tabpanel inside of another tabpanel. I don't think that is what you are trying to do.
You could create that first view above as an Ext.tab.Tab which contains the gridpanel or just create it as the gridpanel itself and include the tab config options in your add method call. To answer your question about referencing the tabpanel when you don't have it defined as a variable: you should just give it an id config (e.g. id: 'tabs') and then you can use Ext.getCmp('tabs'). For example:
// a piece of your viewport config
Ext.applyIf(me, {
items: [
{
xtype: 'tabpanel',
activeTab: 1,
region: 'center',
id: 'tabs', // <-- include this config
// other configs...
Adding the tab could then be done like this:
// get a reference to the tab panel
var tabs = Ext.getCmp('tabs');
// if you create the view as a gridpanel you could do it like this
tabs.add({
title: sometitle,
iconCls: someicon,
closable: yayOrNay,
items: [Ext.create('MyApp.view.MyGridPanel')]
});
// OR if you create the view as an Ext.tab.Tab which already contains the gridpanel
tabs.add(Ext.create('MyApp.view.MyTab'));
Read And Use Following Code:
function allExpenseTypeReport(){
var reportByExpenseType=Ext.getCmp("reportByExpenseType");
if(reportByExpenseType==null){
reportByExpenseType = new Ext.tm.reports.ExpenseTypeReport({
title:WtfGlobal.getLocaleText("ec.reportbyexpensetype"),
layout:'fit' ,
closable: true,
iconCls:'pwnd tabreportsWrap',
id:"reportByExpenseType"
});
Ext.getCmp('as').add(reportByExpenseType);
}
Ext.getCmp("as").setActiveTab(Wtf.getCmp("reportByExpenseType"));
reportByExpenseType.doLayout();
}
Define Here:
Ext.tm.reports.ExpenseTypeReport = function(config){
Ext.apply(this, config);
Ext.tm.reports.ExpenseTypeReport.superclass.constructor.call(this, config);
Define your Code Here:
};
I created a custom field for multiple file uploading, the problem is in the first step i couldn't even add selected file to grid, can you tell me what is the problem of my code? I looked at firebug and there is no java-script error.
Ext.define('VDOA.form.fields.Attachment', {
extend: 'Ext.form.FieldContainer',
mixins: {field: 'Ext.form.field.Field'},
requires: ['Ext.form.field.Base'],
alias: 'widget.attachment',
layout: 'fit',
constructor: function()
{
var me = this;
me.items = [
{
itemId: 'grid',
anchor: '100%',
width: 300,
height: 100,
xtype: 'gridpanel',
layout: 'fit',
autoRender: true,
autoShow: true,
tbar: [
{
itemId: 'add',
hideLabel: true,
buttonOnly: true,
buttonText: 'Browse a file',
xtype: 'fileuploadfield'
}
],
columns: [
{
dataIndex: 'Id',
xtype: 'gridcolumn',
text: 'File Id'
},
{
dataIndex: 'Title',
xtype: 'gridcolumn',
text: 'File Name'
}
]
}
];
me.callParent(arguments);
var store = Ext.create('Ext.data.ArrayStore', {
fields: [
{name: 'Id', type: 'int'},
{name: 'Title', type: 'string'},
{name: 'IsUploading', type: 'bool'}
],
data: []
});
me.down('#grid').store = store;
me.down('#add').on('change', function(o, e){
store.add({Id: Ext.id(), Title: o.value, IsUploading: true});
store.load();
});
},
getErrors: function() {
return [];
},
validate: function() {
return true;
}}); Ext.onReady(function() {
Ext.QuickTips.init();
var win = new Ext.Window({
width:500
,id:'winid'
,height:300
,layout:'fit'
,border:false
,closable:false
,title:'File Upload'
,items:[{
xtype:'form'
,frame:true
,labelWidth:100
,items:[{
name: 'Title',
xtype: 'textfield',
fieldLabel: 'Title',
allowBlank: false,
anchor: '100%'
},
{
name: 'Attachment',
xtype: 'attachment',
fieldLabel: 'Attached Files'
}]
}]
,buttons:[{
text:'Submit'
,handler:function() {
Ext.getCmp('form').getForm().submit();
}
}]
});
win.show();});
Ext.define('VDOA.form.fields.Attachment', {
extend:'Ext.form.FieldContainer',
mixins:{field:'Ext.form.field.Field'},
requires:['Ext.form.field.Base'],
alias:'widget.attachment',
layout:'fit',
constructor:function () {
var me = this,
store = Ext.create('Ext.data.ArrayStore', {
fields:[
{name:'Id', type:'int'},
{name:'Title', type:'string'},
{name:'IsUploading', type:'bool'}
],
data:[]
});
me.items = [
{
itemId:'grid',
anchor:'100%',
width:300,
height:100,
store: store, // link store there...
xtype:'gridpanel',
layout:'fit',
height:400,
autoRender:true,
autoShow:true,
tbar:[
{
itemId:'add',
hideLabel:true,
buttonOnly:true,
buttonText:'Browse a file',
xtype:'filefield'
}
],
columns:[
{
dataIndex:'Id',
xtype:'gridcolumn',
text:'File Id'
},
{
dataIndex:'Title',
xtype:'gridcolumn',
text:'File Name'
}
]
}
];
me.callParent(arguments);
//me.down('#grid').store = store;
me.down('#add').on('change', function (o, e) {
me.down('#grid').store.add({Id:Ext.id(), Title:o.value, IsUploading:true});
// store.load(); // remove it - it set data = [] as it was initialized before
});
},
getErrors:function () {
return [];
},
validate:function () {
return true;
}});
Ext.onReady(function () {
Ext.QuickTips.init();
var win = new Ext.Window({
width:500, id:'winid', height:300, layout:'fit', border:false, closable:false, title:'File Upload', items:[
{
xtype:'form', frame:true, labelWidth:100, items:[
{
name:'Title',
xtype:'textfield',
fieldLabel:'Title',
allowBlank:false,
anchor:'100%'
},
{
name:'Attachment',
xtype:'attachment',
fieldLabel:'Attached Files'
}
]
}
], buttons:[
{
text:'Submit', handler:function () {
Ext.getCmp('form').getForm().submit();
}
}
]
});
win.show();
});
Loot at this snippet.
As I said before store was not linked with its grid successfully. And store reloaded default data = [] when onchange event was appearing.
Enjoy! :)
Try without
store.load();
on your onchange handler.
Also, check about store. Has it linked to the store successfully?
Also.. Good practice is implementing nested components and widget on
initComponent
method
Something like
initComponent: function() {
var me = this;
/* ------ */ me.callParent(arguments); }
And use
Ext.apply
y or
Ext.applyIf
for component initialization