I have a dropdownlist telerik control in a grid working on incell editing model. The annotation of Model class annotation has [UIHint] setting for automatic mapping cell to dropdownlist edit template in edit model. Everything works fine except this: if user click the dropdownlist once, the cell will be marked as "dirty" even no selection changes of the dropdownlist.
In the "OnSave" event, the event args "e" has "dataItem" and "values" property inside which is able to indicate the original value and new value respectively, we can compare them to know if the cell was really changed after editing, but I'm wanna know how to handle "dirty" flag for no change cell (set cell dirty status to false), please help, thanks.
Henry
6 Answers, 1 is accepted
May I have your great comments here? Thanks in advance!
Henry
I'm still expecting the answers...
Thanks
Henry
I tried e.preventDefault(); in OnSave, however this just leaves the cell in edit mode.
I haven't had a change to test this, or work it out, however it appears the grid adds a span inside the cell td when the property is dirty:
<span class="t-dirty">You could probably keep track of the value before and after edit, then clear this if the values are the same.
I'm not sure how this affects the internal mechanics of the grid batch edit functionality... you'd have to check if this clears hasChanges() as well...
We are not sure what the exact requirement is. Could you please clarify?
The hasChanges() is the only official api which the grid provides in this regard.
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
There is no (documented) way to avoid this behaviour...
I sort of hoped that the OnSave event would provide a method of cancelling the edit, but calling e.preventDefault(); from within OnSave simply keeps the cell in edit mode (which semantically makes sense).
I'd say something more appropriate would be an OnChange event like the majority of other controls have... then you could inspect changes to an individual cell and cancel them if required.
In the interim, I proposed a (untested, potential) workaround, that involved tracking changes and removing the t-dirty span from the cell if required; however I'm not sure if the grid maintains a dirty flag elsewhere... i.e. if we removed the span from the cell, is it then considered "clean" and ignored by hasChanges?
Is there another way to cancel a change to a cell?
Most probably something indeed changed and that's why the modified flag is shown. For example if you are editing a number but then your editor template returns a string - this is still considered a change. You can check this by inspecting e.dataItem.Property and e.values.Property. If they are different in any way then the modified flag will be shown.
You can hide the indicator easily but the record will still be considered as changed. Here is how to remove the indicator:
function onSave(e) {
$(e.cell).find(".t-dirty").remove();
}
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items