I am new to Ext JS and I have tried the Example from the Ext JS docs, but I am unable to get pagination.
I have designed my application using MVC architecture.
Here is my Code:
title : 'Trade Data',
store : 'RamDataStore',
id:'tradedatagrid',
dockedItems:[{
xtype:'pagingtoolbar',
store:'TradeDataStore',
displayInfo:true,
id:'tradepage',
itemId:'tradepage',
displayMsg:'{0}-{1} of {2}',
emptyMsg:'no topics to show',
dock:'bottom'}
],
columns : [
{
xtype : 'gridcolumn',
width : 85,align : 'center',
dataIndex : 'tradeid',
text : 'TradeId'
},
{
xtype : 'gridcolumn',
width : 120,
dataIndex : 'instrumentType',
text : 'InstrumentType'
},
{
xtype : 'gridcolumn',
width : 103, align : 'center',
dataIndex : 'tradeBook',
text : 'TradingBook'
},
{
xtype : 'gridcolumn',
width : 120, align : 'center',
dataIndex : 'otherBook',
text : 'CustomerBook'
},
]
Here my paging tool bar store and my grid store are the same.
Store:
I defined my store with some default properties and I created an instance for the same store in the controller to dynamically bind.
Ext.define('Myapp.store.RamDataStore', {
extend: 'Ext.data.Store',
requires: ['MyApp.model.ram.RamDataModel'],
constructor: function(cfg) {
var me = this;
cfg = cfg || {};
me.callParent([Ext.apply({
storeId: 'tradedata',
autoLoad: false,
pageSize: 4,
model: 'MyApp.model.ram.RamDataModel',
proxy:{
writer:{
type:'json'
},
reader:{
type:'json'
},
enablePaging: true
},
sorters: [{
property: 'tradeid',
direction: 'ASC'
}]
}, cfg)]);
}
});
Model:
Ext.define('MyApp.model.ram.RamDataModel', {
extend : 'Ext.data.Model',
fields : [{
name:'tradeid',
type:'int'
}, {
name : 'tradeBook',
type : 'string'
}, {
name : 'otherBook',
type : 'string'
}, {
name : 'tradeDate',
type : 'auto'
}, {
name : 'tradedDate',
type : 'auto'
}});
Controller:
I wrote a function that will call on button clicks, and I got a JSON result from the server:
data = [{"tradeid":1,"tradingbook":"ram"},{"tradeid:2,"tradingbook":"testbook"}] //(etc)
Here is my controller code:
var datastore = Ext.create('MyApp.store.RamDataStore',{
model:'Myapp.model.ram.RamDataModel',
data:Ext.decode(result,true),
pageSize:4,
start:0,
limit:4,
enablePaging : true,
proxy:{
type:'memory',
reader:{type:'json'},
writer:{type:'json'},
},
listeners:{
beforeload:function(store,operation,eOpts){
store.proxy.data.total=Ext.decode(result,true).length;
//store.proxy.data=Ext.decode(result,true);
}
},
});
Ext.getCmp('tradedatagrid').getDockedComponent('tradepage').bind(datastore);
Ext.getCmp('tradedatagrid').getView().bindStore(datastore);
Ext.getCmp('tradedatagrid').getView().loadMask.hide();
}
});
With this code, I can add data to my grid, but can't add store to my paging tool bar.
Please help on this. If you have any examples, please suggest & I will follow.
Thanks.
You specify the store for paging toolbar as string what means that Store Manager assumes the string is storeId and tries to find the instance of it. But it cannot because the store is probably created later. Also, the store must be same for both the grid and paging toolbar.
You have two options:
declare the store in your controller: stores:['RamDataStore']
create it manually during grid initComponent where you would also create the paging toolbar and assign the store to it.
Related
I have to append a value to the data fetched from the store before rendering it to the grid in ExtJs.
Please guide me on achieving the above mentioned functionality.
Currently the grid is populated in the following manner:
Ext.define("MyApp.view.ShowDetails",{
extend: 'Ext.grid.Panel',
requires:['MyApp.store.MyStore'],
store:'MyStore',
stateId: 'stateGrid',
selType : 'checkboxmodel',
selModel : {
mode : 'MULTI'
},
plugins : [Ext.create('Ext.grid.plugin.RowEditing', {
clicksToEdit : 2
})],
defaultType: 'textfield',
columns: [
{
header: 'Userid',
width: 150,
dataIndex: 'uid',
editor :
{
allowBlank : true
}
},
...
Yes this is possible,using the convert property in field declaration in MODEL
An Example:
{
name: 'uid',
type: 'string',
convert: function (value, record) {
if (!value)
return value+'D';
else
return value;
}
},
I am using Bancha basic version for my site. I want to show data from emplyees table to grid using Ext JS.
Following is the code for controller:
class EmployeesController extends AppController {
/**
* #banchaRemotable
*/
public function getData(){
return $this->Employee->find('all');
}
}
Following is my JavaScript file:
Ext.application({
name: 'BanchaExample',
launch: function() {
/**
* Example 1
* Create a grid panel which provides full CRUD support
*/
Bancha.getStub('Employee').index(function(result){
Ext.define('Employee', {
extend: 'Ext.data.Model',
fields: [ 'id', 'name' ]
});
var myStore = Ext.create('Ext.data.Store', {
model: 'Employee',
data: result.data
});
Ext.create('Ext.grid.Panel', {
renderTo: Ext.getBody(),
model: 'Employee',
width: 400,
height: 200,
title: 'Application Users',
//scaffold: 'MyApp.model.User'
columns: [
{
header: 'id',
width: 100,
ryinsortable: false,
hideable: false,
dataIndex: 'id'
},
{
header: 'name',
width: 150,
dataIndex: 'name'
}
]
});
});
}
});
It gives me following response in my console:
[{"type":"rpc","tid":1,"action":"Employee","method":"read","result":{"success":true,"data":[{"Employee":{"id":"1","name":"test"}},{"Employee":{"id":"2","name":"tese"}}],"message":"Expected the response to be multiple Employee records, but some records were missing data, so did not convert data into Ext JS/Sencha Touch structure."}}]
Only grid with header is displayed. Data is not displayed.
Please help me to solve this.
I don't work with Bancha, but may be this will help.
I don't see any grid connection with store. Also store need some config(reader) to parse your result. 'data' is normally used for inline static data.
Ext.define('Employee', {
extend : 'Ext.data.Model',
fields : [ {
name : 'id',
mapping : 'Employee.id'
}, {
name : 'name',
mapping : 'Employee.name'
} ]
});
var myStore = Ext.create('Ext.data.Store', {
model : 'Employee',
proxy : {
url : 'SPECIFY URL TO YOUR SERVICE',
type : 'ajax',
reader : {
type : 'json',
root : 'result.data'
}
}
});
also add store to grid and you can remove model in grid
Ext.create('Ext.grid.Panel', {
renderTo: Ext.getBody(),
store : myStore,
...
});
Bancha Basic does not automatically transform records from the CakePHP structure to Ext JS. For what you want to do you need to use Bancha Pro.
If you want to use Bancha Basic you need to return a correct Ext JS data array.
i am trying to create a panel where i can traverse the contact details from phonegap back and forth. so far i have successfully fetched the contact details from phonegap and storing it into an array and loading into Ext.Store. but how would i move to next record until the last one , as there are so many records.
following is the image that i want to implement
You have everything you need to implement that contact view screen, only thing is you need to try.
You can even more optimize my code and don't copy past the code, just try to get idea from the code.
I can explain this code to you but you will understand better when you explore your own.
1) Basically, I created contactView panel with two butons and detail panel.
2) Detail panel have a panel for showing image and label for showing details.
3) I am controlling contact navigation using next and back button in controller.
Model
Ext.define('ContactApp.model.Contact', {
extend: 'Ext.data.Model',
config: {
fields: [
{name: 'name', type: 'string'},
{name: 'mobileNumber', type: 'string'},
{name: 'emailid', type: 'string'},
{name: 'picture', type: 'string'}
]
}
});
Store
Ext.define('ContactApp.store.Contact',{
extend : 'Ext.data.Store',
config : {
model: "ContactApp.model.Contact",
storeId : 'contact',
data : [
{ name:'Anantha', mobileNumber:'9845633215', emailid: 'anantha#gmail.com', picture: 'resources/images/pic.jpg'},
{ name:'Viswa', mobileNumber:'9876543218', emailid: 'viswa#gmail.com', picture: 'resources/images/pic1.jpg'},
{ name:'Aravind', mobileNumber:'9878963213', emailid: 'aravind#gmail.com', picture: 'resources/images/pic2.jpg'},
{ name:'Ramesh', mobileNumber:'9877856321', emailid: 'ramesh#gmail.com', picture: 'resources/images/pic3.jpg'}
],
autoLoad: true
}
});
View
Ext.define('ContactApp.view.Contact',{
extend : 'Ext.Panel',
xtype : 'contactView',
config : {
items : [{
xtype : 'titlebar',
title : 'Contacts',
items : [{
ui: 'back', text: 'back', align : 'left', action: 'back', hidden: true
},{
ui: 'forward', text: 'next', align : 'right', action: 'next', hidden: true
}]
},{
xtype : 'panel',
itemId : 'contactDetail',
layout : 'hbox',
style : 'margin-left: 15%; margin-top:10%;',
items : [{
xtype : 'panel',
itemId : 'picture',
tpl : '<img src="{picture}" alt="picture" height= "64" width= "64">'
},{
xtype: 'spacer',
width : 40
},{
xtype : 'label',
itemId : 'details',
tpl : '<div>{name}</div><div>{mobileNumber}</div><div>{emailid}</div>'
}]
}]
},
initialize : function() {
this.fireEvent('onContactViewInit',this);
}
});
Controller
Ext.define('ContactApp.controller.Contact', {
extend : 'Ext.app.Controller',
config : {
contactCount : 0,
refs : {
contactView : 'contactView',
backBtn : 'button[action=back]',
nextBtn : 'button[action=next]'
},
control : {
contactView : {
onContactViewInit : 'onContactViewInit'
},
backBtn : {
tap : 'onBackTap'
},
nextBtn : {
tap : 'onNextTap'
}
}
},
onContactViewInit : function(){
var contactStore = Ext.getStore('contact');
var count = contactStore.getCount();
if(count){
var index = this.getContactCount();
var record = contactStore.getAt(index);
this.setContact(record.getData());
if(count>1)
this.getNextBtn().show();
}
},
setContact : function(data){
var contactView = this.getContactView();
var contactDetail = contactView.getComponent('contactDetail');
contactDetail.getComponent('picture').setData(data);
contactDetail.getComponent('details').setData(data);
},
onBackTap : function(){
var contactStore = Ext.getStore('contact');
var count = contactStore.getCount();
var index = this.getContactCount();
this.setContactCount(index-1);
var record = contactStore.getAt(index-1);
this.setContact(record.getData());
this.getNextBtn().show();
if(this.getContactCount() == 0)
this.getBackBtn().hide();
},
onNextTap : function(){
var contactStore = Ext.getStore('contact');
var count = contactStore.getCount();
var index = this.getContactCount();
this.setContactCount(index+1);
var record = contactStore.getAt(index+1);
this.setContact(record.getData());
this.getBackBtn().show();
if(this.getContactCount() == count-1)
this.getNextBtn().hide();
}
});
Output
We have four record, so
Record 1
Record 2
Record 3
Record 4
That is what i do, i mean trying.
Hello, I'm developing a project using Ext Js that needs to edit a line in a grid. I'm trying to use a plugin I found in Ext's documentation, plugins: [Ext.create ('Ext.grid.plugin.RowEditing')] but when I click on the line, update and cancel options appear on the grid, but the cell is not editable, does anyone know what's going on?
The example in the documentation with the plugin is this: http://docs.sencha.com/ext-js/4-0/#!/example/restful/restful.html
My code so far:
Ext.define('GridEditavel',{
extend : 'Ext.grid.Panel',
title: 'Grid Editavel',
store: 'GridStore',
dockedItems : [ {
xtype : 'toolbar',
items : [ {
xtype: 'button',
text : i18n['vds.botao.nova.coluna'],
icon : Webapp.icon('add1.png'),
iconAlign : 'top',
handler : function() {
var gridView = Ext.ComponentQuery.query("gridpanel")[1];
Ext.Msg.prompt('Message', 'Enter a column number:', function(
btn, text) {
if (btn == 'ok' && text != null) {
var column = Ext.create('Ext.grid.column.Column', {
text : text
});
gridView.headerCt.insert(gridView.columns.length,
column);
gridView.getView().refresh();
} else {
Ext.Msg.alert('Alert', 'Enter a column number!');
}
});
}
} ]
} ],
columns: [{
header : 'Nome',
dataIndex : 'nome',
flex : 0.8
}],
plugins : [ Ext.create('Ext.grid.plugin.RowEditing') ]});
You need to set the editor property in the columns. Example:
columns:[{
header:'Nome',
dataIndex:'nome',
flex:0.8,
editor:'textfield'
}]
You can also use a config object for the editor, like this:
columns:[{
header:'Nome',
dataIndex:'nome',
flex:0.8,
editor:{
xtype:'combo',
store:'somestore'
}
}]
I am developing an application using ExtJs, one of the features is to edit a record already saved. There is a grid where I select the line that I want to edit, and a panel appears with the information to be edited. But one of the attributes that can be edited is another object of my system, called a configuration, and this configuration has an id, which is loaded when you edit the registry. The problem is that when I click on the icon of the grid that lets you edit, the first time the id is retrieved, the second the id does not appear anymore, and the third time displays the following error:'
Uncaught TypeError: Cannot read property 'id' of undefined Grid.js:36
Ext.define.columns.items.handler Grid.js:36
Ext.define.processEvent
Ext.define.processEvent Table.js:755
fire ext-debug.js:8583
Ext.define.continueFireEvent Observable.js:352
Ext.define.fireEvent Observable.js:323
Ext.override.fireEvent EventBus.js:22
Ext.define.processItemEvent Table.js:844
Ext.define.processUIEvent View.js:475
Ext.define.handleEvent View.js:404
(anonymous function)
Ext.apply.createListenerWrap.wrap
My code is (when I click edit icon):
icon : Webapp.icon('editar.png'),
tooltip : 'Editar',
handler: function(view, rowIndex, colIndex, item, e) {
var record = Ext.getStore('EstacaoStore').getAt(rowIndex);
var form = Ext.create('PanelNovaEstacao');
record.set('modoIgnorar', record.data.modoIgnorar);
record.set('latitude', record.data.latitude);
record.set('longitude', record.data.longitude);
record.set('reiniciar', record.data.reiniciar);
record.set('configuracaoCombo', record.data.configuracao.id);
record.set('ativar', record.data.ativar);
record.set('tipoColetor', record.data.tipoColetor);
form.loadRecord(record);
Ext.create('Ext.window.Window', {
title : 'Cadastro',
layout : 'fit',
modal : true,
width : 500,
height : 350,
items : [ form ]
}).show();
And 'PanelNovaEstacao' code is:
Ext.define('PanelNovaEstacao', {
extend : 'Ext.form.Panel',
title : 'Painel',
initComponent : function() {
var combo = Ext.create('ComboBoxConfiguration', {
name : 'configuracao'
});
Ext.apply(this, {
bodyPadding : '10 0 0 10',
items : [ {
xtype : 'hiddenfield',
name : 'id'
}, {
xtype : 'hiddenfield',
name : 'numeroSerieAntigo'
}, {
xtype : 'numberfield',
fieldLabel : 'Número de série',
name : 'numeroSerie',
minValue : 0,
allowBlank : false
}, combo
{
xtype: 'numberfield',
fieldLabel: 'Latitude',
name: 'latitude'
}, {
xtype: 'numberfield',
fieldLabel: 'Longitude',
name: 'longitude'
},{
xtype: 'radiogroup',
fieldLabel : 'Estado',
items : [ {
boxLabel : 'Ativo',
inputValue : true,
checked: true,
name : 'ativar'
}, {
boxLabel : 'Inativo',
inputValue : false,
name : 'ativar'
} ]
}, {
xtype : 'checkbox',
fieldLabel : 'Modo ignorar',
name : 'modoIgnorar'
}, {
xtype : 'checkbox',
fieldLabel : 'Reiniciar',
name : 'reiniciar'
}, {
xtype : 'button',
text : 'Salvar',
textAlign : 'center',
action : 'salvar'
} ]
});
this.callParent(arguments);
}
});
ComBoxConfiguration code:
Ext.define('ComboBoxConfiguration', {
extend : 'Ext.form.ComboBox',
store : 'ConfiguracaoStore',
fieldLabel : 'Configurações',
displayField : 'id'
});
Anyone know what might be happening ??
Thanks!
This line is likely causing the issue: record.set('configuracaoCombo', record.data.configuracao.id);
The data that is coming back from the proxy does not have a configuracao property, so accessing it evaluates to undefined, at which point trying to access the sub-property id will lead to the error you are seeing.
Take a look at the data in the EstacaoStore and what's being returned by the store's proxy (or however you load it). You'll likely find a problem there.
When I click in line and run the code:
var record = Ext.getStore('EstacaoStore').getAt(rowIndex);
console.log(record);
The object that return is: (configuracao is synonymous to configuracaoEstacao)