ExtJs: data of store isn't shown - javascript

I'm new to ExtJs, tried the getting started and still reach problems quick. Maybe someone can help me with that easy example. I can't visualize the data of the data store. Panel and columns are working fine but no data. Do you find my mistake?
Main.js:
Ext.define('QuickApp.view.main.Main', {
extend: 'Ext.tab.Panel',
xtype: 'tabpanel',
items: [{
title: 'Employee Directory',
xtype: 'grid',
iconCls: 'x-fa fa-users',
store: 'QuickApp.store.Employee', //change here
columns: [{
text: 'First Name',
dataIndex: 'firstName',
flex: 1
}, {
text: 'Last Name',
dataIndex: 'lastName',
flex: 1
}, {
text: 'Phone Number',
dataIndex: 'phoneNumber',
flex: 1
}]
},{
title: 'About Sencha',
iconCls: 'x-fa fa-info-circle'
}]
});
Store:
Ext.define('QuickApp.store.Employee', {
extend: 'Ext.data.Store',
model: 'QuickApp.model.Employee',
data: [{
"firstName": "Jean",
"lastName": "Grey",
"officeLocation": "Lawrence, KS",
"phoneNumber": "(372) 792-6728"
}, {
"firstName": "Phillip",
"lastName": "Fry",
"officeLocation": "Lawrence, KS",
"phoneNumber": "(318) 224-8644"
}, {
"firstName": "Peter",
"lastName": "Quill",
"officeLocation": "Redwood City, CA",
"phoneNumber": "(718) 480-8560"
}]
});
Model:
Ext.define('QuickApp.model.Employee', {
extend: 'Ext.data.Model',
fields: [
{name: 'firstName', type: 'string'},
{name: 'lastName', type: 'string'},
{name: 'officeLocation', type: 'int'},
{name: 'phoneNumber', type: 'string'}
]
});
Thanks!

Related

How can I make texts highlightable in ExtJs?

I'm still finding my way around Extjs, I'm currently displaying text data to a UI like so:
reference: 'agentLogGrid',
store: {
xclass: 'Ext.data.ChainedStore',
source: 'LogViewSource',
},
itemConfig: {
viewModel: true,
},
columns: [{
text: 'Timestamp',
xtype: 'templatecolumn',
tpl: '{timestamp}',
flex: 1,
}, {
text: 'Data',
xtype: 'templatecolumn',
tpl: '{data}',
flex: 1,
}],...
But the texts are not highlightable, that means I can't highlight them and copy, or select and copy. When I mouse over, the pointer sees it as a link, but I can't highlight or select. How do I make just the {data} highlightable?
In classic toolkit you can use enableTextSelection property. Something like this:
Ext.application({
name: 'Fiddle',
launch: function () {
Ext.create('Ext.data.Store', {
storeId: 'employeeStore',
fields: ['firstname', 'lastname', 'seniority', 'department'],
groupField: 'department',
data: [{
firstname: "Michael",
lastname: "Scott",
seniority: 7,
department: "Management"
}, {
firstname: "Dwight",
lastname: "Schrute",
seniority: 2,
department: "Sales"
}, {
firstname: "Jim",
lastname: "Halpert",
seniority: 3,
department: "Sales"
}, {
firstname: "Kevin",
lastname: "Malone",
seniority: 4,
department: "Accounting"
}, {
firstname: "Angela",
lastname: "Martin",
seniority: 5,
department: "Accounting"
}]
});
Ext.create('Ext.grid.Panel', {
title: 'Column Template Demo',
store: Ext.data.StoreManager.lookup('employeeStore'),
columns: [{
text: 'Full Name',
xtype: 'templatecolumn',
tpl: '{firstname} {lastname}',
flex: 1
}, {
text: 'Department (Yrs)',
xtype: 'templatecolumn',
tpl: '{department} ({seniority})'
}],
// USE viewConfig enableTextSelection property
viewConfig: {
enableTextSelection: true
},
height: 200,
width: 300,
renderTo: Ext.getBody()
});
}
});

Ext js paging with local data does not work

I try to enable paging with ExtJs4 grid. Paging toolbar looks like it is working but paging is not enabled in grid.Can you help me about what I am missing?
Ext.onReady(function () {
var i = 1;
Ext.define('User', {
extend: 'Ext.data.Model',
fields: [
{ name: 'id', type: 'int' },
{ name: 'firstName', type: 'string' },
{ name: 'lastName', type: 'string' },
{ name: 'age', type: 'int' },
{ name: 'eyeColor', type: 'string' }
]
});
It looks that the problem is with totalCount but, there is something more.
var store= Ext.create('Ext.data.Store', {
model: 'User',
totalCount:50,
pageSize: 10,
autoLoad: { start: 0, limit: 10 },
proxy: {
type: 'memory',
reader: {
root: 'users',
totalProperty: 'totalCount'
}
},
data: [
{ id: i++, firstName: 'Ed', lastName: 'Spencer', age:20, eyeColor: 'blue' },
{ id: i++, firstName: 'Tommy', lastName: 'Maintz', age: 30, eyeColor: 'black' },
{ id: i++, firstName: 'Aaron', lastName: 'Conran', age: 40, eyeColor: 'blue' },
{ id: i++, firstName: 'Jamie', lastName: 'Avins', age: 50, eyeColor: 'black' },
{ id: i++, firstName: 'Ed', lastName: 'Spencer', age: 20, eyeColor: 'blue' }
.
.
.
]
});
Paging toolbar looks like it is working but grid values does not change according to the page numbers.
Ext.create('Ext.grid.Panel', {
title: 'Users',
store: store,
proxy: {
type: 'memory',
enablePaging: true
},
columns: [
{ header: 'ID', dataIndex: 'id', width:50 },
{ header: 'Name', dataIndex: 'firstName' },
{ header: 'Last Name', dataIndex: 'lastName' },
{ header: 'Age', dataIndex: 'age', width: 50 },
{ header: 'Eye Color', dataIndex: 'eyeColor' }
],
height: 600,
width: 800,
dockedItems: [{
xtype: 'pagingtoolbar',
store: store,
pageSize: 10,
dock: 'bottom',
displayInfo: true
}],
renderTo: Ext.getBody()
});
});
You need proxy: 'pagingmemory' which is Ext.ux.data.PagingMemoryProxy.
From doc:
Paging with Local Data
Paging can also be accomplished with local data using extensions:
Ext.ux.data.PagingStore
Paging Memory Proxy (examples/ux/PagingMemoryProxy.js)
Also note that there is no need to have:
totalCount in the store config (it will be provided by the proxy);
proxy on the grid (it's already within the store);
pageSize in the paging toolbar config (will be taken from the store).

Extjs - displaying date in grid column and click event for grid row

I have tried different ways of displaying date in grid column and implementing click event for grid row.
My requirements are:
1 Display date in grid column when date in my object is of form: "dateval": "2014-09-05T16:19:39 +04:00"
My data:
data: [
{
"age": 13,
"name": "Ben Watson",
"gender": "male",
"phone": "+1 (548) 314-8928",
"registered": "2014-09-05T16:19:39 +04:00"
}
code:
function render_date(val) {
val = Ext.util.Format.date(val, 'Y-m-d');
return val;
}
columns: [
{ text: 'Name', dataIndex: 'name' },
{ text: 'Age', dataIndex: 'age' },
{
text: 'Registered',
dataIndex: 'registered',
type: 'date',
dateFormat: 'timestamp',
renderer: render_date
}
]
2 When the user clicks a grid row in a panel, display the data in the row in the adjacent panel.
I am using ext.define and extend in this application
I had a play around with your code and discovered that the date is not being parsed by javascript correctly with the space in the datetime string. I removed all spaces and it worked fine for me.
See this Fiddle (code below in case of broken link)
Ext.application({
name: 'MyApp',
launch: function() {
var store = Ext.create('Ext.data.Store', {
storeId: 'simpsonsStore',
fields: ['name', 'email', 'phone', 'registered'],
proxy: {
type: 'ajax',
url: 'data1.json',
reader: {
type: 'json',
rootProperty: 'items'
}
},
autoLoad: true
});
function render_date(val) {
var date = new Date(val.replace(" ", ""));
val = Ext.util.Format.date(date, 'Y-m-d');
return val;
}
Ext.create("Ext.grid.Panel", {
title: 'Simpsons',
renderTo: Ext.getBody(),
store: Ext.data.StoreManager.lookup('simpsonsStore'),
selModel: new Ext.selection.RowModel({
mode: "SINGLE"
}),
columns: [{
text: 'Name',
dataIndex: 'name'
}, {
text: 'Email',
dataIndex: 'email',
flex: 1
}, {
text: 'Phone',
dataIndex: 'phone'
}, {
text: 'Registered',
dataIndex: 'registered',
type: 'date',
dateFormat: 'timestamp',
renderer: render_date
}],
height: 200,
width: 800,
});
}
});
// data1.json
{
"items": [{
'name': 'Lisa',
"email": "lisa#simpsons.com",
"phone": "555-111-1224",
"registered": "2014-09-05T16:19:39 +04:00"
}, {
'name': 'Bart',
"email": "bart#simpsons.com",
"phone": "555-222-1234",
"registered": "2014-09-05T16:19:39 +04:00"
}, {
'name': 'Homer',
"email": "homer#simpsons.com",
"phone": "555-222-1244",
"registered": "2014-09-05T16:19:39 +04:00"
}, {
'name': 'Marge',
"email": "marge#simpsons.com",
"phone": "555-222-1254",
"registered": "2014-09-05T16:19:39 +04:00"
}]
}

The message window hides behind the panel

The message window hides behind the panel when click Tab on Editable cell.
For example: double click the first phone cell, press TAB button. You can see the message box and then hide behind the grid window.
Ext.create('Ext.data.Store', {
storeId: 'simpsonsStore',
fields: ['name', 'email', 'phone'],
data: {
'items': [{
'name': 'Lisa',
"email": "lisa#simpsons.com",
"phone": "1224"
}, {
'name': 'Bart',
"email": "bart#simpsons.com",
"phone": "1234"
}, {
'name': 'Homer',
"email": "home#simpsons.com",
"phone": "1244"
}, {
'name': 'Marge',
"email": "marge#simpsons.com",
"phone": "1254"
}]
},
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'items'
}
}
});
var table = Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
store: Ext.data.StoreManager.lookup('simpsonsStore'),
columns: [{
text: 'Name',
dataIndex: 'name',
editor: {
xtype: 'textfield'
}
}, {
text: 'Email',
dataIndex: 'email',
flex: 1
}, {
text: 'Phone',
dataIndex: 'phone',
editor: {
xtype: 'numberfield',
hideTrigger: true,
validateOnChange: false
}
}],
height: 200,
width: 400,
plugins: [Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 2
})],
listeners: {
'validateedit': function () {
Ext.MessageBox.show({
icon: Ext.MessageBox.ERROR,
buttons: Ext.MessageBox.OK,
title: 'test',
msg: 'test'
});
}
}
});
tablePanel.add(table);
tablePanel.show();
});
Anyone met such problem before?
I got answer from sencha site:
I see it does not do this in 4.07, but in 4.1. I will talk with dev team.
For now, you can use defer:
Code:
listeners:{
'validateedit':function(){
Ext.MessageBox.show({
icon: Ext.MessageBox.ERROR,
buttons: Ext.MessageBox.OK,
title: 'test',
msg: 'test'
}).defer(100);
}
}

Set form field values in ExtJS

I'm using ExtJS to create a formPanel:
new Ext.FormPanel({
labelAlign: 'top',
title: 'Loading Contact...',
bodyStyle:'padding:5px',
width: 600,
autoScroll: true,
closable: true,
items: [{
layout:'column',
border:false,
items:[{
columnWidth:.5,
layout: 'form',
border:false,
items: [{
xtype:'textfield',
fieldLabel: 'First Name',
name: 'first_name',
id: 'first_name',
anchor:'95%'
}, {
xtype:'datefield',
fieldLabel: 'Birthdate',
name: 'birthdate',
width: 150,
}]
},{
columnWidth:.5,
layout: 'form',
border:false,
items: [{
xtype:'textfield',
fieldLabel: 'Last Name',
name: 'last_name',
anchor:'95%'
},{
xtype:'textfield',
fieldLabel: 'Email',
name: 'email',
vtype:'email',
anchor:'95%'
}]
}]
},{
xtype:'tabpanel',
plain:true,
activeTab: 0,
height:300,
/*
* By turning off deferred rendering we are guaranteeing that the
* form fields within tabs that are not activated will still be
* rendered. This is often important when creating multi-tabbed
* forms.
*/
deferredRender: false,
defaults:{bodyStyle:'padding:10px'},
items:[{
title:'Address',
layout:'form',
defaults: {width: 230},
defaultType: 'textfield',
items: [{
fieldLabel: 'Line1',
name: 'line1',
allowBlank:false,
},{
fieldLabel: 'Line2',
name: 'line2',
},{
fieldLabel: 'City',
name: 'city',
allowBlank: false,
},{
xtype:"combo",
fieldLabel:"State",
name:"state",
hiddenName:"combovalue"
}, {
fieldLabel: 'Zipcode',
name: 'zipcode',
allowBlank: false,
}]
},{
title:'Phone Numbers',
layout:'form',
defaults: {width: 230},
defaultType: 'textfield',
items: [{
fieldLabel: 'Home',
name: 'home_phone',
},{
fieldLabel: 'Cell',
name: 'cell_phone'
},{
fieldLabel: 'Emergency',
name: 'emergency_phone'
}]
},{
cls:'x-plain',
title:'Notes',
layout:'fit',
items: {
xtype:'htmleditor',
name:'notes',
fieldLabel:'Notes'
}
}]
}],
buttons: [{
text: 'Save'
},{
text: 'Cancel'
}]
})
How do I access the form fields by the name to set their value manually? Thanks
It's quite easy:
get hands on the form-panel (by the way it's Ext.form.FormPanel and not just Ext.FormPanel):
var formPanel = new Ext.form.FormPanel({...});
get the underlying Ext.form.BasicForm
var form = formPanel.getForm();
you then can use findField(name) to retrieve your form fields by their names:
var cellField = form.findField('cell_phone');
You can also set them in bulk by using the setValues() method.
eg:
Ext.getCmp('formname').getForm().setValues({
fielda: 'value1',
fieldb: 'value2'
})
Nice! worked for me :D
But you can set default value:
...
items: [{
xtype:'textfield',
fieldLabel: 'First Name',
name: 'first_name',
id: 'first_name',
value: 'somevalue',
anchor:'95%'
},
...

Categories