View Full Version : How to check for duplicates in EditorGridPanel

17 Dec 2010, 4:34 AM

I am trying to check for duplicates in an EditorGridPanel column such that when a user edits a textfield (the column's editor is Ext.form.TextField) in a column, before applying it to the underlying store, the *edited* value is checked to ensure it does not already exist in another field in the same column (and if it does I can reject the change). I was listening on the change event for the field, then running through the store (specifically that column) and comparing values; now when I looped through the store, the newly edited value appeared in the store, so I could count the number of entries thus (we are assuming that there is a duplicate entered for the purposes of this discussion):

var grid_vip_change_listener = window.grid_vip_change_listener = function( obj, new_value, old_value ) {
var i = 0;
var dups = 0;

while( i < store.getCount() ) {
if( (store.getAt( i++ )).data['hostname'] == new_value )

if( dups > 1 ) {
Ext.Msg.alert( "Duplicate value", "That value already exists - reverting back" );
And under Ubuntu/Firefox that worked fine because the store value came back as the edited one, so it counted two and I could spot the duplicate! However, when running under Windows 7 (firefox or IE) the store value returned in actually the original one before editing and thus dups never gets incremented past one when there is a duplicate (yes, different behaviour on different OS's).

I do not want to check for duplicates when the store is saved back because I do not want to reject changes on all of the store (user may have added/removed rows, done more changes etc) and of course after the fact - which one is the changed one - I know I can test for value changed, but if they change two rows to create a duplicate - then which one to revert!

Ideally I would like to know in the change listener for the textfield which row is being edited by ID so I can ignore that row in comparing the new_value for duplicates and revert back the specific field if it would be a duplicate (I know above I am rejecting all changes - but at the moment I cannot locate in the store which specific row/field is being edited! In the obj I get sent in the change listener the id is the id of the textfield, not that of the row/field!

So I've struggled for a couple of days and hit a dead end - anyone have any ideas?