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.
Related
I'm stuck in the development of an extension for Shopware.
I want to extend the administration of categories in the correct way.
To achieve that created plugin (legacy). This plugins appends the first tab within a category.
//{block name="backend/category/view/tabs/settings" append}
This is done to add a fieldset with a dropdown. The file looks like this:
//{block name="backend/category/view/tabs/settings" append}
Ext.define('Shopware.apps.HaendlerbundFoobarCategories.view.category.tabs.settings', {
override:'Shopware.apps.Category.view.category.tabs.Settings',
getItems: function() {
var me = this;
var items = me.callParent(arguments);
me.FooBar = me.getFooBarSection();
items.push(me.FooBar);
return items;
},
getFooBarSection : function()
{
var me = this;
return Ext.create('Ext.form.FieldSet',{
title: 'FooBar Verlinkung',
anchor: '100%',
defaults : me.defaults,
disabled : false,
items : me.getDropdowns()
});
},
getDropdowns:function(){
var me = this;
return me.templateComboBox = Ext.create('Ext.form.field.ComboBox', {
xtype:'combobox',
fieldLabel: 'FooBar Product',
store: me.fooBarProducts.load(),
labelWidth: 155,
valueField: 'id',
displayField:'title',
editable: true,
allowBlank:true,
name:'fbproduct'
});
}
});
//{/block}
The main problem I suspect is the store. Leaving it like this I get an JS
error Cannot read property 'load' of undefined. without the .load() there is no error, but I also can't determine if the store got loaded.
The store file itself is in Views/backend/haendlerbund_foobar_categories/store/foo_bar_products
and the content of the file is:
//{block name="backend/haendlerbund_foobar_categories/store/fooBarProducts"}
Ext.define('Shopware.apps.HaendlerbundFoobarCategories.store.fooBarProducts', {
//...
model: 'Shopware.apps.HaendlerbundFoobarCategories.model.fooBarProducts',
proxy : {
type : 'ajax',
/**
* Configure the url mapping for the different
* store operations based on
* #object
*/
api : {
read : '{url controller=HaendlerbundFoobarCategories action=getProducts}'
},
/**
* Configure the data reader
* #object
*/
reader : {
type : 'json',
root: 'data'
}
}
});
//{/block}
EDIT:
For further context, this is the current state of the model the store references.
Ext.define('Shopware.apps.HaendlerbundFoobarCategories.model.fooBarProducts', {
extend: 'Ext.data.Model',
/**
* If the name of the field is 'id' extjs assumes automatically that
* this field is an unique identifier.
* #integer
*/
idProperty : 'id',
fields:[
{ name : 'id', type: 'int' },
{ name : 'ffid', type: 'bigint' },
{ name : 'title', type: 'string' },
{ name : 'description', type: 'string' },
{ name : 'price', type: 'decimal' },
{ name : 'vat', type: 'decimal' },
{ name : 'image', type: 'text' },
{ name : 'active', type: 'boolean' },
{ name : 'createdAt', type: 'datetime' },
{ name : 'modfiedAt', type: 'datetime' }
],
/*associations: [
{
relation: 'OneToMany',
storeClass: 'Shopware.apps.HaendlerbundFoobarCategories.store.fooBarProducts',
loadOnDemand: true,
type: 'hasMany',
model: 'Shopware.apps.HaendlerbundFooBarCategories.model.fooBarProducts',
name: 'getCategories',
associationKey: 'categories'
},
]*/
});
And the php controller which the store references as well has the following content:
<?php
class Shopware_Controllers_Backend_HaendlerbundFoobarCategories extends Shopware_Controllers_Backend_Application
{
protected $model = 'Shopware\CustomModels\Product\FFProduct';
protected $alias = 'ffproducts';
protected function getListQuery()
{
$builder = parent::getListQuery();
return $builder;
}
protected function getDetailQuery($id)
{
$builder = parent::getDetailQuery($id);
return $builder;
}
protected function getAdditionalDetailData(array $data)
{
return $data;
}
public function getProducts(){
$builder = $this->getManager()->createQueryBuilder();
$builder->select('*')
->from($model, $alias);
$data['id'] = 1;
$data['ffid'] = 1;
$data['title'] = 'lorem ipsum';
$this->view()->assign([
'success' => true,
'data' => $data,
'total' => 1
]);
}
}
It should return some dummy data for now.
I fail to solve the problem. As any documentation I was able to find was either focused on creating a separate component of changing an existing field. I suspect that I'm in the wrong scope or have a namespacing error or something.
Any help is greatly appreciated.
Your problem is the store assigning to combobox
this line of code isn't correct:
store: me.fooBarProducts.load(),
Usually a store should be only connected to a combobox like this:
store:'fooBarProducts'
Heres a fiddle to show you:
https://fiddle.sencha.com/#view/editor&fiddle/1kqj
Ext.application({
name : 'Fiddle',
launch : function() {
var yourStore=Ext.create('Ext.data.Store',{
fields:[{
name:'text'
},{
name:'value'
}],
data:[
{text:'test1',value:'testVal1'},
{text:'test2',value:'testVal2'},
{text:'test3',value:'testVal3'}
]
});
Ext.create({
xtype:'window',
width:300,
height:200,
items:[{
xtype:'combo',
displayField:'text',
valueField:'value',
store:yourStore
},{
xtype:'combo',
displayField:'text',
valueField:'value',
store:yourStore
}]
}).show();
}
});
have also a look here: http://docs.sencha.com/extjs/6.2.0/classic/Ext.form.field.ComboBox.html
for a combobox example
and here to store declaration:
http://docs.sencha.com/extjs/6.2.0/modern/Ext.data.Store.html
To load your store, you should call the store load out of combo declaration
If you use
store: somestore.load()
the combobox will bind to the value returned by load. The load function does not return anything, so the combo's store config is set to undefined.
What you want to do may be
me.fooBarProducts.load();
return me.templateComboBox = Ext.create('Ext.form.field.ComboBox', {
xtype:'combobox',
fieldLabel: 'FooBar Product',
store: me.fooBarProducts,
labelWidth: 155,
valueField: 'id',
displayField:'title',
editable: true,
allowBlank:true,
name:'fbproduct'
});
Rowediting is not working on update. I have grid with column in it. If i add a new row then data will bind as we change.
If we try to change the binded data then after update it will not reflect the changed one.
Here is my Grid combo box
xtype: 'grid',
itemId: 'gdItemId',
store: {
type: 'webapi',
api: {
read: 'api/Report/GetTimeDetails'
},
autoLoad: false,
},
columns: [
{
text: 'Type', dataIndex: 'type_id', width: '12%', editor: combo, renderer: comboBoxRenderer(combo),msgTarget: 'side'
}
var store = new Ext.data.SimpleStore({
fields: ["value", "text"],
data: [
[1, "Deliverys"],
[2, "Pickup"]
]
});
var comboBoxRenderer = function (combo) {
return function (value) {
var idx = combo.store.find(combo.valueField, value);
var rec = combo.store.getAt(idx);
return (rec === null ? '' : rec.get(combo.displayField));
};
}
var combo = new Ext.form.ComboBox({
store: store,
valueField: "value",
displayField: "text"
});
What i am doing wrong here ?
I found some problems here one is , I think has no model defined the model is necessary for use as base in your CRUD, another thing is there no proxy type webapi should be type: 'rest' if you wanna use RESTFULL [ , finally autoSync should be true for update data and another problem you should map the update method for send data to your server api{ read : yourlinkread , update: yourlinktoupdate }
Complete Example
https://docs.sencha.com/extjs/4.2.3/#!/example/build/KitchenSink/ext-theme-neptune/#cell-editing
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.
For some reason unknown to me, I cannot get my Ext JS store to display in my combobox
Here's my model:
Type.js
Ext.define('AM.model.Type', { //app name config is "AM"
extend: 'Ext.data.Model',
fields: [
{ name: 'field', type: "string" }
]
});
And my store:
Type.js
Ext.define('AM.store.Type', {
extend: 'Ext.data.Store',
model: 'AM.model.Type',
storeId: 'typestore',
data: [
{ field: 'Bobby' },
{ field: 'Jimbo' },
{ field: 'Craig' }
]
});
And where I call it:
app.js
{ xtype: 'combobox', padding: 5, store: Ext.getStore('typestore'), displayField: 'field'}...
Any ideas?
I don't see anything wrong here. The problem is probably elsewhere.
I have created a sample fiddle with your code slightly simplified, and it works fine.
http://jsfiddle.net/dbrin/28sX7/
I solved the problem by instantiating my store class with into a variable using Ext.Create
and setting my comboboxes queryMode to local (remote would display the data but keep on loading and loading).
I hope someone helps me out.
I want to load my grid with xml file's data, locally.
I created model,store and grid. I load the store in render event of grid.
The problem is,
Store is loaded but the grid is still empty. I looked at the grid at console, and grids items contains the loaded data, but grid doesnt contain the data on the screen.
Here is the model
Ext.define('BTOM.model.test.test', {
extend: 'Ext.data.Model',
fields: [
{ name: 'id', type: 'string' },
{ name: 'name', type: 'string' },
{ name: 'phone', type: 'string' }
]
});
Here is the store
Ext.define('BTOM.store.test.test', {
extend: 'Ext.data.Store',
model: 'BTOM.model.test.test',
autoLoad: false,
proxy: {
type: 'memory',
reader: {
type: 'xml',
root: 'users',
record: 'user'
}
}
});
And the grid
Ext.define('BTOM.view.test.test', {
extend: 'Ext.grid.Panel',
store: 'BTOM.store.test.test',
alias: 'widget.test',
title: 'Test',
initComponent: function () {
this.columns =
[
{ header: "Id", width: 120, dataIndex: 'id', sortable: false },
{ header: "Name", width: 180, dataIndex: 'name', sortable: false },
{ header: "Phone", width: 115, dataIndex: 'phone', sortable: false}
];
this.callParent(arguments);
},
});
And where I load the store is
render: function (grid, eOpts) {
var store = grid.getStore();
var data =
'<?xml version="1.0" encoding="utf-8"?>' +
'<users> ' +
'<user><id>1</id><name>Bll QASD</name><phone>333 2211</phone></user> ' +
'<user><id>2</id><name>Asd QWF</name><phone>444 2211</phone></user> ' +
'<user><id>3</id><name>Zas QWE</name><phone>555 2211</phone></user> ' +
'</users>';
var dataXml = (new DOMParser()).parseFromString(data, 'text/xml');
console.log(dataXml);
store.loadRawData(dataXml, true);
console.log(grid);
}
dataXML document is created without problem.
grid seems to contain the data (by firebug, I can see)
but datagrid is empty, doesnt show the data!
Ok, the error is that you are defining the store but not creating it.
So the grid just has the name of the store but it expects a store instance,
or is that some thing you have missed in the code snippet above.
I used the same code and here is a running example:
https://fiddle.sencha.com/#fiddle/oel