View Full Version : adding a column to an existing ColumnModel

1 May 2007, 10:43 AM

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?


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

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;

grid.reconfigure(ds, cm);

Does any one help me?


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

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:


The source code:

function AppendColumn() {
var ds = grid.getDataSource();
var cm = grid.getColumnModel();
var colName = prompt('Column name', 'Default');


grid.reconfigure(ds, cm);

var i = cm.getColumnCount() - 1;

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


Would you help me to solve this problem?

Does any one help me?

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.

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

9 May 2007, 8:46 AM
Anybody plz?

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?


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.

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?