View Full Version : Editable grid with cell status tracking

14 Dec 2006, 12:35 PM
I'm trying to use an editable grid but track the various states that an edited cell is in via color. The behaviour I'm trying to implement is:
user changes a cell value: post the update to the server and mark the cell as "pending" which would show the cell's background in yellow
update succeeded: mark the cell as "changed" which would show the cell's foreground in green
update failed or timeout: mark the cell as "error" which would show the cell's background in red AND revert the cell's value to its previous value
There are a couple of problems I'm having with this: 1) the cellupdated event callback only receives the new value so I don't seem to have access to the old value if the update fails or times out, and 2) I'm using a SelectEditor which passes the bare value back to the cellupdated callback so even if I store an object with some of this extra info in the cell (previous value, status, etc.) its replaced by the editor before my handler is called.

I've sort of hacked around this by appending on some extra info to the value and then stripping it off during the renderer but it doesn't handle the reverting back to the previous value on a failure.

I'm using a JSONDataModel, btw.

Does anyone have any suggestions or examples that might give me some insight into how to implement this behavior?

Thanks in advance.

14 Dec 2006, 12:58 PM
You may be able to do more robust state operations using beforeedit and afteredit on the grid object. I have never done exactly what you are doing so unfortunately I can't offer much more advice.

14 Dec 2006, 6:29 PM
Thanks for the hint. That helped and now I have a good way to maintain the state of a cell properly, but I'm having one more problem: after I receive a response to my POST (via Connect) I update the state table for that cell, but I need to force the cell to be rendered again. I tried Grid.render() and DataModel.fireEvent('datachanged') but then all my rows disappear!

And I can't modify the cell value (via DataModel.setValueAt) because that triggers my cellUpdated handler which results in another post. And in my case, the value hasn't changed - its the meta data that's changed which effects the rendering of the value.

I fell like I'm missing something really simple here...

14 Dec 2006, 6:33 PM
remove the listener, change the data, readd the listener?

14 Dec 2006, 6:50 PM
remove the listener, change the data, readd the listener?

Doh! Remember when I said that I might be missing something simple?

14 Dec 2006, 7:29 PM
:lol: I've done it a million times myself.

14 Dec 2006, 8:16 PM
You could also abandon the cellupdated event all together and use afteredit. Then you can use the standard setValueAt.