PDA

View Full Version : Am I using Grid.afteredit correctly?



gordon
2 Mar 2007, 8:01 AM
Jack,

I want to post cell changes back to my application server as they happen. Grid.afteredit seems like the right place to do this. However I have to go through a couple of hoops to simply get at the new value - see the first two lines of the callback below.

Am I doing this in the most effective way? Perhaps you could review the parameter list to the afteredit event - the new value does appear to be available when the event is fired.

Secondly, is creating a new connection the best way to post the update?

Thanks,

Gordon


this.grid = new Ext.grid.EditorGrid(divId, {
...
});
this.grid.on('afteredit', this.afterEdit, this, true);
...
afterEdit : function(grid, row, field, rowIndex, columnIndex){
var ed = this.grid.getColumnModel().getCellEditor(columnIndex, rowIndex);
var value = ed.getValue();

var rowId = row.id;
var url = this.jsonUrl+"update/";
var conn = new Ext.data.Connection();
conn.request({
url: url,
params: {
pageUrl: getPageUrl(),
rowId: rowId,
field: field,
value: value
}
});
},

jack.slocum
2 Mar 2007, 8:24 AM
The original intention was to give you the ability to validate the value before it was set. Unfortunately, it doesn't provide the value in the event, so that makes it kind of worthless. I have completely redone the events, and they will be much more useful. Here's the documentation. This will be in the next Rev.


/**
* @event beforeedit
* Fires before cell editing is triggered. The edit event object has the following properties

* <ul style="padding:5px;padding-left:16px;">
* grid - This grid
* record - The record being edited
* field - The field name being edited
* value - The value for the field being edited.
* row - The grid row index
* column - The grid column index
* cancel - Set this to true to cancel the edit or return false from your handler.
* [/list]
* @param {Object} e An edit event (see above for description)
*/
"beforeedit" : true,
/**
* @event afteredit
* Fires after a cell is edited.

* <ul style="padding:5px;padding-left:16px;">
* grid - This grid
* record - The record being edited
* field - The field name being edited
* value - The value being set
* originalValue - The original value for the field, before the edit.
* row - The grid row index
* column - The grid column index
* [/list]
* @param {Object} e An edit event (see above for description)
*/
"afteredit" : true,
/**
* @event validateedit
* Fires after a cell is edited, but before the value is set in the record. Return false
* to cancel the change. The edit event object has the following properties

* <ul style="padding:5px;padding-left:16px;">
* grid - This grid
* record - The record being edited
* field - The field name being edited
* value - The value being set
* originalValue - The original value for the field, before the edit.
* row - The grid row index
* column - The grid column index
* cancel - Set this to true to cancel the edit or return false from your handler.
* [/list]
* @param {Object} e An edit event (see above for description)
*/
"validateedit" : true

gordon
2 Mar 2007, 8:28 AM
That's excellent - Thanks Jack

jack.slocum
2 Mar 2007, 8:28 AM
Wow, you are fast. :)

vtswingkid
3 Mar 2007, 2:17 PM
in the meantime...

I understand that the afteredit event is called before the new value is stored in the record.
So how do I get the new value? I suppose it is hiding in the editor but how do I get to that editor?

thanks.

buk110
14 Mar 2007, 10:34 AM
in the meantime...

I understand that the afteredit event is called before the new value is stored in the record.
So how do I get the new value? I suppose it is hiding in the editor but how do I get to that editor?

thanks.

Hey, any progress on this question. I'm also unsure of how to use the call afterEdit

soad
16 Mar 2007, 9:31 PM
I used this example to implement back end field validation.
http://yui-ext.com/forum/viewtopic.php?t=3439

and that worked for me.

MD
25 Mar 2007, 3:07 PM
Does afteredit and validateedit occur before or after a cell's custom renderer?

jack.slocum
26 Mar 2007, 1:19 PM
The validateedit allows you to intercept and cancel the edit so it occurs before. The afteredit fires after the edit completes. Since "completes" means updating the data store, which in turns notifies the grid of the change, it would be after the renderer has been called.

MD
26 Mar 2007, 1:43 PM
Thanks, Jack. It's becoming clearer -- although...



The validateedit allows you to intercept and cancel the edit so it occurs before.


beforeedit vs. validateedit? (as you can cancel the edit in beforeedit as well)

tryanDLS
26 Mar 2007, 2:15 PM
I believe beforeEdit is so that you can stop the process before you even allow the user to edit the cell, for example, you might want to disallow an edit of the cell in a given row b/c some other value in the row means it shouldn't be editable.

MD
26 Mar 2007, 2:43 PM
Thanks for the response, tryanDLS. I think the way I understand it now is:

beforeedit -- occurs before the IPE in the cell would even initialize

validateedit -- occurs after ie. user hits enter following changing a value in a cell's IPE, but before it's send to handlers/backend/datastore. Also let's say the user entered a value of 10, hit enter or clicked away. validateedit would check if value >= 5 and since it's not, sets cancel to true.

afteredit -- as Jack described, after everything completes and ds is updated

It's validateedit that I'm not 100% clear on, but I suspect it's somewhat like I figure.

Hani
26 Apr 2007, 9:26 AM
In my case, validateedit is no good since it does a remote async call via DWR.

So I'd like to be able to do a 'rollback' in afteredit, however, this doesn't work in my handler:

record.data[e.field] = e.originalValue

Any idea on how to reset the value in the cell/module afteredit to originalValue?

mystix
26 Apr 2007, 9:33 AM
shouldn't that be
e.record.data[e.field] = e.originalValue; instead?

Ext.data.Record also has a reject() method, so you should be able to do
e.record.reject();in your handler too.

Hani
26 Apr 2007, 9:56 AM
Perfect, reject does exactly what I need. Thanks!

Eloy Vieira
21 Jul 2007, 8:20 AM
The original intention was to give you the ability to validate the value before it was set. Unfortunately, it doesn't provide the value in the event, so that makes it kind of worthless. I have completely redone the events, and they will be much more useful. Here's the documentation. This will be in the next Rev.


/**
* @event beforeedit
* Fires before cell editing is triggered. The edit event object has the following properties

* <ul style="padding:5px;padding-left:16px;">
* grid - This grid
* record - The record being edited
* field - The field name being edited
* value - The value for the field being edited.
* row - The grid row index
* column - The grid column index
* cancel - Set this to true to cancel the edit or return false from your handler.
* [/list]
* @param {Object} e An edit event (see above for description)
*/
"beforeedit" : true,
/**
* @event afteredit
* Fires after a cell is edited.

...etc
*/
"validateedit" : true


hi man, there is a way to get the data of other field in the same row?? exemple: a grid with ID,name columns .. you edit name column and get the ID data of the same row.. is it possible?

thanks

jack.slocum
23 Jul 2007, 1:31 AM
hi man, there is a way to get the data of other field in the same row?? exemple: a grid with ID,name columns .. you edit name column and get the ID data of the same row.. is it possible?

thanks


*record - The record being edited

e.g.

var otherValue = e.record.data['other-field'];

Eloy Vieira
23 Jul 2007, 6:50 AM
*record - The record being edited

e.g.

var otherValue = e.record.data['other-field'];


thanks man!! i already tried to config the record etc.. no sucess!
but now everything runs 100% ..thanks!

themattreid
5 Aug 2009, 12:05 PM
*record - The record being edited

e.g.

var otherValue = e.record.data['other-field'];

Thanks Jack! Exactly the solution I was looking for. :D