store sync data does not work - extjs

my store's code
Ext.define('Console.store.SubjectMaterial.DetailStore', {
extend: 'Ext.data.Store',
model: 'Console.model.SubjectMaterial.DetailModel',
proxy: {
actionMethods: 'POST',
type: 'ajax',
api: {
create: './modules/source/controller/SubjectMaterial/insertDetail.php',
read: './modules/source/store/SubjectMaterial/selectDetail.php',
destroy: './modules/source/controller/SubjectMaterial/deleteDetail.php'
},
reader: {
type: 'json',
root: 'result'
},
writer: {
type: 'json',
root: 'data',
encode: true
}
},
sorters: {
direction: 'ASC',
property: 'material_name'
},
remoteSort: true,
autoLoad: false,
autoSync: true
});
my model's code
Ext.define('Console.model.SubjectMaterial.DetailModel',{
extend:'Ext.data.Model',
fields:[
{
name:'material_id',
type:'string'
},{
name:'material_name',
type:'string'
},{
name:'material_version',
type:'string'
},{
name:'material_picture',
type:'string'
},{
name:'material_detail',
type:'string'
},{
name:'material_url',
type:'string'
},{
name: 'material_size',
type: 'string'
},{
name: 'material_author',
type: 'string'
},{
name: 'subject_share',
type: 'string'
},{
name: 'subject_secure',
type: 'string'
},{
name: 'material_create_date',
type: 'string'
},{
name: 'material_update_date',
type: 'string'
}]
});
my controller's code
detailInsertConfirm: function(obj, e, eOpts) {
var masterSelectedRecord = Ext.getCmp('sumagridmaster').getSelectionModel().getSelection()[0];
var detailStore = Ext.getCmp('sumagriddetail').store;
var actionPanel = obj.up('sumaactionpanel');
var gridPanel = obj.up('sumaformdetailinsert');
// console.log(gridPanel);
// var formPanel = gridPanel.getForm();
//insert
detailStore.add(gridPanel.getSelectionModel().getSelection());
// detailStore.add(masterSelectedRecord);
console.log(detailStore.data);
// console.log(gridPanel.getSelectionModel().getSelection());
detailStore.sync({
callback: function(batch, options) {
// body...
console.log('this is callback.');
},
success: function(batch, options) {
console.log('this is success.');
Ext.MessageBox.show({
title: MSG['universal_msg_box_header_text'],
icon: Ext.MessageBox.INFO,
msg: MSG['universal_msg_box_content_insert_success'],
closable: false,
buttons: Ext.MessageBox.OK,
fn: function(buttonId,text,opt){
if (buttonId == 'ok') {
detailStore.reload();
}
}
});
},
failure: function(batch, options) {
console.log('this is failure.');
Ext.MessageBox.show({
titel: MSG['universal_msg_box_header_text'],
icon: Ext.MessageBox.ERROR,
msg: MSG['universal_msg_box_content_insert_fail'],
closable: false,
buttons: Ext.MessageBox.OK
});
}
});
And I don't know why my controll's detailStore.sync cannot work.
Doesn't have any error code.
Just totally no Response....
And I always check my network.
It have no requset.

I'm not quite sure what you're asking. For sync to work you need to change something in the store (modify, delete, add), you need a writer on the proxy and when you then call store.sync() the request(s) is sent to the server. Only after that a response arrives.

Inside proxy make your autoSync:false . When autoSync: true then no need to call detailStore.sync({....}).

Related

Why my store does not load data even though data is returned

I can't tell why my store does not bind the the data returned from the server. Thank you in advance.
Here is how I instantiate and call "load":
var store = Ext.create('Iip.store.giip.other.States');
store.load({
params: {c: 'get_states'},
scope: this,
callback: function(records, operation, success) {
console.log(records); **<=== never prints**
}
});
Here is the store:
Ext.define("Iip.store.giip.other.States", {
extend: "Ext.data.Store",
storeId:"states-store",
model: "Iip.model.giip.other.State",
autoLoad: false,
buffered: true
});
Here is the model:
Ext.define('Iip.model.giip.other.State', {
extend: 'Ext.data.Model',
idProperty: "stateId",
fields:[
{name: "stateId", type: "int"},
{name: "state", type: "string"}
],
proxy: {
type: "ajax",
actionMethods: {
read: "POST"
},
api: {
read: "indexes/common_index.php"
},
reader: {
type: "json",
root: "states"
},
listeners: {
exception: function(proxy, response, operation, opts) {
if(typeof(operation.error) == "string") {
Ext.Msg.alert("Error", "Connection to server interrupted");
}
}
}
}
});
Here is the data returned from the server in firebug:
{"states":[{"stateId":"1","state":"AL"},{"stateId":"2","state":"AK"},
{"stateId":"3","state":"AS"},{"stateId":"4","state":"AZ"},{"stateId":"5","state":"AR"},
{"stateId":"6","state":"CA"},{"stateId":"7","state":"CO"},{"stateId":"8","state":"CT"},
{"stateId":"9","state":"DE"},{"stateId":"10","state":"DC"},
{"stateId":"11","state":"FM"},{"stateId":"12","state":"FL"},
{"stateId":"13","state":"GA"},{"stateId":"14","state":"GU"},
{"stateId":"15","state":"HI"},{"stateId":"16","state":"ID"},
{"stateId":"17","state":"IL"},{"stateId":"18","state":"IN"},
{"stateId":"19","state":"IA"},{"stateId":"20","state":"KS"},
{"stateId":"21","state":"KY"},{"stateId":"22","state":"LA"},
{"stateId":"23","state":"ME"},{"stateId":"24","state":"MH"},
{"stateId":"25","state":"MD"},{"stateId":"26","state":"MA"},
{"stateId":"27","state":"MI"},{"stateId":"28","state":"MN"},
{"stateId":"29","state":"MS"},{"stateId":"30","state":"MO"},
{"stateId":"31","state":"MT"},{"stateId":"32","state":"NE"},
{"stateId":"33","state":"NV"},{"stateId":"34","state":"NH"},
{"stateId":"35","state":"NJ"},{"stateId":"36","state":"NM"},
{"stateId":"37","state":"NY"},{"stateId":"38","state":"NC"},
{"stateId":"39","state":"ND"},{"stateId":"40","state":"MP"},
{"stateId":"41","state":"OH"},{"stateId":"42","state":"OK"},
{"stateId":"43","state":"OR"},{"stateId":"44","state":"PW"},
{"stateId":"45","state":"PA"},{"stateId":"46","state":"PR"},
{"stateId":"47","state":"RI"},{"stateId":"48","state":"SC"},
{"stateId":"49","state":"SD"},{"stateId":"50","state":"TN"},
{"stateId":"51","state":"TX"},{"stateId":"52","state":"UT"},
{"stateId":"53","state":"VT"},{"stateId":"54","state":"VA"},
{"stateId":"55","state":"VI"},{"stateId":"56","state":"WA"},
{"stateId":"57","state":"WV"},{"stateId":"58","state":"WI"},
{"stateId":"59","state":"WY"}]}
Here is the combo the data is supposed to bind to:
{
xtype: 'combo',
fieldLabel: 'State',
store: store,
displayField: 'state',
valueField: 'stateId',
anchor:'97%',
itemId: 'fatherState',
editable: false,
allowBlank: false,
emptyText: 'Select a state',
tabIndex: 6,
queryMode: 'local'
}
try after change this two fiels like below
store:
Ext.define("Iip.store.giip.other.States", {
extend: "Ext.data.Store",
config: {
storeId:"states-store",
model: "Iip.model.giip.other.State",
autoLoad: false,
buffered: true,
proxy: {
type: "ajax",
actionMethods: {
read: "POST"
},
api: {
read: "indexes/common_index.php"
},
reader: {
type: "json",
root: "states"
},
listeners: {
exception: function(proxy, response, operation, opts) {
if(typeof(operation.error) == "string") {
Ext.Msg.alert("Error", "Connection to server interrupted");
}
}
}
}
}
});
model:
Ext.define('Iip.model.giip.other.State', {
extend: 'Ext.data.Model',
idProperty: "stateId",
fields:[
{name: "stateId", type: "int"},
{name: "state", type: "string"}
]
});

store.sync after pressed OK button only reload the store

Ext.define('RouteSeqModel', {
extend: 'Ext.data.Model',
fields: [{name: '_id', type: 'number'}, {name: 'Route_Seq' , type: 'int'},'Location_Name','Route_LocationID','Route_ID']
});
var RouteSeqStore = Ext.create('Ext.data.JsonStore', {
model: 'RouteSeqModel',
storeId: 'RouteSeqStore',
autoLoad: false,
sorters: [{
property: 'Route_Seq',
direction: 'ASC'
}],
proxy: {
type: 'ajax',
url: 'get-routeseq.php',
api: {
create: 'insert-routeseq.php',
//read: 'http://visual04/ModuleGestion/php/Pays.php?action=read',
update: 'update-routeseq.php',
//destroy: 'http://visual04/ModuleGestion/php/Pays.php?action=destroy'
},
actionMethods: 'POST',
baseParams: {
_id : 0,
},
reader: {
type: 'json',
idProperty: '_id'
},
writer: {
type: 'json',
id: '_id'
}
}
});
RouteSeqStore.sync({
success: function(batch) {
//var button = Ext.getCmp('BtnRouteSeqRefresh');
//button.fireEvent('click', button); //need at here , if not too fast refresh will get the old data
grid.setLoading(false);
Ext.MessageBox.show({
title: "Information",
msg: batch.operations[0].request.scope.reader.jsonData["message"],
icon: Ext.MessageBox.INFO,
buttons: Ext.MessageBox.OK,
fn: function(buttonId) {
if (buttonId === "ok") {
//load store at here
}
}
});
},
failure: function(batch){
//var button = Ext.getCmp('BtnRouteSeqRefresh');
//button.fireEvent('click', button); //need at here , if not too fast refresh will get the old data
grid.setLoading(false);
RouteSeqStore.rejectChanges();
Ext.MessageBox.show({
title: "Error",
msg: batch.operations[0].request.scope.reader.jsonData["message"],
icon: Ext.MessageBox.ERROR,
buttons: Ext.MessageBox.OK,
fn: function(buttonId) {
if (buttonId === "ok") {
//load store at here
}
}
});
}
});
whenever called .sync function will automatically load the datastore with get-routeseq.php ,
is that have any way after pressing OK button only load the datastore(after pressed OK only call the get-routeseq.php)?
my autoLoad is false, but still automatically load the datastore.
I think you should use type: 'rest' and avoid url config in proxy.
Something like this:
var RouteSeqStore = Ext.create('Ext.data.JsonStore', {
model: 'RouteSeqModel',
storeId: 'RouteSeqStore',
autoLoad: false,
sorters: [{
property: 'Route_Seq',
direction: 'ASC'
}],
proxy: {
type: 'rest',
api: {
create: 'insert-routeseq.php',
read: 'get-routeseq.php',
update: 'update-routeseq.php',
//destroy: 'http://visual04/ModuleGestion/php/Pays.php?action=destroy'
},
actionMethods: 'POST',
baseParams: {
_id : 0,
},
reader: {
type: 'json',
idProperty: '_id'
},
writer: {
type: 'json',
id: '_id'
}
}
});
And if you want to just load store, use RouteSeqStore.load(). After you have made changes in store, use RouteSeqStore.sync().

Sencha Touch toolbar duplicating

I'm new with Sencha Touch 2 and I've got a trouble using nested list:
toolbar duplicates along with back button, so at the end of nested list I have 3 toolbars with 3 back buttons. I guess that the reason is that I create Ext.nestedList for each detailed card, useToolbar:false doesn't fix the problem because then I can't go to previous list. Maybe back button needs to be overwritten but I've got no idea of that. Any help would be very useful. Here is top part of code:
Ext.define('ListItem', {
extend: 'Ext.data.Model',
config: {
fields: ['text'],
},
});
var treeStore = Ext.create("Ext.NestedList", {
fullscreen: true,
tabBarPosition: 'bottom',
title: 'Now-Yakutsk',
iconCls: 'star',
displayField: 'title',
layout: 'card',
store: {
type: 'tree',
id: 'ListCard',
fields: [
'title','code',
{name: 'leaf', defaultValue: true}
],
root: {
leaf: false
},
proxy: {
type: 'jsonp',
url: 'http://now/catlist.php',
reader: {
type: 'json',
rootProperty: 'cat'
}
}
},
listeners: {
leafitemtap: function(nestedList, list, index, target, record) {
var treeStore2 = Ext.create("Ext.NestedList", {
fullscreen: true,
tabBarPosition: 'bottom',
//useToolbar:false,
//leaf: true ,
iconCls: 'star',
displayField: 'title',
store: {
type: 'tree',
id: 'detailCard',
fields: [
'title','code','link',
{name: 'leaf', defaultValue: true}
],
root: {
leaf: false
},
proxy: {
type: 'jsonp',
url: 'http://now/catlist2.php',
reader: {
type: 'json',
rootProperty: 'cat'
}
}
},
detailCard: { useToolbar:true,
xtype: 'panel',
scrollable: true,
styleHtmlContent: true
},
listeners: {
leafitemtap: function(nestedList, list, index, target, record) {
var cin = Ext.create("Ext.NestedList", {
fullscreen: true,
tabBarPosition: 'bottom',
//useToolbar:false,
//title: 'Blog',
iconCls: 'star',
displayField: 'list',
store: {
type: 'tree',
fields: [
'name', 'link', 'list', 'image', 'adress', 'banner',
{name: 'leaf', defaultValue: true}
],
root: {
leaf: false
},
proxy: {
type: 'jsonp',
url: 'http://now/cinemalist.php',
reader: {
type: 'json',
rootProperty: 'cinema'
}
}
},
detailCard: {
xtype: 'panel',
scrollable: true,
styleHtmlContent: true
},
listeners: {
leafitemtap: function(nestedList, list, index, element, post) {
this.getDetailCard().setHtml(post.get('banner'));
}
}
});
and the screenshot:
http://piccy.info/view3/4985552/cdfd1dcca3928d4a5d4b4b41ba060b1f/
found solution in case someone else has the same problem
-the point is hiding and showing the toolbar playing with active deactive methods
for example in parent we create
listeners: { activate : function() {
//this.getToolbar().hide();
tb = this.getToolbar();
} ,
deactivate: function() {
//this.getToolbar().hide();
}
then in child we put
listeners: {
activate : function() {
tb1 = this.getToolbar();
tb1.hide();
tb.show();
//this.getToolbar().hide();
} ,
deactivate: function() {
//tb.show();
//alert('dd');
//this.getToolbar().hide();
}
and so on ...

Extjs 4, Dynamic Tree and store re-mapping

I need to Extjs Tree panel with dynamic remote data(JSON) for file listing.
and the date field name is not fit to Extjs tree store field. so I need to re-mapping to make fit, like adding leaf field and text field.
the return JSON data is like this:
[{
"id":1,
"yourRefNo":"A91273",
"documentName":"Test Document",
"documentFileName":"login_to_your_account-BLUE.jpg",
"updatedBy":"root root",
"updatedAt":"\/Date(1343012244000)\/"
}]
and this is the tree panel:
Ext.define('App.view.Document.DocumentList', {
extend :'Ext.tree.Panel',
rootVisible : false,
alias: 'widget.Document_list',
store: 'DocumentList_store'
});
and this is the store:
Ext.define('App.store.DocumentList_store', {
extend: "Ext.data.TreeStore",
model: 'App.model.DocumentList_model',
proxy: {
type: 'ajax',
url: '/Document/GetDocumentList/',
actionMethods: {
read: 'POST'
},
reader: {
type: 'json',
root: '' // there is no root
},
pageParam: undefined,
startParam: undefined,
pageParam: undefined
},
root: {
children: []
},
autoLoad: false,
listeners: {
append: function (thisNode, newChildNode, index, eOpts) {
console.log(newChildNode.get('documentName')); // 'Test Document'
newChildNode.set('leaf', true);
newChildNode.set('text', newChildNode.get('documentName'));
// it does not add to tree panel.
}
}
});
after load data from server, and it call the append function well. but after that, nothing show up in tree panel.
What I am doing wrong? please advice me.
Thanks
[EDIT]
This is the model,
Ext.define("App.model.DocumentList_model", {
extend: "Ext.data.Model",
fields: [
'id','yourRefNo','documentName','documentFileName','updatedBy','updatedAt'
]
});
I'm fusing your code with a piece of working code of mine. Try see if this works:
Model:
Ext.define("App.model.DocumentList_model", {
extend: 'Ext.data.Model',
fields: [
{name: 'id'},
{name: 'yourRefNo'},
{name: 'documentName' },
{name: 'documentFileName'},
{name: 'updatedBy'},
{name: 'updatedAt', convert: function(v) { return v;} }, // Notice you can do field conversion here
{name: 'leaf', type: 'boolean', defaultValue: false, persist: false},
],
proxy: {
type: 'ajax',
url: '/Document/GetDocumentList/',
actionMethods: {
read: 'POST'
},
reader: {
type: 'json',
root: 'children'
},
},
});
Store:
Ext.define('App.store.DocumentList_store', {
extend: "Ext.data.TreeStore",
model: 'App.model.DocumentList_model',
root: {
text: 'Root',
id: null,
expanded: true
},
autoLoad: false,
});
JSON Response:
{
"success":true,
"children":[{
"id":1,
"yourRefNo":"A91273",
"documentName":"Test Document",
"documentFileName":"login_to_your_account-BLUE.jpg",
"updatedBy":"root root",
"updatedAt":"\/Date(1343012244000)\/",
"leaf":false
}]
}

problem with JsonStore and JsonReader

In my ExtJS application I use EditorGridPanel to show data from server.
var applicationsGrid = new Ext.grid.EditorGridPanel({
region: 'west',
layout: 'fit',
title: '<img src="../../Content/img/app.png" /> Приложения',
collapsible: true,
margins: '0 0 5 5',
split: true,
width: '30%',
listeners: { 'viewready': { fn: function() { applicationsGridStatusBar.setText('Приложений: ' + applicationsStore.getTotalCount()); } } },
store: applicationsStore,
loadMask: { msg: 'Загрузка...' },
sm: new Ext.grid.RowSelectionModel({
singleSelect: true,
listeners: { 'rowselect': { fn: applicationsGrid_onRowSelect} }
}),
viewConfig: { forceFit: true },
tbar: [{
icon: '../../Content/img/add.gif',
text: 'Добавить'
}, '-', {
icon: '../../Content/img/delete.gif',
text: 'Удалить'
}, '-'],
bbar: applicationsGridStatusBar,
columns: [{
header: 'Приложения',
dataIndex: 'ApplicationName',
tooltip: 'Наименование приложения',
sortable: true,
editor: {
xtype: 'textfield',
allowBlank: false
}
}, {
header: '<img src="../../Content/img/user.png" />',
dataIndex: 'UsersCount',
align: 'center',
fixed: true,
width: 50,
tooltip: 'Количество пользователей приложения',
sortable: true
}, {
header: '<img src="../../Content/img/role.gif" />',
dataIndex: 'RolesCount',
align: 'center',
fixed: true,
width: 50,
tooltip: 'Количество ролей приложения',
sortable: true}]
});
When I use JsonStore without reader it works, but when I try to update any field it uses my 'create' url instead of 'update'.
var applicationsStore = new Ext.data.JsonStore({
root: 'applications',
totalProperty: 'total',
idProperty: 'ApplicationId',
messageProperty: 'message',
fields: [{ name: 'ApplicationId' }, { name: 'ApplicationName', allowBlank: false }, { name: 'UsersCount', allowBlank: false }, { name: 'RolesCount', allowBlank: false}],
id: 'app1234',
proxy: new Ext.data.HttpProxy({
api: {
create: '/api/applications/getapplicationslist1',
read: '/api/applications/getapplicationslist',
update: '/api/applications/getapplicationslist2',
destroy: '/api/applications/getapplicationslist3'
}
}),
autoSave: true,
autoLoad: true,
writer: new Ext.data.JsonWriter({
encode: false,
listful: false,
writeAllFields: false
})
});
I believe that the problem is that I don't use reader, but when I use JsonReader grid stops showing any data at all.
var applicationReader = new Ext.data.JsonReader({
root: 'applications',
totalProperty: 'total',
idProperty: 'ApplicationId',
messageProperty: 'message',
fields: [{ name: 'ApplicationId' }, { name: 'ApplicationName', allowBlank: false }, { name: 'UsersCount', allowBlank: false }, { name: 'RolesCount', allowBlank: false}]
});
var applicationsStore = new Ext.data.JsonStore({
id: 'app1234',
proxy: new Ext.data.HttpProxy({
api: {
create: '/api/applications/getapplicationslist1',
read: '/api/applications/getapplicationslist',
update: '/api/applications/getapplicationslist2',
destroy: '/api/applications/getapplicationslist3'
}
}),
reader: applicationReader,
autoSave: true,
autoLoad: true,
writer: new Ext.data.JsonWriter({
encode: false,
listful: false,
writeAllFields: false
})
});
So, does anyone know what the problem might be and how to solve it. The data returned from my server is Json-formated and seams to be ok
{"message":"test","total":2,"applications":[{"ApplicationId":"f82dc920-17e7-45b5-98ab-03416fdf52b2","ApplicationName":"Archivist","UsersCount":6,"RolesCount":3},{"ApplicationId":"054e2e78-e15f-4609-a9b2-81c04aa570c8","ApplicationName":"Test","UsersCount":1,"RolesCount":0}]}
I had the same problem.. I solved it establishing Success Property in the json store and returning success true in the response from my create Method.. here is my code. Hope it helps
var EStore = new Ext.data.JsonStore
({
api: { read: 'getAssignedJobs',
create: 'createAssignedJobs',
update: 'updateAssignedJobs',
destroy: 'destroyAssignedJobs'},
root: 'jobData',
idProperty: 'Id',
autoSave: false,
autoLoad: true,
batch: true,
successProperty: 'success',
writer: new Ext.data.JsonWriter({ encode: true, writeAllFields: true }),
fields: [
{ name: 'Id', type: 'int', mapping: 'Id' },
{ name: 'ResourceId', type: 'int', mapping: 'fitter_id' },
{ name: 'StartDate', type: 'date', dateFormat: "Y-m-d\\TH:i:s" },
{ name: 'EndDate', type: 'date', dateFormat: "Y-m-d\\TH:i:s" },
{ name: 'status', type: 'int' },
{ name: 'job_id', type: 'int' }
]
});
and this is my Create method from Server Side..
public JsonResult createAssignedJobs(string jobData)
{
var Jsondata = (JobfitterToScheduler)new JavaScriptSerializer().Deserialize<JobfitterToScheduler>(jobData);
JobToFitterRepo jobtofitter = new JobToFitterRepo();
if (Jsondata != null)
{
jobtofitter.insertJobToFitter(13, Jsondata.fitter_id, 0, DateTime.Now, DateTime.Now);
return this.Json(new { success = true, jobData = Jsondata });
}
return null;
}
Looking at the source for Ext.data.Api I would say that the verbs are screwed up:
restActions : {
create : 'POST',
read : 'GET',
update : 'PUT',
destroy : 'DELETE'
},
For me the create should be a PUT and the update should be a POST. But I guess the Sencha guys have a different idea.
Btw, the source is taken from Ext 3.3.1
I guess you could override the restActions object to work as you would expect:
Ext.data.Api.restActions = {
create : 'PUT',
read : 'GET',
update : 'POST',
destroy : 'DELETE' };
As I've managed to know the Store 'id' config option is depricated.
I think the JsonStore keys off the record id on whether to do a POST vs PUT. So if the id is non-user generated the it will issue a POST, and a PUT otherwise. I am referring to record.id not record.data.id.
Not sure about the first part (my stores make the correct calls with similar code) but I can shed light on the 2nd part of your question.
Ext.data.JsonStore does NOT accept a reader object - it only takes fields and always makes its own reader, as you can see from the source
Ext.data.JsonStore = Ext.extend(Ext.data.Store, {
constructor: function(config){
Ext.data.JsonStore.superclass.constructor.call(this, Ext.apply(config, {
reader: new Ext.data.JsonReader(config)
}));
}
});
and is confirmed as being "as per docs" in Ext 2.x
http://www.sencha.com/forum/showthread.php?57189-2.x-Closed-Bug-in-Ext.data.JsonStore-cconstructor
So if you supply your own reader you must, in this case, make an Ext.data.Store instead (this caught me out too)

Resources