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
Related
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
In the below ExtJS 4.2.2 code, you can click repeatedly on the "Search" and "Show Label" controls, and the label "here is the text" will toggle visible/hidden.
But if you click in the search text input field, the label is only hidden the first time you click there. If you then click "Show Label" to once again display the label, and then again click the search text input field, the label if not hidden.
Ext.define('MyToolbar', {
extend: 'Ext.grid.feature.Feature',
alias: 'feature.myToolbar',
requires: ['Ext.grid.feature.Feature'],
width: 160,
init: function () {
if (this.grid.rendered)
this.onRender();
else{
this.grid.on('render', this.onRender, this);
}
},
onRender: function () {
var panel = this.toolbarContainer || this.grid;
var tb = panel.getDockedItems('toolbar[dock="top"]');
if (tb.length > 0)
tb = tb[0];
else {
tb = Ext.create('Ext.toolbar.Toolbar', {dock: 'top'});
panel.addDocked(tb);
}
this.createSearchBox(tb);
},
createSearchBox: function (tb) {
tb.add({
text: 'Search',
menu: Ext.create('Ext.menu.Menu'),
listeners: {
click: function(comp) {
MyApp.app.fireEvent('onGridToolbarControlClicked', comp);
}
}
});
this.field = Ext.create('Ext.form.field.Trigger', {
width: this.width,
triggerCls: 'x-form-clear-trigger',
onTriggerClick: Ext.bind(this.onTriggerClear, this)
});
this.field.on('render', function (searchField) {
this.field.inputEl.on('click', function() {
MyApp.app.fireEvent('onGridToolbarControlClicked', searchField);
}, this, {single: true});
}, this, {single: true});
tb.add(this.field);
}
});
Ext.define('MyPage', {
extend: 'Ext.container.Container',
alias: 'widget.myPage',
flex: 1,
initComponent: function () {
var me = this;
Ext.applyIf(me, {
items: [{
xtype: 'container',
layout: {
type: 'vbox',
align: 'middle'
},
items: [{
xtype: 'button',
text: 'Show Label',
handler: function(comp) {
comp.up('myPage').down('label').setVisible(true);
}
},{
xtype: 'label',
itemId: 'testLbl',
text: 'here is the text'
},{
xtype: 'gridpanel',
width: 250,
height: 150,
store: Ext.create('Ext.data.Store', {
fields: ['name'],
data: [
{name: 'one'},
{name: 'two'},
{name: 'three'}
]
}),
columns: [{
text: 'Text',
flex: 1,
dataIndex: 'name'
}],
features: [{
ftype: 'myToolbar'
}]
}]
}]
});
me.callParent(arguments);
MyApp.app.on({onGridToolbarControlClicked: function(comp) {
if('function' == typeof comp.up && !Ext.isEmpty(comp.up('myPage')) &&
'function' == typeof comp.up('myPage').down &&
!Ext.isEmpty(comp.up('myPage').down('label'))) {
comp.up('myPage').down('label').setVisible(false);
}
}});
}
});
Ext.onReady(function() {
Ext.application({
name: 'MyApp',
launch: function() {
Ext.create('Ext.container.Viewport', {
renderTo: Ext.getBody(),
width: 700,
height: 500,
layout: 'fit',
items: [{
xtype: 'myPage'
}]
});
}
});
});
Here
this.field.inputEl.on('click', function() {
MyApp.app.fireEvent('onGridToolbarControlClicked', searchField);
}, this, {single: false});
instead of {single:true} in your code. onRender IS single, onClick - (in your case) is not.
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]);
}
}
}
]
});
I am trying to add rows to my grid.
I saw an example in the docs:
onAddRouteClick: function(){
// Create a model instance
var rec = new KitchenSink.model.grid.Plant({
buying_vendor_id: 12,
country_code: '1',
route: 0
});
this.getStore().insert(0, rec);
this.cellEditing.startEditByPosition({
row: 0,
column: 0
});
}
this.getStore().insert(0, rec);
this.cellEditing.startEditByPosition({
row: 0,
column: 0
});
}
But i cant seem to make it work in my code.
This is my grid:
onBtnRoutesSearchClick: function(button, e, options){
var me = this;
var v_url = 'GetRoutes.jsp?' + Ext.urlEncode({'route_id': routeID, 'route_country_code' : routeCountryCode , 'route_vendor_id' : routeVendorID});
var newTab = Ext.create('Ext.panel.Panel', {
id: 'routes_pannel',
title: 'Routes',
autoScroll: true,
layout: {
type: 'fit'
},
closable: true,
dockedItems: [
{
xtype: 'toolbar',
dock: 'top',
items: [
{
xtype: 'button',
id: 'buttonResetBid',
icon: 'images/Plus.png',
text: 'Add Row',
listeners: {
click: {
fn: me.onAddRouteClick,
scope: me
}
}
}
]
}
],
items: [{
id: 'routes_grid',
xtype: 'gridpanel',
autoShow: false,
autoScroll: true,
store: Ext.create('Ext.data.Store', {
fields:[
{name: 'buying_vendor_id', type: 'int', sortType: 'asInt'},
{name: 'country_code', type: 'int', sortType: 'asInt'},
{name: 'route', type: 'int', sortType: 'asInt'}
],
proxy: {
type: 'ajax',
timeout: 120000,
url: v_url,
reader: {
type: 'json',
root: 'data',
successProperty: 'success'
}
},
autoLoad: true
}),
columns: [
{
xtype: 'gridcolumn',
dataIndex: 'buying_vendor_id',
width: 100,
text: 'Buying Vendor'
},
{
xtype: 'gridcolumn',
dataIndex: 'country_code',
width: 100,
text: 'Country Code'
},
{
xtype: 'gridcolumn',
dataIndex: 'route',
width: 80,
text: 'Route'
}
],
}]
});
var panel = Ext.getCmp("MainTabPanelID");
panel.add(newTab).show();
1.Create your model
Ext.define('Product', {
extend: 'Ext.data.Model',
fields:
[
{ name: 'ProductID' },
{ name: 'ProductName' },
{ name: 'UnitPrice' },
{ name: 'UnitsInStock' }
]
});
2.create your rowEditing
var rEditor = Ext.create('Ext.grid.plugin.RowEditing', {
clicksToEdit: 2,
listeners:
{
edit: function (editor, e) { });
}
});
3.get Store and create your grid
var grid = Ext.create('Ext.grid.Panel', {
store: store,
plugins: [rEditor],
title: 'Products',
columns:
[
],
dockedItems:
[
{
xtype: 'toolbar',
dock: 'top',
items:
[
{
xtype: 'button',
text: 'Yeni',
listeners:
{
click:
{
fn: function () {
store.insert(0, new Product());
rEditor.startEdit(0, 0);
}
}
}
}
]
}
],
width: 450,
renderTo: Ext.getElementById('hede')
});
So you are trying to add a record to store right?
OK, lets look at the Store API
http://docs.sencha.com/extjs/4.1.3/#!/api/Ext.data.Store-method-add
Sample usage:
myStore.add({some: 'data'}, {some: 'other data'});
The best practice is to also create a Model class . Read the component guides on grid and the data package .
I am using extjs 4.1 .I have a grid that is showing date in desired time format. But when I want to show the date and intime and outtime in a window for edit then only date is displaying. but intime and outtime is not displaying. All the fields in database are datetime. Can anyone please help me on this. Here is my code below :
my grid is like below :
Ext.define('Ext4Example.view.attendence.Datagrid' ,{
extend: 'Ext.grid.Panel',
alias : 'widget.datagrid',
layout: 'fit',
border: true,
viewConfig: {
stripeRows: true,
forceFit:true,
emptyText:'No Records to display'
},
hideHeaders: false,
initComponent: function() {
this.store = 'Attendences';
//this.width = 400;
this.columns = [
{
text: 'Date',
dataIndex: 'id',
renderer: function(value, metaData){
return Ext.Date.format(value, 'M d, Y');
}
},{
text: 'Day',
dataIndex : 'id',
renderer: function(value, metaData){
return Ext.Date.format(value, ' l');
}
},
{
text: 'In-Time',
dataIndex: 'intime',
renderer: function(value, metaData){
return Ext.Date.format(value, 'h:i A');
}
},
{
text: 'Out-Time',
dataIndex: 'outtime',
renderer: function(value, metaData){
return Ext.Date.format(value, 'h:i A');
}
}
];
this.callParent(arguments);
}
});
And the window is given below where i want the values for edit :
Ext.define('Ext4Example.view.attendence.Editattendence' ,{
extend: 'Ext.window.Window',
alias : 'widget.editattendence',
title: 'Edit Attendence',
layout: 'fit',
autoShow: true,
initComponent: function () {
this.items = [
{
xtype: 'form',
bodyStyle: {
background: 'none',
padding: '10px',
border: '0'
},
items: [
{
xtype: 'datefield',
name: 'id',
allowBlank: false,
fieldLabel: 'Attendene ID'
},
{
xtype: 'numberfield',
name: 'intime',
allowBlank: false,
fieldLabel: 'IN TIME',
renderer: function(value, metaData){
return Ext.Date.format(value, 'h:i A');
}
},{
xtype: 'numberfield',
fieldLabel: 'OUT TIME',
name: 'outtime',
renderer: function(value, metaData){
return Ext.Date.format(value, 'h:i A');
}
}
]
}
];
this.buttons = [
{
text: 'Save',
action: 'save'
},
{
text: 'Cancel',
scope: this,
handler: this.close
}
];
this.callParent(arguments);
}
});
And the controller where I am calling this window on double click in grid row is given below :
Ext.define('Ext4Example.controller.Attendences', {
extend: 'Ext.app.Controller',
stores: [
'Attendences','Months'
],
models: [
'Attendence','Month'
],
views: [
'attendence.Timeperiod','attendence.Details','attendence.Attendencewindow','attendence.Editattendence','attendence.Datagrid' //'attendence.Months'
],
refs: [{
ref: 'stockaddForm',
selector: 'form'
}],
init: function () {
this.control({
'datagrid': {
itemdblclick: this.editUser,
viewready: this.attnready
},
'attendencewindow button[action=save]': {
click: this.save
}
});
},
editUser: function(grid, record){
var view = Ext.widget('editattendence');
view.down('form').loadRecord(record);
},
save: function(){
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear(); //+1
Ext.Msg.alert("Today is - ",dd+" - "+mm+" - "+yyyy);
},
attnready: function(grid, eOpts) {
console.log('hello');
var store = grid.getStore(),
selModel = grid.getSelectionModel();
if (store.getAt(0)) {
selModel.select(0);
}
}
});
Hey I have solve this problem. Just a little bit of change in the editAttendence form as follows :
Ext.define('Ext4Example.view.attendence.Editattendence' ,{
extend: 'Ext.window.Window',
alias : 'widget.editattendence',
title: 'Edit Attendence',
layout: 'fit',
autoShow: true,
initComponent: function () {
this.items = [
{
xtype: 'form',
bodyStyle: {
background: 'none',
padding: '10px',
border: '0'
},
items: [
{
xtype: 'datefield',
name: 'id',
allowBlank: false,
fieldLabel: 'Attendene ID'
},
{
xtype: 'datefield',
format:'h:i A',
name: 'intime',
allowBlank: false,
fieldLabel: 'IN TIME'
},{
xtype: 'datefield',
format:'h:i A',
fieldLabel: 'OUT TIME',
allowBlank: false,
name: 'outtime'
}
]
}
];
this.buttons = [
{
text: 'Save',
action: 'save'
},
{
text: 'Cancel',
scope: this,
handler: this.close
}
];
this.callParent(arguments);
}
});