Extjs : url in store - javascript

here is my store
Gave the url : '/rest/helloworld/submit',
var store = Ext.create('Ext.data.Store', {
autoLoad: false,
fields: ['name', 'date', 'email'],
pageSize: 10, // items per page
proxy: {
method: 'GET',
url: '/rest/helloworld/submit',
disableCaching: false,
type: 'json',
root: 'result',
totalProperty: 'total'
}
});
But as i can see in the console of browser.
request for url is like : Request URL:http://localhost:8080/JAXRS-HelloWorld/proxy/json.js?_dc=1428776089867
Also i added disableCaching : false
but it still shows _dc=1428776089867
Please help

Try using the ajax proxy and the noCache property:
var store = Ext.create('Ext.data.Store', {
autoLoad: false,
fields: ['name', 'date', 'email'],
pageSize: 10, // items per page
proxy: {
method: 'GET',
url: '/rest/helloworld/submit',
noCache: false,
type: 'ajax',
root: 'result',
totalProperty: 'total'
}
});

Related

ExtJs 4 Proxy Writer and PHP $_POST

I have this store:
Ext.define('strMtoOrganismos', {
extend: 'Ext.data.Store',
model: 'mdlMtoOrganismos',
autoLoad: false,
pageSize: 20,
proxy: {
type: 'ajax',
api: {
read: 'some php url',
update: 'some php url'
},
reader: {
type: 'json',
root: 'data',
totalProperty: 'total',
successProperty: 'success'
},
writer: {
type: 'json',
root: 'data',
encode: true,
writeAllFields: false,
}
}
});
In my controller I have a button that sync the store:
onPulsarGuardar:function(){
Ext.getStore('strMtoOrganismos').sync();
}
And in my php file,printing $_POST[data] I receive for example:
{"codigo_erp_cliente":"243","id":2}
How can I convert this string to an array like:
[codigo_erp_cliente]=>243
[id]=>2
Or an alternative configuration to the store writer?

How load data from mySQL to JSON in EXTJS

I create file in my store folder, i want load my data from mySQL to JSon, so this is my code:
Ext.define('DWP3.store.konten.Coba', {
extend: 'Ext.data.Store',
alias: 'store.coba',
uses: [
'Ext.data.Store'
],
initComponent: function(){
var store = Ext.create('Ext.data.Store', {
fields: [
{name: 'periode'},
{name: 'Teknik Informatika S1'},
],
proxy: {
type: 'ajax',
url : 'resources/data/load2.php',
reader: {
type: 'json',
rootProperty: 'view_aktif'
}
},
autoLoad: true
});
}
});
how can i load the data from store?
Can You Help me Please.
It seems better to me declared this way :
Ext.define('DWP3.store.konten.Coba', {
extend: 'Ext.data.Store',
alias: 'store.coba',
fields: [
{name: 'periode'},
{name: 'Teknik Informatika S1'},
],
proxy: {
type: 'ajax',
url : 'resources/data/load2.php',
reader: {
type: 'json',
rootProperty: 'view_aktif'
},
autoLoad: true
});

ExtJS Record with auto id Property

i have following problem with my ExtJS 5.1.0 Store.
When i want to create a new empty model with var m = new (store.model)(); and set Values with record.set(values); ( Which come from a Ext.form.Panel) the record has next to the normal Id, a second id. The Second one looks like that: "AM.namespace.model.ServiceContract-2".
Is it able to prevent a auto generated id?
To Create I use:
onAddServiceContract: function (item) {
this.__form = item.up('form');
var values = this.__form.getValues();
var store = this.getStore('ServiceContract');
var record = new (store.model)();
record.set('Id', 0000);
record.set(values);
record.phantom = true;
var rec = store.add(record);
}
The Store is defined as:
Ext.define('AM.####.store.ServiceContract',{
extend: 'AM.####.data.Store',
requires: ['Ext.data.proxy.Direct'],
model: 'AM.####.model.ServiceContract',
remoteGroup: true,
autoLoad: true,
//buffered: true,
pageSize: 1000,
leadingBufferZone: 500,
trailingBufferZone: 500,
autoSync: true,
constructor: function (config) {
config = Ext.apply({}, config);
if (!config.proxy) {
var proxy = {
type: 'direct',
reader: {
idProperty: 'Id',
rootProperty: 'data',
type: 'json'
},
writer: {
allowSingle: true,
writeAllFields: false // Note: Changed in ExtJS 5 to be default false
},
api: {
read: AM.####.ServiceContract.List,
create: AM.####.ServiceContract.Create,
update: AM.####.ServiceContract.BulkUpdate,
destroy: AM.####.ServiceContract.BulkDelete
}
};
config.proxy = proxy;
}
this.callParent([config]);
this.proxy.on('exception', this.onProxyException, this);
}
});
Thanks for your help!
You can mod the idProperty of the model to some other name.
For instance:
Ext.define('App.model.rssSoaFeed_m', {
extend: 'Ext.data.Model',
idProperty:'extIdProperty',//renaming the extjs id property
fields: [
{ name: 'title', type: 'auto' },
{ name: 'id', type: 'auto' }, //my custom id property
],
proxy:
{
type: 'ajax',
url: '/someurl.service',
extraParams: {
},
reader: {
type: 'json',
root: 'query.results.item'
}
}
});
And here is more info in sencha docs
Also, please note from the docs
the idProperty may be configured as null which will mean that no identifying field will be generated.

Store create works, store define not

I got a store for messages and it worked fine.
Now I need the same store, but with different initialization so I wanted to reuse it.
Before:
Ext.create('Ext.data.JsonStore', {
model: 'my.MessageModel',
storeId: 'importantStore',
autoLoad: true,
proxy: {
type: 'ajax',
url: 'ajax/ajAsProof.php',
actionMethods: {
read: 'POST'
},
reader: {
type: 'json',
root: 'messages',
idProperty: 'id'
},
writer: {
type: 'json',
writeAllFields: true,
allowSingle: false,
encode: true,
root: 'messages'
}
},
...
}
Ext.define('my.MessagesGrid', {
extend: 'Ext.grid.Panel',
store: 'myGrid',
...
}
Ext.create('my.MessageGrid', {
store:'importantStore',
renderTo: 'myGridId'
});
After:
Ext.define('my.ImportantStore', {
extend: 'Ext.data.JsonStore',
model: 'my.MessageModel',
autoLoad: true,
proxy: {
type: 'ajax',
url: 'ajax/ajAsProof.php',
actionMethods: {
read: 'POST'
},
reader: {
type: 'json',
root: 'messages',
idProperty: 'id'
},
writer: {
type: 'json',
writeAllFields: true,
allowSingle: false,
encode: true,
root: 'messages'
}
},
...
}
Ext.define('my.MessagesGrid', {
extend: 'Ext.grid.Panel',
store: 'myGrid',
...
}
var importantStore = Ext.create('my.ImportantStore', {
storeId: 'importantStore',
... // my custom settings to come here, like filters or parameters
});
Ext.create('my.MessageGrid', {
store:'importantStore',
renderTo: 'myGridId'
});
This fails. Firefox/Firebug gives me a
TypeError: url is undefined ext-all-debug.js (line 14429)
this.$cache = dom.id ? Ext.cache[dom.id] : null;
All defined in the same js file within the Ext.ready() call. ExtJS 4.2.1.883 used.
Any ideas on what's wrong? Doing the same to make the grid reusable works fine, but fails with the store.
"url is undefined"
Are you actually putting some value to url config on your store ?
Ext.define('my.ImportantStore', {
extend: 'Ext.data.JsonStore',
model: 'my.MessageModel',
autoLoad: true,
url: '../myServletOrRestService' // do you have this config ?
...
}
After days of looking for a reply I got the solution, mostly by coincidence... coming from C# background I wasn't aware of the prototypean horrors that comes with ExtJS and JavaScript.
Ext.define('my.ImportantStore', {
extend: 'Ext.data.JsonStore',
model: 'my.MessageModel',
autoLoad: true,
constructor: function(config) {
config = config || {};
this.initConfig(config);
this.proxy = Ext.create('Ext.data.proxy.Ajax', {
extraParams: config.extraParams
// other config
});
...
this.callParent(arguments);
}
});
Ext.create('my.ImportantStore', {
storeId: 'importantStore',
extraParams: {
...
}
});
If the components (in this case the proxy) isn't created within the container, when using Ext.define the proxy (or settings for that case) will be shared above all instances, which is counter intuitive for people who were familiar with OOP programming and class inheritance and never worked with prototype styled inheritance which works via cloning.

loading data to store but no data visible in grid

So I load json to the store but no data visible in grid. What am I doing wrong? Here is the grid:
{
xtype: 'gridpanel',
title: 'Clients List',
store: Ext.create('Ext.data.Store', {
model: 'app.model.modelClients',
proxy: Ext.create('Ext.data.HttpProxy', {
type: 'ajax',
headers: { 'Accept': 'application/json' },
url: 'client.php',
noCache: false,
startParam: undefined,
filterParam: undefined,
limitParam: undefined,
pageParam: undefined
}),
reader: new Ext.data.JsonReader({
root: 'records',
id: 'id',
fields: ['first_name', 'last_name', 'phone']
}),
listeners: {
load: function (self, records, successful, eOpts) {
var fields = records[0].fields;
console.log(fields.getAt(0));
}
},
autoLoad: true
}),
flex: '1',
columns: [
{ text: 'Name', dataIndex: 'first_name' },
{ text: 'Last Name', dataIndex: 'last_name' },
{ text: 'Phone', dataIndex: 'phone' }
]
}
ah. you have the reader at the wrong level. It is part of the proxy
proxy: {
type: "ajax",
url: "...",
reader: {

Categories

Resources