PDA

View Full Version : Why do unchanged cells become blank on ajax updating ?



Pachat
14 Jun 2010, 1:57 PM
I have a GridPanel using a BufferView and a RowEditor :
when I update one cell the other cells of the Row becomes blank. Why ?

Here is my code :

var record_members_listing = Ext.data.Record.create([
{
name: 'id',
type: 'int'
}, {
name: 'name',
type: 'string'
}, {
name: 'usertype',
type: 'string'
}
]);

var reader_members_listing = new Ext.data.JsonReader({
root: 'rows',
idProperty: 'id',
successProperty: 'success',
fields: record_members_listing
});

var store_members_listing = new Ext.data.Store({
storeId: 'id-store_members_listing',
url: './../../my/members_listing.php',
reader: reader_members_listing,
writer: new Ext.data.JsonWriter()
});

var editor_members_listing = new Ext.ux.grid.RowEditor({
id: 'id-editor_members_listing',
saveText: 'OK',
cancelText: 'Cancel',
commitChangesText: 'Please confirm or cancel',
errorText: 'Error'
});

table_members_listing = new Ext.grid.GridPanel({
id: 'id-table_members_listing',
region:'center',
store: store_members_listing,
sm: new Ext.grid.RowSelectionModel({
singleSelect: true
}),
view: new Ext.ux.grid.BufferView({
scrollDelay: false
}),

columns: [
new Ext.grid.RowNumberer(),
{ id: 'id-col', header: '', width: 10, dataIndex: 'id', filterable: true, sortable: true, hidden: true }, {
id: 'name-col',
header: 'Name',
dataIndex: 'name',
editor: { xtype: 'textfield'}
}, {
id: 'name-col',
header: 'User Type',
dataIndex: 'usertype',
editor: {
xtype: 'textfield'
}
}
],
plugins: [ editor_members_listing ],
tbar: [],
loadMask: true,
listeners: {
beforerender: function( gridpanel ) {
store_members_listing.load();
}
}
});
When User Type is unchanged
JSON sent is :

{"success":true,"rows":{"name":"Christopher SMITH","id":"608"}}and this blanks the "User Type" in the row,

as when I change also the User Type JSON sent is :

{"success":true,"rows":{"name":"Christopher SMITH","usertype":"member", "id":"608"}}which shows correct in the row.

Do I have to transmit all the fields in the row?
Or to take a specific action?
Or some parameter to set to keep showing the unchanged cells of the row?

darthwes
14 Jun 2010, 2:36 PM
Yes you must transmit all the fields...

Pachat
15 Jun 2010, 2:42 AM
Yes you must transmit all the fields...
Thank you for the hint.
It seems that only the modified cells are transmitted + the id by the RowEditor.
Where can I set or change something to have all cells transmitted ?

Another solution would be to ask the server to request the full row and send it back.

The best solution would still be to have no modification after the response from the server,
or only the cells that deserve it without blanking the others.

For the present, I fire a load() :

var editor_members_listing = new Ext.ux.grid.RowEditor({
id: 'id-editor_members_listing',
saveText: 'OK',
cancelText: 'Cancel',
commitChangesText: 'Please confirm or cancel',
errorText: 'Error',
listeners : {
afteredit : {
fn : function(rowEditor, obj, data, rowIndex ){
store_members_listing.load(); }
}
});
which is not very good because it jumps to the begining of the table, loosing the focus.
(better would be to refresh only the row : how ?)

Animal
15 Jun 2010, 2:45 AM
http://www.sencha.com/deploy/dev/docs/?class=Ext.data.JsonWriter&member=writeAllFields

Pachat
15 Jun 2010, 3:33 AM
http://www.sencha.com/deploy/dev/docs/?class=Ext.data.JsonWriter&member=writeAllFields
Thousand thanks, Animal : it does the job !

darthwes
15 Jun 2010, 2:31 PM
Sorry for being useless, I appreciate code being given. I just pasted your code and saw initial load wasn't sending all fields... Thanks Animal.

Pachat
15 Jun 2010, 3:09 PM
A functional side effect of this is that the server receiving now all the fields does not know anymore which ones have been changed.
For instance, let suppose I have some actions to take when the usertype changes.

Of course, I can retreive the old values from the database, make a comparison and decide if anything has to be done if the usertype appears changed. Well that's a bit heavy.

Is there an elegant way to send to the server the old values from the client ? So if the usertype goes from, let say, Author to Admin, the rigth actions can be taken altogether with the updating ?