Use MVC to manage grid column events - extjs

I have a grid with some columns(combobox columns) which I need to manage their change events. I want to do it from a controller. The goal is to send the server the selected combo id when i need to insert or update the row and update the other columns depending of the value of this selected combo. Could you give me an example how I much do this?
I have 2 hidden columns which must be updated when the Combo Empresa and Camion changes with the id.
This is my grid def:
{
xtype: 'gridpanel',
id: 'grdListaFichaEmbarques',
minWidth: 1024,
autoScroll: true,
title: 'Listado de Fichas',
store: 'ListaFichasTransporte',
plugins: [
Ext.create('Ext.grid.plugin.RowEditing', {
pluginId: 'ListaFEPlugin'
})
],
columns: [
{
xtype: 'numbercolumn',
dataIndex: 'NumEmbarque',
text: 'NumEmbarque'
},
{
xtype: 'gridcolumn',
dataIndex: 'Empresa',
text: 'Empresa',
editor: {
xtype: 'combobox',
allowBlank: false,
displayField: 'Nombre',
hiddenName: 'Id',
store: 'ListaEmpresa',
valueField: 'Id'
}
},
{
xtype: 'gridcolumn',
dataIndex: 'Contacto',
text: 'Contacto'
},
{
xtype: 'gridcolumn',
dataIndex: 'Celular',
text: 'Celular'
},
{
xtype: 'gridcolumn',
dataIndex: 'Placa1',
text: 'Placa1',
editor: {
xtype: 'combobox',
allowBlank: false,
displayField: 'Placa1',
store: 'ListaCamiones',
valueField: 'Id'
}
},
{
xtype: 'gridcolumn',
dataIndex: 'Placa2',
text: 'Placa2'
},
{
xtype: 'gridcolumn',
dataIndex: 'Capacidad',
text: 'Capacidad'
},
{
xtype: 'gridcolumn',
dataIndex: 'Chofer',
text: 'Chofer'
},
{
xtype: 'gridcolumn',
dataIndex: 'Nextel',
text: 'Nextel'
},
{
xtype: 'gridcolumn',
dataIndex: 'CelularPeru',
text: 'CelularPeru'
},
{
xtype: 'gridcolumn',
dataIndex: 'CelularEcuador',
text: 'CelularEcuador'
},
{
xtype: 'gridcolumn',
dataIndex: 'Termoregistro1',
text: 'Termoregistro1'
},
{
xtype: 'gridcolumn',
dataIndex: 'Termoregistro2',
text: 'Termoregistro2'
},
{
xtype: 'gridcolumn',
dataIndex: 'PuntoRecojo',
text: 'PuntoRecojo',
editor: {
xtype: 'combobox',
displayField: 'Nombre',
store: 'ListaOrigenDestino',
valueField: 'Id'
}
},
{
xtype: 'datecolumn',
dataIndex: 'FechaHoraLlegadaOrigen',
text: 'FechaHoraLlegadaOrigen',
editor: {
xtype: 'datefield',
format: 'd/m/Y h:i:s',
submitFormat: 'd/m/Y h:i:s'
}
},
{
xtype: 'datecolumn',
dataIndex: 'FechaHoraDespachoOrigen',
text: 'FechaHoraDespachoOrigen',
editor: {
xtype: 'datefield',
format: 'd/m/Y h:i:s',
submitFormat: 'd/m/Y h:i:s'
}
},
{
xtype: 'datecolumn',
dataIndex: 'FechaHoraLlegadaTumbes',
text: 'FechaHoraLlegadaTumbes',
editor: {
xtype: 'datefield',
format: 'd/m/Y h:i:s',
submitFormat: 'd/m/Y h:i:s'
}
},
{
xtype: 'gridcolumn',
dataIndex: 'PuntoLlegadaEcuador',
text: 'PuntoLlegadaEcuador',
editor: {
xtype: 'combobox',
displayField: 'Nombre',
store: 'ListaOrigenDestino',
valueField: 'Id'
}
},
{
xtype: 'datecolumn',
dataIndex: 'FechaHoraLLegadaDestinoEcuador',
text: 'FechaHoraLLegadaDestinoEcuador',
editor: {
xtype: 'datefield',
format: 'd/m/Y h:i:s',
submitFormat: 'd/m/Y h:i:s'
}
},
{
xtype: 'numbercolumn',
hidden: true,
dataIndex: 'IdEmpresa',
text: 'IdEmpresa'
},
{
xtype: 'numbercolumn',
hidden: true,
dataIndex: 'IdCamion',
text: 'IdCamion'
}
]
}
This is my Controller:
Ext.define('Fplweb2.controller.FichaEmbarque', {
extend: 'Ext.app.Controller',
refs: [
{
ref: 'GrillaFE',
selector: 'grid[id=grdListaFichaEmbarques]',
xtype: 'Ext.grid.Panel'
}
],
onButtonClick: function(button, e, eOpts) {
this.save();
},
onComboboxSelect: function(combo, records, eOpts) {
var grid = this.getGrillaFE();
var store = grid.getStore();
//HERE I WAS TRYING TO UPDATE THE COLUMNS
if( grid.getSelectionModel().hasSelection() )
{
var row = grid.getSelectionModel().getSelection();
var srow;
for(var i=0; i<store.count(); i++)
{
srow = store.getAt(i);
if(srow.get('NumEmbarque') == row[0].data.NumEmbarque)
{
console.log("ASIGNARA");
srow.IdEmpresa = records[0].data.Id;
srow.Contacto = records[0].data.Contacto;
srow.Celular = records[0].data.Celular;
}
}
}
},
init: function(application) {
this.listen({
controller: {},
component: {
'grid[xtype=gridpanel]': {
edit: this.save,
canceledit: this.cancel
}
});
this.control({
"button[id=btnFichaEmbarqueAgregar]": {
click: this.onButtonClick
},
"combobox[id=cmbGrdListaFichaEmbarquesEmpresa]": {
select: this.onComboboxSelect
}
});
},
save: function() {
var fechaact = new Date();
var grid = this.getGrillaFE();
var plugin = grid.editingPlugin;
var store = grid.getStore();
//SET THE FIRTS COMBO VALUE
//Combo Lista Empresas
var lestore = Ext.data.StoreManager.lookup('ListaEmpresa').getAt(0).get('Nombre');
//Combo Lista Origen - Destino
var odstore = Ext.data.StoreManager.lookup('ListaOrigenDestino').getAt(0).get('Nombre');
//Combo Lista Camiones
var lcstore = Ext.data.StoreManager.lookup('ListaCamiones').getAt(0).get('Placa1');
plugin.cancelEdit();
var r = Ext.create('Fplweb2.model.ListaFichasTransporte', {
NumEmbarque: store.getCount() + 1,
Empresa: lestore,
Contacto: 'Nuevo Contacto',
Celular: '999999999',
Placa1: lcstore,
Placa2: '',
Capacidad: '',
Chofer: 'Nuevo Chofer',
Nextel: '999999999',
CelularPeru: '999999999',
CelularEcuador: '999999999',
Termoregistro1: '',
Termoregistro2: '',
PuntoRecojo: odstore,
FHTranspPuntoRecojo: fechaact,
FHDespaPuntoRecojo: fechaact,
FHLlegadaTumbes: fechaact,
PuntoLlegadaEcuador: odstore,
FHLlegadaPuntoEcuador: fechaact
});
store.insert(0, r);
plugin.startEdit(0, 0);
store.sync();
},
cancel: function(editor, context, eOpts) {
console.log("cancelo");
var grid = this.getGrillaFE();
var plugin = grid.editingPlugin;
var store = grid.getStore();
plugin.cancelEdit();
store.removeAt(0);
if( context.record.phantom ) {
context.store.remove( context.record );
}
}
});
I want to do this FROM a controller.
Thanks in advance...

You need to catch the edit event of the grid (added by the editing plugin):
listeners: {
edit: function(editor, e) {
if (e.field === 'Empresa') {
// do a trip to the server if needed
// or update your column locally
e.record.set('IdCamion', e.value);
}
}
}

Related

Height specified is not the real one on extjs

Hi guys i need help with grid panel, I set the height of the grid to 200px and when I see the grid on the browser it has 600px. I tried to force height with setHeight(), but didn't work.
The code for the grid panel is the next:
for(var i=0; i<json.length;++i){
var data = JSON.parse(json[i].json);
var store = Ext.create('Ext.data.Store', {
fields: ['question', 'type', 'answer'],
data: data.questions
});
var rEditor = Ext.create('Ext.grid.plugin.RowEditing', {
clicksToEdit: 2,
listeners:{
edit: function (editor, e) { }
}
});
var itemId ="";
if(json[i].enabled){
act++;
itemId = 'active'+act;
}else{
inact++
itemId = 'inactive'+inact;
}
var grid = Ext.create('Ext.grid.Panel', {
height: 200,
margin: '20 35 0 35',
title: 'Group of Questions',
store: store,
plugins: [rEditor],
itemId: itemId,
stateId: itemId,
columns: [
{xtype: 'rownumberer', stateId: itemId+'_1', width:30},
{ text: 'Question', dataIndex: 'question', stateId: itemId+'_2', tdCls: 'gridTree', flex: 1, editor: {xtype: 'textfield'}},
{ text: 'Type', dataIndex: 'type', stateId: itemId+'_3', tdCls: 'gridTree', flex: 1, editor: {xtype: 'combobox', fieldLabel: 'Choose Type', store: types,queryMode: 'local', valueField: 'name',tpl: Ext.create('Ext.XTemplate','<tpl for=".">','<div class="x-boundlist-item">{name}</div>','</tpl>'), displayTpl: Ext.create('Ext.XTemplate','<tpl for=".">','{name}','</tpl>')}},
{ text: 'Answer', dataIndex: 'answer', stateId: itemId+'_4', tdCls: 'gridTree', flex: 1, editor: {xtype: 'textfield', store: types, }}
],
dockedItems: [
{
xtype: 'toolbar',
dock: 'top',
items: [
{
xtype: 'button',
scale: 'medium',
glyph: Rd.config.icnLight,
listeners: {
click: {
fn: function(){
Ext.Ajax.request({
url: '',
method: 'POST',
params: {
country: country,
language: language,
realm_id: realm_id,
},
});
}
}
}
},
]
}
],
});
if(json[i].enabled){
active.add(grid);
actives.push(grid);
}else{
inactive.add(grid);
inactives.push(grid);
}
}
I forget to say that in the same container i can have more than one grid panel. I don't know if this is possible. Can you guys tell me please.

Passing arguments to Listener

I have a button:
var me = this;
...
var argumentToPass;
...
{
xtype: 'button',
text: 'text',
listeners: {
click: {
fn: me.onBtnAddToBidClick,
scope: me
}
}
}
...
me has a refferance to the argumentToPass.
And the Listerner:
onBtnAddToBidClick: function(button, e, options){
alert(argumentToPass)
}
Basicly i am trying to make a simple function(String var) method.
How can i get the scope from inside the Listener(onBtnAddToBidClick)
EDIT: Thsi is most of my code:
Ext.require([
'Ext.grid.*',
'Ext.data.*',
'Ext.selection.CheckboxModel'
]);
var sm = Ext.create('Ext.selection.CheckboxModel');
Ext.define('MyApp.view.MyViewport', {
extend: 'Ext.container.Viewport',
layout: {
type: 'border'
},
initComponent: function() {
var me = this;
Ext.applyIf(me, {
items: [
{
xtype: 'panel',
region: 'west',
id: 'MenuPanelID',
width: 255,
layout: {
type: 'accordion'
},
collapsed: true,
collapsible: true,
title: 'תפריט',
items: [
{
xtype: 'form',
width: 148,
layout: {
align: 'stretch',
type: 'vbox'
},
collapsed: false,
title: 'מחירונים',
dockedItems: [
{
xtype: 'textfield',
flex: 1,
dock: 'top',
id: 'txtPrefixID',
margin: 10,
fieldLabel: 'Prefix',
labelWidth: 50
},
{
xtype: 'button',
flex: 1,
dock: 'top',
margin: 10,
text: 'חפש',
listeners: {
click: {
fn: me.onBtnPrefixSearchClick,
scope: me,
arg: 0
}
}
},
{
xtype: 'button',
flex: 1,
dock: 'top',
margin: 10,
text: 'חפש טווח',
listeners: {
click: {
fn: me.onBtnPrefixSearchClick,
scope: me,
arg: 1
}
}
}
]
}
]
},
{
xtype: 'tabpanel',
region: 'center',
id: 'MainTabPanelID',
activeTab: 0,
items: [
{
xtype: 'panel',
layout: {
type: 'border'
},
title: 'General',
items: [
{
xtype: 'container',
region: 'center',
layout: {
align: 'stretch',
type: 'vbox'
},
items: [
{
xtype: 'gridpanel',
flex: 1,
autoScroll: true,
title: 'שיחות נכנסות',
store: 'IncomingDataStore',
viewConfig: {
id: 'IncomingGridId'
},
columns: [
{
xtype: 'gridcolumn',
dataIndex: 'trunk_owner',
text: 'Owner'
},
{
xtype: 'gridcolumn',
dataIndex: 'country_name',
text: 'Country'
},
{
xtype: 'gridcolumn',
dataIndex: 'country_code',
text: 'Code'
},
{
xtype: 'numbercolumn',
align: 'right',
dataIndex: 'operator_prefix',
text: 'Operator Prefix',
format: '00'
},
{
xtype: 'numbercolumn',
align: 'right',
dataIndex: 'call_duration',
text: 'Duration Hourly'
},
{
xtype: 'numbercolumn',
align: 'right',
dataIndex: 'acd',
text: 'ACD Hourly'
},
{
xtype: 'numbercolumn',
align: 'right',
dataIndex: 'asr',
text: 'ASR Hourly'
},
{
xtype: 'numbercolumn',
align: 'right',
dataIndex: 'calls',
text: 'Calls Hourly',
format: '0,000'
}
],
listeners: {
celldblclick: {
fn: me.onIncomingGridpanelCellDblClick,
scope: me
}
}
}
]
}
]
}
]
}
]
});
me.callParent(arguments);
},
onBtnPrefixSearchClick: function(arg) {
var checkBoxPrefixes = Ext.create('Ext.selection.CheckboxModel');
var val = Ext.getCmp('txtPrefixID').value;
var v_url = 'GetCountryPrefixes.jsp?' + Ext.urlEncode({'prefix': val, 'action': 'search_exact'});
alert(arg);
if arg === 0 {
// do something...
}
var me = this;
var newTab = Ext.create('Ext.panel.Panel', {
id: 'prefix_panel',
title: 'Price Usage Report',
autoScroll: true,
layout: {
type: 'fit'
},
closable: true,
dockedItems: [
{
xtype: 'toolbar',
dock: 'top',
items: [
{
xtype: 'button',
id: 'buttonBiding',
icon: 'images/dollar16x16.png',
text: 'הוסף להצעת מחיר',
listeners: {
click: {
fn: me.onBtnAddToBidClick,
scope: me
}
}
}
]
}
],
items: [{
id: 'prefix_grid',
xtype: 'gridpanel',
autoShow: false,
autoScroll: true,
selModel: checkBoxPrefixes,
store: Ext.create('Ext.data.Store', {
fields: [
{name: 'price_date'}, //, type: 'Date' , sortType: 'asDate', format: 'Y-m-d h:M:s'
{name: 'country_code',type: 'int', sortType: 'asInt'},
{name: 'prefix',type: 'int', sortType: 'asInt'},
{name: 'vendor_name'},
{name: 'rate', type: 'float', sortType: 'asFloat'},
{name: 'currency'},
{name: 'quality', type: 'int', sortType: 'asInt'},
{name: 'duration',type: 'int', sortType: 'asInt'},
{name: 'acd', type: 'float', sortType: 'asFloat'}
],
proxy: {
type: 'ajax',
timeout: 120000,
url: v_url,
reader: {
type: 'json',
root: 'data',
successProperty: 'success'
}
},
autoLoad: true
}),
title: 'Price Reprort for "' + val + '" - Monthly' ,
columns: [
{
xtype: 'gridcolumn',
dataIndex: 'price_date',
width: 80,
text: 'Date',
renderer: Ext.util.Format.dateRenderer('Y-m-d')
},
{
xtype: 'gridcolumn',
dataIndex: 'country_code',
text: 'Counry Code',
width: 80
},
{
xtype: 'gridcolumn',
dataIndex: 'prefix',
text: 'Prefix',
width: 80
},
{
xtype: 'gridcolumn',
dataIndex: 'vendor_name',
width: 100,
text: 'Vendor Name'
},
{
xtype: 'gridcolumn',
dataIndex: 'currency',
width: 100,
text: 'Currency'
},
{
xtype: 'gridcolumn',
dataIndex: 'rate',
width: 50,
text: 'Rate'
},
{
xtype: 'gridcolumn',
dataIndex: 'quality',
width: 50,
text: 'Quality'
},
{
xtype: 'gridcolumn',
dataIndex: 'duration',
width: 100,
text: 'Duration'
},
{
xtype: 'gridcolumn',
dataIndex: 'acd',
width: 100,
text: 'ACD'
}
]
}]
});
var panel = Ext.getCmp("MainTabPanelID");
panel.remove('prefix_panel');
panel.add(newTab).show();
},
You cannot do it because you are not able to modify event args of a defined event.
But you can store the arguments you want to pass into the instance that fires the event or into the scope in which the event callback get executed. In that way you will have access to them either by the first event arg, which is in nearly all situations the instance that fires the event or by the this keyword when you have applied them to the scope.
Simplified example with data stored in callback scope:
fiddle

ExtJs Grid BufferRenderer doesnot display the grid rows

I want to implement grid bufferrenderer in my simple grid panel that shows a list of information using ExtJS 4.2.1. Without using the bufferrenderer plugin, it shows all the data, but when i used this plugin, my grid contains no data.
This is my grid without using the plugin
This is my grid using the plugin
The grid panel's code is:
Ext.define('MyApp.view.MyPanel', {
extend: 'Ext.panel.Panel',
itemId: 'myPanel',
title: '',
requires: ['Ext.grid.plugin.BufferedRenderer'],
initComponent: function() {
var me = this;
Ext.applyIf(me, {
items: [
{
xtype: 'gridpanel',
autoRender: true,
autoShow: true,
itemId: 'gridPanel',
title: 'My Grid Panel',
store: 'MyJsonStore',
columns: [
{
xtype: 'gridcolumn',
dataIndex: 'id',
text: 'Id'
},
{
xtype: 'gridcolumn',
dataIndex: 'firstName',
text: 'FirstName'
},
{
xtype: 'gridcolumn',
dataIndex: 'middleName',
text: 'MiddleName'
},
{
xtype: 'gridcolumn',
dataIndex: 'lastName',
text: 'LastName'
},
{
xtype: 'gridcolumn',
dataIndex: 'age',
text: 'Age'
},
{
xtype: 'gridcolumn',
dataIndex: 'country',
text: 'Country'
},
{
xtype: 'gridcolumn',
dataIndex: 'city',
text: 'City'
},
{
xtype: 'gridcolumn',
dataIndex: 'street',
text: 'Street'
},
{
xtype: 'gridcolumn',
dataIndex: 'mobile',
text: 'Mobile'
},
{
xtype: 'gridcolumn',
dataIndex: 'phone',
text: 'Phone'
},
{
xtype: 'gridcolumn',
dataIndex: 'zip',
text: 'Zip'
}
],
plugins: 'bufferedrenderer'
/*plugins: {
ptype: 'bufferedrenderer',
trailingBufferZone: 20,
leadingBufferZone: 25
}*/
}
]
});
me.callParent(arguments);
}
});
The Store's code is:
Ext.define('MyApp.store.MyJsonStore', {
extend: 'Ext.data.Store',
requires: [
'MyApp.model.GridModel'
],
constructor: function(cfg) {
var me = this;
cfg = cfg || {};
me.callParent([Ext.apply({
autoLoad: true,
model: 'MyApp.model.GridModel',
storeId: 'MyJsonStore',
buffered: true,
clearOnPageLoad: false,
clearRemovedOnLoad: false,
leadingBufferZone: 25,
pageSize: 500,
purgePageCount: 10,
trailingBufferZone: 20,
proxy: {
type: 'ajax',
url: 'data/users.json',
reader: {
type: 'json',
root: 'users',
totalProperty: 'total_user'
}
}
}, cfg)]);
}
});
Can anyone help me with this? Thanks
Setting the height property in grid will fix this issue.
height: 300
Make sure that all panels up to the viewport have their layout set to “fit”. Also, region of the grid should be “center”.
I have not tested, but something like this should work:
var grid = Ext.create('MyApp.view.MyPanel', {
layout: 'fit',
region: 'center'
});
var viewport = Ext.create('Ext.container.Viewport', {
renderTo: Ext.getBody(),
items: [
grid
]
});

How to show the value for edit in a window in time format from grid in extjs 4

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

how do i create a tab in a tabpanel onclick?

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:
};

Resources