PDA

View Full Version : Maintaining dirty state of editable data model



jmakeig
30 Jan 2007, 11:41 PM
I'm able to listen to the cellupdated event on an EditableGrid's data model. However, I'd like to encapsulate maintenance of the dirty state of the model into the DataModel itself, so I can just call something like, grid.getDataModel().isDirty().
I imagine I'm going to have to hot-rod AbstractDataModel to maintain its own dirty state. Does this sound like a sensible approach? Has anyone else done something similar? Any guidance would be much appreciated.

Animal
31 Jan 2007, 12:35 AM
If all you want is a single isDirty flag (as opposed to a flag for each cell), then it's a piece of cake to add this.

http://www.yui-ext.com/playpen/yui-ext.0.40/docs/output/YAHOO.ext.grid.AbstractDataModel.html#event-cellupdated

In the handler you are passed:

# this : DataModel
# rowIndex : Number
# columnIndex : Number

So you can set a boolean property in the DataModel to true. You could use YAHOO.extendX to add iisDirty() to return tat boolean, but you don't have to - you can just access it directly.

Even if you wanted a flag for each cell, it would eb quite easy to add like this.

imranprogrammer
14 Sep 2007, 10:45 PM
Hi, I have a check/Uncheck field in Editable Grid.
I want this field , not to contribute in the dirty state of Data Store. How can I do that??

imranprogrammer
14 Sep 2007, 10:46 PM
OR How can I sent the dirty state of a column to always FALSE??

imranprogrammer
14 Sep 2007, 10:46 PM
How can I set the dirty state of a column to always false??

Animal
14 Sep 2007, 11:07 PM
Maybe add a listener for this event: http://extjs.com/deploy/ext/docs/output/Ext.grid.EditorGrid.html#event-afteredit

That fires after the Record that backs the Grid row has been updated.

The Record contains an Array called modified which contains the field names that are modified.

You could use



delete myRecord.modified[myFieldName];


Or you could use http://extjs.com/deploy/ext/docs/output/Ext.grid.EditorGrid.html#event-validateedit

Which fires before the Record is changed, so you could react to the event in your own code, and return false to veto the edit.

imranprogrammer
15 Sep 2007, 1:10 AM
I did it but it still shows the whole record dirty.

Animal
15 Sep 2007, 5:05 AM
You can just clear the flag yourself.

imranprogrammer
17 Sep 2007, 2:15 AM
I did it. It works :D
Thank you ANIMAL !