yd290276
28 Sep 2010, 2:56 PM
Hello all,
i've got a problem with roweditor when i want to programmatically set a column editable or not.
I've got a simple grid with two columns 'id' and 'description'. Column 'id' is not editable for existing rows and 'description' is always editable.
My case is that when i want to add a new row (says with an 'add' button), i want to set the column 'id' editable ONLY at this time.
So i use grid method 'setEditable' with argument 'true' to allow user to input data in 'id' column. In addition i call roweditor 'initFields' (or refreshFields closely the same) to reinit fields.
The problem is that when i click 'add' button the first time, all is ok and i can input data in the two fields. But when i save or cancel and want to edit an existing row, i see three fields :
> A display field : the data of column 'id' that is set to uneditable
> An input field : the field to input data for column 'id' that i previously set as editable
> An input field : the field to input data for column 'description' that is always editable
After debugging, i saw that roweditor 'initFields' method use this.removeAll(false), so the input fields are never removed from DOM.
I tried to modify this method by line :
initFields: function(){
var cm = this.grid.getColumnModel(), pm = Ext.layout.ContainerLayout.prototype.parseMargins;
this.removeAll(true);
if(this.displayFields){
Ext.each(this.displayFields, function(){
this.destroy();
});
this.displayFields = [];
}
But it appears that if i do this, DOM elements are removed but the column editor property is not removed and editor is still known as 'rendered'. So the following code in roweditor 'initFields' method throw an error :
for(var i = 0, len = cm.getColumnCount(); i < len; i++){
var c = cm.getColumnAt(i),
ed = c.getEditor();
if(!ed){
if(c.displayEditor){
ed = c.displayEditor;
} else{
ed = new Ext.form.DisplayField({html:' ',style:{minHeight:'1px'}});
if(!this.displayFields)
this.displayFields = [];
this.displayFields.push(ed);
}
} else if(ed.rendered){
this.getLayout().configureItem(ed);
}
Does someone has any idea of how to toggle the column editable property ? Note that as an alternative i could show a popup window to enter new data instead of editing data in a new row in the grid. But i don't want to use this alternative.
As a quick and dirty, my current solution is :
> Modify roweditor 'initFields' method and call 'this.removeAll(true)'
> Reconfigure my columnmodel each time i need (i know when my code calls 'initFields')
But i think there should be a better way to accomplish this.
Thanks for your help !
i've got a problem with roweditor when i want to programmatically set a column editable or not.
I've got a simple grid with two columns 'id' and 'description'. Column 'id' is not editable for existing rows and 'description' is always editable.
My case is that when i want to add a new row (says with an 'add' button), i want to set the column 'id' editable ONLY at this time.
So i use grid method 'setEditable' with argument 'true' to allow user to input data in 'id' column. In addition i call roweditor 'initFields' (or refreshFields closely the same) to reinit fields.
The problem is that when i click 'add' button the first time, all is ok and i can input data in the two fields. But when i save or cancel and want to edit an existing row, i see three fields :
> A display field : the data of column 'id' that is set to uneditable
> An input field : the field to input data for column 'id' that i previously set as editable
> An input field : the field to input data for column 'description' that is always editable
After debugging, i saw that roweditor 'initFields' method use this.removeAll(false), so the input fields are never removed from DOM.
I tried to modify this method by line :
initFields: function(){
var cm = this.grid.getColumnModel(), pm = Ext.layout.ContainerLayout.prototype.parseMargins;
this.removeAll(true);
if(this.displayFields){
Ext.each(this.displayFields, function(){
this.destroy();
});
this.displayFields = [];
}
But it appears that if i do this, DOM elements are removed but the column editor property is not removed and editor is still known as 'rendered'. So the following code in roweditor 'initFields' method throw an error :
for(var i = 0, len = cm.getColumnCount(); i < len; i++){
var c = cm.getColumnAt(i),
ed = c.getEditor();
if(!ed){
if(c.displayEditor){
ed = c.displayEditor;
} else{
ed = new Ext.form.DisplayField({html:' ',style:{minHeight:'1px'}});
if(!this.displayFields)
this.displayFields = [];
this.displayFields.push(ed);
}
} else if(ed.rendered){
this.getLayout().configureItem(ed);
}
Does someone has any idea of how to toggle the column editable property ? Note that as an alternative i could show a popup window to enter new data instead of editing data in a new row in the grid. But i don't want to use this alternative.
As a quick and dirty, my current solution is :
> Modify roweditor 'initFields' method and call 'this.removeAll(true)'
> Reconfigure my columnmodel each time i need (i know when my code calls 'initFields')
But i think there should be a better way to accomplish this.
Thanks for your help !