PDA

View Full Version : Direct Store Not Working



azinyama
23 May 2013, 6:40 AM
Good day all!!! I have a store that I'm attaching to a grid.

Store..




Ext.define('Firm_Matters.store.Contact',
{
extend : 'Ext.data.Store',
id : 'Contact',
autoLoad : false,
autoSave : false,
autoSync : true,
remoteSort : true,
model : 'Firm_Matters.model.Contact',
proxy : {
type : 'direct',
reader : {
type : 'json',
successProperty : 'success',
messageProperty : 'message',
totalProperty : 'total',
root : 'data',
idProperty : 'Contact_RowID'
},
writer : {
type : 'json',
encode : false,
writeAllFields : true
},
api : {
create : Firm_Matters.ContactHandler.Create_Contact,
read : Firm_Matters.ContactHandler.Load_Contact,
update : Firm_Matters.ContactHandler.Update_Contact,
destroy : Firm_Matters.ContactHandler.Delete_Contact
},
listeners : {
exception : function (proxy, response, operation)
{
Ext.MessageBox.show(
{
title : 'Remote Exception: Contact',
msg : operation.getError(),
icon : Ext.MessageBox.ERROR,
buttons : Ext.Msg.OK
});
}
},
afterRequest: function (request, success)
{
if (request.action == 'read')
{
this.readCallback(request);
}
},
readCallback: function (request)
{
if (!request.operation.success)
{
Ext.Msg.show(
{
title : 'Contact Load Error',
msg : 'Could not load contact. Please try again or contact your administrator.',
buttons : Ext.Msg.OK,
icon : Ext.Msg.WARNING
});
}
},
scope: this
}
});


Model...




Ext.define('Firm_Matters.model.Contact',
{
extend: 'Ext.data.Model',

fields :
[
{
name: 'Contact_RowID',
type: 'int'
},
{
name: 'Contact_IsCompany',
type: 'bool'
},
{
name: 'Contact_DisplayName',
type: 'string'
},
{
name: 'Title_RowID',
type: 'int'
},
{
name: 'Contact_FName',
type: 'string'
},
{
name: 'Contact_SName',
type: 'string'
},
{
name: 'Contact_JobTitle',
type: 'string'
},
{
name: 'Contact_Address_01',
type: 'string'
},
{
name: 'Contact_Phone',
type: 'string'
},
{
name: 'Contact_Mobile',
type: 'string'
},
{
name: 'Contact_Email',
type: 'string'
},
{
name: 'Contact_Fax',
type: 'string'
},
{
name: 'Contact_WebSite',
type: 'string'
},
{
name: 'Contact_Notes',
type: 'string'
},
{
name: 'Contact_RegNo',
type: 'string'
},
{
name: 'Contact_TaxClearance',
type: 'string'
},
{
name: 'Bank_RowID',
type: 'int'
},
{
name: 'Bank_Code',
type: 'string'
},
{
name: 'Bank_AccountName',
type: 'string'
},
{
name: 'Bank_AccountNumber',
type: 'string'
},
{
name: 'Bank_AccountType',
type: 'string'
},
{
name: 'Bank_Reference',
type: 'string'
},
{
name: 'Contact_IsActive',
type: 'bool'
}
]
});


Grid placed inside panel...



items : [{
xtype : 'gridpanel',
name : 'gridContact',
closable : false,
resizable : false,
draggable : false,
border : false,
bodyBorder : false,
floating : false,
frame : false,
autoDestroy : true,
store : 'Contact',
// height : 140,
margin : '0',
region : 'center',
// plugins : Ext.create('Ext.grid.plugin.RowEditing',
// {
// clicksToMoveEditor : 1,
// errorSummary : false,
// autoCancel : false
// }),
viewConfig : {
stripeRows : true,
loadingText : 'Loading contacts...'
},
columns : [{
text : 'Contact_RowID',
sortable : false,
hideable : false,
hidden : true,
dataIndex : 'Contact_RowID'
},
{
text : 'Display Name',
flex : 1,
sortable : false,
hideable : false,
dataIndex : 'Display_Name'
},
{
text : 'Address',
flex : 3,
sortable : false,
hideable : false,
dataIndex : 'Contact_Address_01'
},
{
text : 'Phone',
flex : 1,
sortable : false,
hideable : false,
dataIndex : 'Contact_Phone'
},
{
text : 'Mobile',
flex : 1,
sortable : false,
hideable : false,
dataIndex : 'Contact_Mobile'
},
{
text : 'Email',
flex : 1,
sortable : false,
hideable : false,
dataIndex : 'Contact_Email'
},
{
xtype : 'actioncolumn',
cls : 'tasks-icon-column-header tasks-edit-column-header',
width : 24,
icon : '../../ext-4.2.0/resources/images/edit_task.png',
iconCls : 'x-hidden',
tooltip : 'Edit',
menuDisabled: true,
sortable : false,
handler : Ext.bind(this.handleEditContactClick, this)
}]
}]


My problem is that with this code as it is, when I try to load the panel I get the following error from fire bug...

TypeError: c is undefined

But if I comment out
'store : 'Contact','
for the grid it works fine. Is there something I'm doing wrong when I'm connecting the store or there is something wrong with the store itself???

glopes
23 May 2013, 7:38 AM
Hi,

I've noticed that you have added some invalid options to your store and set your api values without quotes among other things. Try creating your store like this:



Ext.define('Firm_Matters.store.Contact', {
extend : 'Ext.data.Store',


requires : [
'Firm_Matters.model.Contact'
],


constructor : function (cfg) {
var me = this;
cfg = cfg || {};
me.callParent([Ext.apply({
autoLoad : false,
autoSync : true,
model : 'Firm_Matters.model.Contact',
remoteSort : true,
storeId : 'Contact',
proxy : {
type : 'direct',
afterRequest : function (request, success) {
if (request.action == 'read') {
this.readCallback(request);
}
},
readCallback : function (request) {
if (!request.operation.success) {
Ext.Msg.show({
title : 'Contact Load Error',
msg : 'Could not load contact. Please try again or contact your administrator.',
buttons : Ext.Msg.OK,
icon : Ext.Msg.WARNING
});
}


},
api : {
create : 'Firm_Matters.ContactHandler.Create_Contact',
read : 'Firm_Matters.ContactHandler.Load_Contact',
update : 'Firm_Matters.ContactHandler.Update_Contact',
destroy : 'Firm_Matters.ContactHandler.Delete_Contact'
},
reader : {
type : 'json',
idProperty : 'Contact_RowID',
messageProperty : 'message',
root : 'data'
},
writer : {
type : 'json'
},
listeners : {
exception : {
fn : me.onDirectException,
scope : me
}
}
}
}, cfg)]);
},


onDirectException : function (proxy, response, operation, eOpts) {
Ext.MessageBox.show({
title : 'Remote Exception: Contact',
msg : operation.getError(),
icon : Ext.MessageBox.ERROR,
buttons : Ext.Msg.OK
});


}


});


Regards,

azinyama
23 May 2013, 10:49 AM
Thanks for the help. It's sorted now :)