PDA

View Full Version : grid validator



rh_it
26 Jun 2013, 4:53 AM
Hello again, I have a grid with three columns, the last column has an editableNumberField; the editableNumberField cannot be a number less of 0 or less of the nearby column (dataIndex is 'colTwoNumber'); here it is the newbie question... how can I retrieve the 'colTwoNumber' value!?



validator: function(value){
if (value != '0') {
console.log('ok');
} else {
console.log('no way');
}
}

Farish
26 Jun 2013, 5:09 AM
I am using the following in the validator (I have rowEditing plugin in grid):


var grid = Ext.getCmp('gridID'); // using getCmp() is not the preferred way to access a component, you can use component query etc. instead to get your grid
var otherFieldValue = grid.plugins[0].getEditor().getValues().otherField;
// then you can do comparison with the value variable
// where otherField is the dataIndex of the other column you want to compare with.

rh_it
26 Jun 2013, 5:35 AM
mmh...does it work with cellEditingPlugin ?

Farish
26 Jun 2013, 5:55 AM
try and find out :)

rh_it
26 Jun 2013, 6:00 AM
seems to not working...or maybe I'm doing something wrong...
it says
Uncaught TypeError: Cannot call method 'getItemId' of undefined

Farish
26 Jun 2013, 6:02 AM
hmmm. may be in cellEditor, you dont have access to the values.


grid.plugins[0].getEditor()

this should return the cellEditing plugin but then you have to see if there is some method of the cellEditing plugin which allows you to get values. if not, this approach wont work...

rh_it
26 Jun 2013, 6:12 AM
mmh...then what should I do to get the other column-cell value?

Farish
26 Jun 2013, 6:14 AM
if you can someone access the record being edited, then you can get this info...

friend
26 Jun 2013, 6:44 AM
There's a small caveat to be aware of when using the CellEditing plugin: If your editing components are declared as xtypes, a component won't actually be instantiated until the first time you enter a cell to perform an edit.

This can be problematic if you want to get the value from the editing component in the next column over, but you haven't actually navigated to that cell to trigger instantiation of the editing component. In this case, if you attempt to reference the next columns editing component, you'll be returned an xtype config and not the actual component...

Farish
26 Jun 2013, 6:44 AM
ok. I have found a solution but it doesnt look so elegant. may be someone else can suggest something better but for now, it should get you going.

add a listener for the beforeedit event of the cellediting plugin. there you have the editor and event available as parameter:


listeners:
{
beforeedit: function(editor, e)
{
console.log(editor.record.get('otherFieldName')); // from the record, you can get the value of any field you like
}
}

you now have to compare this value in the validator function. you can do it by using a variable which is accessible to both functions (like a global var).