PDA

View Full Version : adding a column to an existing ColumnModel



raphinou
1 May 2007, 10:43 AM
Hi,

I'm looking at adding a column to an existing ColumnModel. I'm using one datastore and a corresponding grid and columnmodel in several places in my application to display data only. Now I want to add it in another place with an additional column to let the user link an entry to his account. I'd like to include the same columnmodel I have defined in a file I reuse each time I need it, and just add the new column. Is this possible?

Raph

jsakalos
1 May 2007, 12:31 PM
Grid has (perhaps undocumented) method reconfigure. Look in source.

ncminhtung1979
4 May 2007, 6:39 PM
I insert a column in already ColumnModel. After inserting, I reconfigure it. I get a problem: although the width header is equal width that I defined, but width column is less than header column. Example is below:

function AppendColumn() {
var fm = Ext.form, Ed = Ext.grid.GridEditor;
var ds = grid.dataSource;
var cm = grid.getColumnModel();

cm.config.push({"header":"NewColumn","dataIndex":"name","width":"70","editor":new Ed(new fm.TextField({allowBlank: false}))});

var i = cm.getColumnCount() - 1;
cm.setColumnWidth(i,70);

grid.reconfigure(ds, cm);
}

Does any one help me?

Ca

jsakalos
5 May 2007, 1:44 AM
Try to call grid.autoSize()

ncminhtung1979
5 May 2007, 11:36 AM
Thank you jsakalos. I tried grid.autoSize() but column width is still less than header width. I show you my rule for create new column:

- Firstly, I load source from XML then I config it to ext grid
- Secondly, I keep my source, my column. For now, column is multi array demension (Json). I push an element to it, then I cal grid.reconfig() again. A new column appears. But the problem is width column header and width column is not the same like image below:

308

The source code:

function AppendColumn() {
var ds = grid.getDataSource();
var cm = grid.getColumnModel();
var colName = prompt('Column name', 'Default');
cm.config.push({"header":colName,"dataIndex":"sequence","width":80,"editable":false});

grid.autoSize();

grid.reconfigure(ds, cm);

var i = cm.getColumnCount() - 1;
cm.setColumnWidth(i,70);
}

When going on "Append button", new column appears but the layout of header column breaks like image below:

309


Would you help me to solve this problem?

Does any one help me?

jsakalos
5 May 2007, 11:44 AM
I have no practical experiences with this. What I would look at would be config parameters: autoSizeColumns, autoSizeHeaders, methods: setColumnWidth, fitColumns and similar stuff.

ferlycreator
8 May 2007, 12:49 AM
I have same problem,who answer the question?

pomata
9 May 2007, 8:46 AM
Anybody plz?

wwgtsc
29 May 2007, 12:47 PM
I'm having the same problem. I'm wondering if it is due to the fact that the initial Ext.data.Store was created with a reader looking for a certain number of columns, and now we're changing that number of columns on the fly? Yes, we're updating the ColumnModel, but is there something we need to do to the data store as well?

Bill

tryanDLS
29 May 2007, 1:03 PM
I would think you will have a problem if your colModel isn't in sync with the record defined in the store. There was another thread today where a proposed addField method was posted to handle this situation.

Animal
29 May 2007, 11:31 PM
If the Store contains the data item that you want, then the Store doesn't need changing does it?

Does the Store contain the data item from which this new column should draw its value?