PDA

View Full Version : roweditor after adding



Preston85
16 Sep 2009, 2:24 AM
Hi, i'm not sure if this is a bug or an error in my code.

Once i've added an item to a grid using the roweditor I am able to edit and remove it, but this does not call the appropriate php files. The update actual adds the item again with the changes and the remove does remove the item from the grid but the store does not call the delete php file.

If I refresh the grid or do actions on other items they work perfectly, its just some strange behavior after adding.

I've removed some code from around the grid, just a function called to display its tab and the tab panel definitions.



// Define extended grid for use in Proxy attribute of grids.
var contact_edit_editor = new Ext.ux.grid.RowEditor({
saveText: 'Update' // Changes text of the row edit button.
});

// List of Contacts associated to Company
var nameContact_edit = new Ext.form.TextField();
var valueContact_edit = new Ext.form.TextField();

var contact_type_editgrid = new Ext.grid.GridPanel({
title : 'Contact Type',
id : 'contact_type_editgrid',
plugins : [contact_edit_editor], // Use grid extention defined above.
view : new Ext.grid.GroupingView({
markDirty: false
}),
store : contact_type_edit_store,
columns : [
{header: "Id", dataIndex: 'idcontacttype',hidden:true},
{header: "Contact Name", dataIndex: 'nameContact', editor: nameContact_edit},
{header: "Contact Value", dataIndex: 'valueContact', editor: valueContact_edit}
],
tbar: [{
text: 'Add Contact Type',
handler: function(){
var u = new contact_type_editgrid.store.recordType({
idcontacttype : '',
nameContact : '',
valueContact: ''
});
contact_edit_editor.stopEditing();
contact_type_edit_store.insert(0,u);
contact_type_editgrid.getView().refresh();
contact_edit_editor.startEditing(0);
}
},{
text: 'Remove Contact Type',
ref: '../removeBtn',
disabled: true,
handler: function(){
contact_edit_editor.stopEditing();
var s = contact_type_editgrid.getSelectionModel().getSelections();
for(var i = 0, r; r = s[i]; i++){
contact_type_edit_store.remove(r);
}
}

}]
});

contact_type_editgrid.getSelectionModel().on('selectionchange', function(sm){
contact_type_editgrid.removeBtn.setDisabled(sm.getCount() < 1);
});

contact_type_edit_store.reload();


Datastore code.
I commented out the write listener as it was giving an error, maybe thats where the problem is?

// Contact Types

// Proxy settings for built in CRUD functions.
var contact_type_edit_proxy = new Ext.data.HttpProxy({
api: {
create : './optionmanagement/assets/fnc/create_contact_types.php',
read : './optionmanagement/assets/fnc/get_contact_types.php',
update : './optionmanagement/assets/fnc/edit_contact_types.php',
destroy : './optionmanagement/assets/fnc/destroy_contact_types.php'
}
});

// Typical JsonReader. Notice additional meta-data params for defining the core attributes of your json-response
var contact_type_edit_reader = new Ext.data.JsonReader({
totalProperty : 'total',
successProperty : 'success',
idProperty : 'idcontacttype',
root : 'rows'
}, [
{name: 'idcontacttype'},
{name: 'nameContact', allowBlank: false},
{name: 'valueContact', allowBlank: false}
]);

// The new DataWriter component.
var contact_type_edit_writer = new Ext.data.JsonWriter({
encode : true,
writeAllFields : true
});

// Typical datastore of type grouping for roweditor grid.
var contact_type_edit_store = new Ext.data.GroupingStore({
proxy : contact_type_edit_proxy, // Defined above.
reader : contact_type_edit_reader, // Defined above.
writer : contact_type_edit_writer, // Defined above.
autoLoad : true,
autoSave : true, // Automatically save when store is modified.
listeners: {
/*write : function(store, action, result, res, rs) {
App.setAlert(res.success, res.message); // <-- show user-feedback for all write actions
},*/
exception : function(proxy, type, action, options, res, arg) {
if (type === 'remote') {
Ext.Msg.show({
title: 'REMOTE EXCEPTION',
msg: res.message,
icon: Ext.MessageBox.ERROR,
buttons: Ext.Msg.OK
});
}
}
}
});

Thanks.

Preston85
17 Sep 2009, 12:33 AM
Any ideas from fresh eyes?

Preston85
20 Sep 2009, 12:48 PM
It's been 4 days since I posted this, over 50 views but yet not 1 response. I would of thought someone would know something about this, if the Ext support guys don't know I would still expect a response out of courtesy, even if its just that you've seen the issue. Has anyone else used these grids / datastore CRUD methods successfully? Examples of working programs would be a big help.

mjlecomte
20 Sep 2009, 4:09 PM
I'd suggest looking at one of the demos, or post working code someone can test out.

Preston85
21 Sep 2009, 2:24 AM
I'd suggest looking at one of the demos, or post working code someone can test out.

I used the demo's to create this code, most of its is copy and paste from the demo's hence my query about it being a bug or error on my part. I used http://www.extjs.com/deploy/ext-3.0.0/examples/writer/writer.html (http://www.extjs.com/forum/../deploy/ext-3.0.0/examples/writer/writer.html) the datastore code and http://www.extjs.com/deploy/dev/examples/grid/row-editor.html (http://www.extjs.com/forum/../deploy/dev/examples/grid/row-editor.html) for my roweditor grid.

mjlecomte
21 Sep 2009, 3:29 AM
If demo works stands to reason the error is in your code.

Preston85
21 Sep 2009, 5:25 AM
If demo works stands to reason the error is in your code.

Well its hard to tell as i'm using a row-editor but the DataWriter example uses a standard edit grid so mine is a combination of the two.

I suspect its to do with the store side since its the store selecting if it should do add/update/delete but maybe there's some difference between edit grid and row-editor that is causign the issue? Maybe i'm missing a listener or something thats meant to end a Add process and make any subsequent processes on the new row a update/destroy process...

I would of thought combination of row-editor and writer would be a common combination with pleanty of examples of them working together?

Preston85
21 Sep 2009, 5:47 AM
The other idea i've had on why it behaves wierd after a Add is the store not getting a response that the add was successful so is still expecting to add the row, thats also why it won't update/remove it as it doesn't have the id value from the db and trys to add the row again if you Update it.

What does the store expect back from the PHP files when using the datastore Writer ?

ramana_l_v
20 Dec 2009, 5:35 PM
Hey Preston,
Were you able to solve your problem, I am also facing the same issue can you please share what you have done to solve the issue.

Thanks,

Monkee
21 Dec 2009, 2:01 AM
[SOLVED]

I'm using an EditorGridPanel together with LockingGridView plugin.
On "create" I always get an exception, altough the returned json code is well-formated.
Still not found a solution. :-?

My problem was that the root value I used for the reader was different.

Taking the example code of Preston:



var contact_type_edit_reader = new Ext.data.JsonReader({
totalProperty : 'total',
successProperty : 'success',
idProperty : 'idcontacttype',
root : 'rows'
}, [
{name: 'idcontacttype'},
{name: 'nameContact', allowBlank: false},
{name: 'valueContact', allowBlank: false}
]); When you're using that custom value, be sure that the response type, after you insert a new record in your database, is following this pattern:
{"success":true,"message":"Record added!","rows":{"id":"4b2f5226-1c38-448e-96ac-74dac0a80126","name":"New record"}}


Because I was heavily inspired by the demos, I thought that the store/writer/reader were expecting the "data" object, but be careful to stick to that value you setup in the reader across all CRUD operations.
Hope this helps!

ramana_l_v
24 Dec 2009, 2:40 PM
This worked..... thats a lot

aliasneo
31 Dec 2009, 7:13 PM
Thank you Monkee -- been looking around for the proper JSON response format after a CRUD "Create" operation.

Preston85
2 Jan 2010, 2:01 AM
Hey Preston,
Were you able to solve your problem, I am also facing the same issue can you please share what you have done to solve the issue.

Thanks,

Sorry for the slow reply and that I can't help. Was taking to long so went for windows with forms to edit the information (were better for what I was doing anyway).

Have used edit grids since but not with the new datastore method. Will have to dig out a backup with the code and see if I had the same error as you guys but don't think it was.