Pergunta

I'm designing a grid in ExtJs 4 that will represent a Map data structure. I have a custom cell editor for the key column in the grid. I want to enforce the fact that the key must be unique among all keys. How do I go about doing this?

At the moment I'm trying to set up a special textfield editor with a custom validator that checks if the user-submitted key value is unique by comparing it to the dataStore's values. Unfortunately, this runs into the issue that the dataStore does not know what is the "current" record and so does not know which record to exclude when checking for duplicates.

^Confusing, right? That's why I think I'm doing it wrong.

Foi útil?

Solução

It's a very good question, and I ended up doing pretty much exactly what you're doing. In order to handle current record so I can exclude it from the lookup I added something like that to the vtype validation function:

unique: function (val, field) {
  // If field has not been changed - don't care about anything else
  if (field.originalValue === undefined || val === field.originalValue) {
    // _trace('unique - original value has not changed'); 
    return true;
  }

  if (!field.isDirty()) {
    // _trace('unique - field is not dirty'); 
    return true;
  }

  // Check you store here...
},
uniqueText: 'Duplicate'

One more note - if you will try to use same validator in the dialogs (as oppose to grid roweditor) - you will need to add more checks because originalValue will not be properly set always (at least I had to do this in 4.0.7 in my application).

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top