Grid showing empty rows extjs - extjs

Here, store loads data from databse(firebug shows) but all rows are empty...Please help.I cant find the reason behind...
Store
autoLoad: true,
model: 'CustomerService.model.OrderModel',
idProperty: 'id',
fields: [{
name: 'id',
type: 'int'
}, {
name: 'name',
type: 'string'
}, {
name: 'quantity',
type: 'int'
}, {
name: 'receivedquantity',
type: 'int'
}],
proxy: {
type: 'ajax',
url: 'data/Getall.php',
reader: {
type: 'json',
root: 'data',
successProperty: 'success'
}
}
});
Here is Model:
Ext.define('CustomerService.model.OrderModel', {
extend: 'Ext.data.Model'
});
here is view:
Ext.define('CustomerService.view.customer.List', {
extend: 'Ext.grid.Panel',
alias: 'widget.mylist',
selModel: Ext.create('Ext.selection.CheckboxModel', {
checkOnly: false
}),
store: 'OrderStore',
forceFit: true, //Fit to container:: columnLines:true, height:132, width:200, autoResizeColumns:true, initComponent:function(){
this.columns = [{
header: 'name',
dataIndex: 'name'
}, {
header: 'Quantity',
dataIndex: 'quantity',
}, {
header: 'Received Quantity',
dataIndex: 'receivedquantity'
}];
this.callParent(arguments);
}
});

If your using a model in your store you should define the fields in your model instead of defining them in your store.
Ext.define('CustomerService.model.OrderModel', {
extend: 'Ext.data.Model',
fields: [{
name: 'id',
type: 'int'
}, {
name: 'name',
type: 'string'
}, {
name: 'quantity',
type: 'int'
}, {
name: 'receivedquantity',
type: 'int'
}],
});
Ext.data.Store fileds:
This may be used in place of specifying a model configuration. The
fields should be a set of Ext.data.Field configuration objects. The
store will automatically create a Ext.data.Model with these fields. In
general this configuration option should only be used for simple
stores like a two-field store of ComboBox. For anything more
complicated, such as specifying a particular id property or
associations, a Ext.data.Model should be defined and specified for the
model config.

Related

Data binding associations in ExtJS admin template

I'm unsuccessful in getting binding associations working in the admin dashboard template (with the desired behavior of selecting a record from a combobox and pulling up associated records in a grid).
My main viewModel is defined as:
Ext.define('Admin.view.main.MainModel', {
extend: 'Ext.app.ViewModel',
alias: 'viewmodel.main',
stores: {
patients: {
model: 'md_registry.model.Patient',
autoLoad: true
}
}
});
I added a leaf node to Pages in NavigationTree.js:
{
text: 'Pages',
iconCls: 'x-fa fa-leanpub',
expanded: false,
selectable: false,
//routeId: 'pages-parent',
//id: 'pages-parent',
children: [
{
text: 'Proc',
iconCls: 'x-fa fa-send',
rowCls: 'nav-tree-badge nav-tree-badge-hot',
viewType: 'procedure',
leaf: true
}]
}
With the procedure view being:
Ext.define('Admin.view.pages.Procedure', {
extend: 'Ext.panel.Panel',
xtype: 'procedure',
requires: [
'Ext.panel.Panel',
'Admin.model.Patient',
'Admin.model.Procedure'
//'Admin.model.Diagnosis'
],
anchor : '100% -1',
referenceHolder: true,
width: 1000,
height: 1000,
referenceHolder: true,
layout: {
type: 'hbox',
align: 'stretch'
},
viewModel: 'main',
session: {},
items: [
// https://www.sencha.com/forum/showthread.php?299301-Bind-combobox-displayField-value-to-displayfield
{
xtype: 'fieldset',
layout: 'anchor',
items: [{
xtype: 'combobox',
listeners : {
select : function() {
console.log(arguments)
console.log(arguments[1].data.birth_date)
console.log(arguments[1].data.first_name)
console.log(arguments[1].data.last_name)
console.log(arguments[1].data.sex)
}
},
bind: {
store: '{patients}'
},
reference: 'patientCombo',
publishes: 'id',
fieldLabel: 'Patient Search',
displayField: 'mrn',
//anchor: '-',
// We're forcing the query to run every time by setting minChars to 0
// (default is 4)
minChars: 2,
queryParam: '0',
queryMode: 'local',
typeAhead: true,
// https://www.sencha.com/forum/showthread.php?156505-Local-combobox-with-any-match-filter
doQuery: function(queryString, forceAll) {
this.expand();
this.store.clearFilter(!forceAll);
if (!forceAll) {
this.store.filter(this.displayField, new RegExp(Ext.String.escapeRegex(queryString), 'i'));
}
}
}, {
// https://www.sencha.com/forum/showthread.php?299301-Bind-combobox-displayField-value-to-displayfield
xtype: 'displayfield',
fieldLabel: 'Selected Patient',
bind: {
html: '<p>Name: <b>{patientCombo.selection.first_name}, ' +
'{patientCombo.selection.last_name} </b></p>' +
'<p>Sex: {patientCombo.selection.sex}</p>' +
'<p>Birthdate: {patientCombo.selection.birth_date}</p>'
}
}]
},
{
title: 'Procedures',
xtype: 'grid',
bind: '{patientCombo.selection.procedures}',
flex: 1,
margin: '0 0 0 10',
columns: [{
text: 'Procedure Date', dataIndex: 'proc_date', flex: 1
}, {
text: 'Procedure', dataIndex: 'proc_name', flex: 1
}],
plugins: [{
ptype: 'rowexpander',
rowBodyTpl : new Ext.XTemplate(
'<p><b>Proc Name Orig:</b> {proc_name_orig}</p>',
'<p><b>Proc Code:</b> {proc_code}</p>',
'<p><b>Proc Code Type:</b> {proc_code_type}</p>')
}],
viewConfig: {
emptyText: 'No procedures',
deferEmptyText: false
}
}]
});
My Patient and Procedure models are simply:
Ext.define('Admin.model.Procedure', {
extend: 'Ext.data.Model',
idProperty: 'id',
fields: [
//{ name: 'id', type: 'string' },
{ name: 'proc_code', type: 'string' },
{ name: 'proc_name', type: 'string' },
{ name: 'proc_code_type', type: 'string' },
{ name: 'proc_name_orig', type: 'string' },
{ name: 'proc_date', type: 'date', format: 'Y-m-d' },
{
name: 'patient_id',
type: 'string',
reference: {
parent: 'Admin.model.Patient',
//type: 'md_registry.model.Patient',
inverse: 'procedures',
autoLoad: false
}
}
],
proxy: {
type: 'rest',
url: 'http://127.0.0.1:5000/procedureview/api/read',
reader: {
type: 'json',
rootProperty: ''
}
}
});
and
Ext.define('Admin.model.Patient', {
extend: 'Ext.data.Model',
requires: [
'Ext.data.proxy.Rest'
],
fields: [
{ name: 'id', type: 'string' },
{ name: 'mrn', type: 'string' },
{ name: 'birth_date', type: 'date', format: 'Y-m-d' },
{ name: 'sex', type: 'string' },
{ name: 'first_name', type: 'string' },
{ name: 'last_name', type: 'string' }
],
proxy: {
type: 'ajax',
url: 'http://127.0.0.1:5000/patientview/api/read',
reader: {
type: 'json',
rootProperty: ''
}
}
});
respectively.
The data for my Patients store are getting loaded into the combobox just fine, but when I select an item from the combo list it is not firing off the call to grab the associated procedures data (see image: .
However, the binding associations work as expected with Side Navigation Tabs (see image: , and show up within the object prototype chain, as expected... see
(whereas for the admin dashboard, the associations are empty).
I cannot for the life of me get these working in the Admin Dashboard. I noticed a tool called the bind inspector, but I am running the GPL version of the SDK, so I do not have access to this. Beyond this, I cannot figure out a way to debug why the binding association is not working in the admin dashboard, but otherwise works perfectly well in Side Navigation Tabs.
I would set up a Fiddle, but I have no idea how to do it using the Admin Template.
I just figured it out. It was a namespace issue.
My reference in the procedure model should be:
reference: {
parent: 'Patient',
inverse: 'procedures',
autoLoad: false
}
Voila, all the associated data get loaded as expected!

ExtJS: dataIndex property not working

My Simplified Store:
Ext.define('PT.store.DealTree', {
extend: 'Ext.data.TreeStore',
proxy: {
type: 'rest',
url: '/dealTree',
reader: { type: 'json', root: 'children', successProperty: 'success' },
},
root: { name: 'children', expanded: true }
})
My Simplified Grid:
Ext.define('PT.view.deal.DealSelectionGrid', {
extend: 'Ext.tree.Panel',
alias: 'widget.dealSelectionGrid',
rootVisible: false,
fields: ['text', 'date'],
store: 'DealTree',
columns: [
{ xtype: 'treecolumn', text: 'Deal', dataIndex: 'text' },
{ xtype: 'datecolumn', text: 'Date', dataIndex: 'date' }
]
});
Example of simplified response:
[ { text: 'aNode',
id: 522f7dd2323544c424000034,
leaf: true,
date: '2013/10/10' } ]
nothing appears in the Date column, yet the text, leaf, id all work perfectly. I'm clearly missing something. Currently, I'm not using a model because each level is a different model, which isn't supported by default - hence I let ExtJS add all the NodeInterface decoration for me.
The fields configuration goes into the store, not the tree component.
For example, your code is showing the date with this store:
Ext.define('PT.store.DealTree', {
extend: 'Ext.data.TreeStore',
proxy: {
type: 'rest',
url: '/dealTree',
reader: { type: 'json', root: 'children', successProperty: 'success' }
},
// fields option here!
fields: ['text', 'date'],
root: {
name: 'children',
expanded: true,
children: [{
text: 'aNode',
id: '522f7dd2323544c424000034',
leaf: true,
date: '2013/10/10'
}]
}
});

Does Extjs Combobox work with store filters?

i want to ask you if extjs comboboxes use filtered stores. I have a table with different kind of business(so it has a "type" field). I have a view with multiple comboboxes, and i want that those works with stores that use the same model, but with different filters. So when i put them to work, it doesn't work.
This is one of the filtered stores:
Ext.define('myapp.store.ListaAerolineas', {
extend: 'Ext.data.Store',
requires: [
'myapp.model.Empresa'
],
constructor: function(cfg) {
var me = this;
cfg = cfg || {};
me.callParent([Ext.apply({
autoLoad: true,
autoSync: true,
model: 'myapp.model.Empresa',
storeId: 'MyJsonPStore',
proxy: {
type: 'jsonp',
url: 'http://myapp.localhost/empresa/listar/',
reader: {
type: 'json',
root: 'listaempresa'
}
},
filters: {
property: 'IdTipo',
value: 5
}
}, cfg)]);
}
});
This is the model:
Ext.define('myapp.model.Empresa', {
extend: 'Ext.data.Model',
idProperty: 'Id',
fields: [
{
name: 'Id',
type: 'int'
},
{
name: 'Nombre',
type: 'string'
},
{
name: 'Direccion',
type: 'string'
},
{
name: 'Telefono',
type: 'string'
},
{
name: 'Contacto',
type: 'string'
},
{
name: 'Celular',
type: 'string'
},
{
name: 'TipoEmpresa',
type: 'string'
},
{
name: 'Estado',
type: 'string'
},
{
name: 'FechaCreacion',
type: 'date'
},
{
name: 'IdTipo',
type: 'int'
},
{
name: 'IdEstado',
type: 'int'
}
]
});
And finally this is my grid column definition for my combobox:
{
xtype: 'gridcolumn',
dataIndex: 'Aerolinea',
text: 'Aerolinea',
editor: {
xtype: 'combobox',
id: 'cmbGridListaEmbarquesAerolinea',
store: 'ListaAerolineas'
}
So, i must do anything? Thank you in advance...
What version of ExtJs are you using? but in general combobox will display only records that are filtered in the store. So, to answer your question - yes, it should work.

Sencha Touch, one store to be used by a list and a dataview display?

So I implemented a dataview and a list format card to display my json in store. I am trying to get the two view to share one store, since the data are the same. However the way i am doing it is not really working, if I only have Dataview or List it works fine. When I have both call the store, it will stop working... please help!
Dataview:
Ext.define('Sencha.view.hoardboard.HoardList', {
extend: 'Ext.DataView',
xtype: "hoardlist",
requires: ['Ext.XTemplate'],
config: {
flex:1,
scrollable: true,
store: 'Plist',
baseCls: 'columns',
itemTpl: '<div class=pin><img src={image}><div style="padding-top: 10px; padding-left: 20px; padding-right:20px">{name}<br>{brand}</div></div>'
}
});
List view
Ext.define('Sencha.view.hoardboard.HoardList2', {
extend: 'Ext.List',
xtype: "hoardlist2",
config: {
flex:1,
scrollable: true,
store: 'Plist',
grouped: true,
itemTpl: '{name}'
}
});
Model
Ext.define('Sencha.model.HoardList', {
extend: 'Ext.data.Model',
config: {
fields: [
{
name: 'name',
type: 'string'
},
{
name: 'image',
type: 'string'
},
{
name: 'type',
type: 'string'
},
{
name: 'brand',
type: 'string'
}
,
{
name: 'color',
type: 'string'
},
{
name: 'description',
type: 'string'
}
]
}
});
Store
Ext.define('Sencha.store.HoardList',{
extend: 'Ext.data.Store',
storeId: 'Plist',
model:'Sencha.model.HoardList',
title: 'My Collection',
autoLoad: true,
sorters: 'name',
grouper: {
groupFn: function(record) {
return record.get('name')[0];
}
},
proxy: {
type: 'ajax',
url : 'products.json',
reader: {type: 'json', rootProperty:'products'}
}
});
Thank you so much!
Generally speaking when you're using Sencha framework you don't share one store object between several visual controls.
If you want to use same store in two places you need to clone it and have two separate store objects.

sencha touch 2: list population with associations in model

as a learning project for sencha-touch2 i'm trying to populate a store with data from https://www.hnsearch.com/api
i have created the model and store as follow and in the inspector view i can see that data is received and correctly mapped.
the problem i cannot figure out is, how to show a sencha xtype:list element with the actual result items nested in the json (Model: SearchResultItem). i tried the following, which will give me a list with ONE list item with the results in it, but i would like to have a list item for each search result.
models:
Ext.define('senchaHackerNews.model.Search', {
extend: 'Ext.data.Model',
config: {
fields: [{
name: 'hits',
type: 'int'
}],
associations: {
type: 'hasMany',
name: 'results',
model: 'senchaHackerNews.model.SearchResults',
associationKey: 'results'
}
}
});
Ext.define('senchaHackerNews.model.SearchResults', {
extend: 'Ext.data.Model',
config: {
fields: [{
name: 'score',
type: 'float'
}],
associations: {
type: 'hasOne',
name: 'item',
model: 'senchaHackerNews.model.SearchResultItem',
associationKey: 'item'
}
}
});
Ext.define('senchaHackerNews.model.SearchResultItem', {
extend: 'Ext.data.Model',
config: {
fields: [{
name: 'username',
type: 'string'
}, {
name: 'title',
type: 'string'
}, {
name: 'points',
type: 'int'
}, {
name: 'url',
type: 'string'
}, {
name: 'domain',
type: 'string'
}]
}
});
store:
Ext.define('senchaHackerNews.store.Search', {
extend: 'Ext.data.Store',
requires: ['senchaHackerNews.model.Search'],
config: {
storeId: 'hnSearchStore',
model: 'senchaHackerNews.model.Search',
autoload: false,
proxy: {
type: 'jsonp',
// url: 'http://api.thriftdb.com/api.hnsearch.com/items/_search?q=ipad',
reader: {
type: 'json',
rootProperty: ''
},
callbackKey: 'callback'
}
}
});
view:
Ext.define('senchaHackerNews.view.Search', {
extend: 'Ext.navigation.View',
alias: 'widget.hnSearch',
xtype: 'hnSearch',
requires: ['Ext.field.Search'],
initialize: function() {
var xtpl = new Ext.XTemplate('<tpl for="results">{item.username} ---- {item.title} | <br></tpl>');
this.add([
{
xtype: 'container',
title: 'Search HN',
layout: 'vbox',
items: [{
xtype: 'searchfield',
placeHolder: 'Search HN News (at least 3 chars)',
listeners: {
scope: this,
clearicontap: this.onSearchClearIconTap,
keyup: this.onSearchKeyUp
}
}, {
xtype: 'list',
flex: 1,
itemTpl: xtpl,
store: 'hnSearchStore',
emptyText: 'No Matching Items',
}]
}
]);
this.callParent(arguments);
},
onSearchKeyUp: function(field) {
if(field.getValue() != '' && field.getValue().length > 3) {
var store = Ext.StoreMgr.get('hnSearchStore');
store.setProxy({
url: 'http://api.thriftdb.com/api.hnsearch.com/items/_search?q='+field.getValue()
});
store.load();
} else if(field.getValue() == '') {
Ext.StoreMgr.get('hnSearchStore').removeAll();
}
},
onSearchClearIconTap: function() {
Ext.StoreMgr.get('hnSearchStore').removeAll();
}
});
Example JSON is here http://api.thriftdb.com/api.hnsearch.com/items/_search?q=facebook&pretty_print=true
AFAIK if you are looking for array of items to be displayed the you should use items model in store and rootProperty pointing to item so
Ext.define('senchaHackerNews.store.Search', {
extend: 'Ext.data.Store',
requires: ['senchaHackerNews.model.SearchResults'],
config: {
storeId: 'hnSearchStore',
model: 'senchaHackerNews.model.SearchResults',
autoload: false,
proxy: {
type: 'jsonp',
// url: 'http://api.thriftdb.com/api.hnsearch.com/items/_search?q=ipad',
reader: {
type: 'json',
rootProperty: 'results'
},
callbackKey: 'callback'
}
}
});
Note the change in model & rootProperty attribute

Resources