So, in my ext application i have a login form, and after the login succeed i'm synchronously loading my controllers for the given user. Everything work fine except the fact that every time i'm adding a new record (or delete one), the grid doesn't automaticaly refresh and i can't figure it out why. This is my store:
And this is my controller:
I have to mention that the records are saved and on refresh they show up. Also, on edit, the grid shows the modified row correctly.
Thanks in advance for any hint
Extjs with synchronously loaded controllers doesn't refrsh grid
Code:
Ext.define('myapp.store.Partners_list', {
extend: 'Ext.data.Store',
alias: 'store.partners_list',
pageSize: 25,
requires: [ 'myapp.model.Partners_list'],
constructor: function(cfg) {
var me = this;
cfg = cfg || {};
me.callParent([Ext.apply({
autoSync: true,
model: 'myapp.model.Partners_list',
storeId: 'Partners',
proxy: {
type: 'ajax',
actionMethods: 'POST',
listeners: {
exception: function(proxy, response, operation){
Ext.MessageBox.show({
title: 'ERROR',
msg: operation.getError(),
icon: Ext.MessageBox.ERROR,
buttons: Ext.Msg.OK
});
}
},
api: {
read: 'http://ift.tt/1thol0U',
create: 'http://ift.tt/1xtBD0R',
update: 'http://ift.tt/1xtBD0T',
destroy: 'http://ift.tt/1thoj9o'
},
reader: {
type: 'json',
idProperty: 'id',
root: 'data',
totalProperty:'total'
},
writer: {
type: 'json',
encode: true,
root: 'data'
},
afterRequest: function (request, success) {
console.log(request.action);
if (request.action == 'create')
{
var jsonMsg = Ext.JSON.decode(request.operation.response.responseText);
var vMsg=jsonMsg.msg;
Ext.Msg.alert('Insert',vMsg);
}
if (request.action == 'update')
{
var jsonMsg = Ext.JSON.decode(request.operation.response.responseText);
var vMsg=jsonMsg.msg;
Ext.Msg.alert('Update',vMsg);
}
},
listeners: {
exception: function(proxy, response, operation){
Ext.MessageBox.show({
title: 'ERROR',
msg: operation.getError(),
icon: Ext.MessageBox.ERROR,
buttons: Ext.Msg.OK
});
},
}
}
},
cfg)]);
}
});
And this is my controller:
Code:
Ext.define('myapp.controller.Partners_list', {
extend: 'Ext.app.Controller',
alias: 'controller.partners',
models: [ 'Partners_list'],
stores: [ 'Partners_list'],
views: [ 'Partners_list.PartnersGrid', 'Partners_list.PartnersEdit'],
refs:[ { ref:'RefgridPartners', selector:'partnersGrid' }],
listeners: {
'selectionchange': function(view, records) {
this.down('#delete').setDisabled(!records.length);
}},
init : function() {
var me = this;
me.control({
'partnersGrid dataview': {
itemdblclick: this.Edit
},
'partnersGrid button[action=actAdd]':
{
click:this.Add
},
'partnersGrid button[action=actEdit]':
{
click:this.Edit
},
'partnersEdit button[action=actSave]':
{
click:this.SavePartners
},
'partnersGrid button[action=actDelete]':
{
click:this.Delete
},
'partnersGrid button[action=actPrint]':
{
click:this.Print
}
});
},
Add: function(){
var FormAddEditPartners= Ext.widget('partnersEdit');
},
Edit: function(grid, record){
records = this.getRefgridPartners().getSelectionModel().getSelection();
if(records.length > 0){
var FormAddEditPartners= Ext.widget('partnersEdit');
var EditForm=FormAddEditPartners.down('form');
var record=records[0];
EditForm.loadRecord(record);
}
},
SavePartners: function(button) {
var win = button.up('window'),
form = win.down('form'),
record = form.getRecord(),
values = form.getValues();
if (form.getForm().isValid()) {
if (values.id > 0){
record.set(values);
} else{
record = Ext.create('myapp.model.Partners_list');
record.set(values);
store = this.getPartners_listStore();
store.add(record);
store.reload();
}
}
win.close();
},
Delete: function(){
var grid = this.getRefgridPartners();
record =grid.getSelectionModel().getSelection();
Partner=grid.getSelectionModel().getSelection()[0].data.Partner;
store = this.getPartners_listStore();
Ext.MessageBox.show({
title : 'Delete',
buttons : Ext.MessageBox.YESNO,
msg : 'Delete'+' '+Partner+'?',
icon : Ext.Msg.WARNING,
fn : function(btn)
{
if (btn == 'yes')
{
store.remove(record);
}
}
});
}
});
I have to mention that the records are saved and on refresh they show up. Also, on edit, the grid shows the modified row correctly.
Thanks in advance for any hint
Extjs with synchronously loaded controllers doesn't refrsh grid
Aucun commentaire:
Enregistrer un commentaire