View Full Version : How to completety reset grid with empty store and empty ColumnModel ?

23 Nov 2010, 9:00 AM
Hi everybody,

I'm desperately trying to entirely reset a grid but i can't find any solutions.

reconfigure or Condor's override removeColumn doesn't work.
I've always same error : this.config[col] is undefined

Error is here: col =-1 and config is empty so it can't works.

getColumnWidth : function(col) {
var width = this.config[col].width;
if(typeof width != 'number'){
width = this.defaultWidth;
return width;
How can i bypass it ?


23 Nov 2010, 9:28 AM
Needs more code. Your grid is displaying and you want to clear the rows from it? Your grid won't display and you want to configure it to show?

23 Nov 2010, 9:40 AM
The easiest solution is probably to call the grid's reconfigure(store, colModel) method with a minimally configured store and column model.

24 Nov 2010, 1:14 AM
@darthwes : My grid is displaying well and i want to clear both rows and columns.
@Screamy : Store is not a problem. Just have to call removeAll but with reconfigure ColumnModel must been defined with at least a column and i need a grid without any column.

For information, I'm using a dataView and a grid. I add dynamically columns to the grid from the dataview by drag and drop.
Now i want to be able to reset the grid at once.

Thanks for help

24 Nov 2010, 1:51 AM
My removeColumn override also uses setConfig, so that's not the problem.

As you've already concluded, a grid must have at least one column.

You'll have to write some extra code to add a dummy column when removing the last column and remove the dummy column when the first column is added.

24 Nov 2010, 3:38 AM
@Condor : I'm afraid your right. I Don't have choice.

Thanks for your help

24 Nov 2010, 5:50 AM
@Condor :
I add some extra code in your removeColumn override

removeColumn: function(colIndex){
var config = this.config;
this.config = [config[colIndex]];
if(config.length>1) config.splice(colIndex, 1);
else config.splice(colIndex, 1,{header: "dummy", dataIndex: "dummy"});
}but still get the error : "this.config[col] is undefined" in getColumnWidth of ColumnModel
Can't understand where i'm wrong.

24 Nov 2010, 8:59 AM

removeColumn: function(colIndex){
var config = this.config;
this.config = [config[colIndex]];
if (config.length > 1) {
config.splice(colIndex, 1);
} else {
config = [{header: "dummy", dataIndex: "dummy"}];

24 Nov 2010, 9:35 AM
Thanks Condor but still the same error :(
Here my code

/* ColumnModel */
var cm = new Ext.grid.ColumnModel({
// specify any defaults for each column
defaults: {
sortable: true,
menuDisabled: true,
//fixed: true,
editor: new Ext.form.TextField()

columns: [
//{ header: "dummy", width: 50, resizeable: false, id:\'dummy\',dataIndex:\'dummy\',editable:false}

var grid = new Ext.grid.EditorGridPanel({
bodyCssClass: \'field-target\',
store: [],
disableSelection: true,
height: 400,
stripeRows: true,
title: \'Visualisation de la liste en cours de création\',
colModel: cm,
listeners: {
render: initializeExportDragAndDropZone
Two ways to "reset" the grid with the same error:

var nbCol = grid.getColumnModel().getColumnCount();
for(var i=0;i<nbCol;i++)

grid.getColumnModel().setConfig([{header: "dummy", dataIndex: "dummy"}]);

24 Nov 2010, 12:10 PM
The last one shouldn't give any errors.

Can you post a stacktrace of the error (using the <xxx>-debug.js files)?

25 Nov 2010, 1:24 AM
Not sure that's what you mean :

this.config[col] is undefined
Line 48966that pointed the red line in getColumnWidth of ColumnModel :

getColumnWidth : function(col) {
var width = this.config[col].width;
if(typeof width != 'number'){
width = this.defaultWidth;
} return width;

25 Nov 2010, 1:49 AM
Can you post the stacktrace (which methods are calling getColumnWidth)?

25 Nov 2010, 2:32 AM
Sorry don't use it so much :

this.config[col] is undefined
getColumnWidth(Object { name="col"})ext-all-debug.js (ligne 48967)
autoExpand(Object { name="preventUpdate"})ext-all-debug.js (ligne 47133)
layout(Object { name="initial"})ext-all-debug.js (ligne 46695)
refresh(Object { name="headersToo"})ext-all-debug.js (ligne 47291)
onColConfigChange()ext-all-debug.js (ligne 47595)
fire()ext-all-debug.js (ligne 310)
fireEvent()ext-all-debug.js (ligne 54)
setConfig(Object { name="config"}, Object { name="initial"})ext-all-debug.js (ligne 48873)
removeColumn(Object { name="colIndex"})... (ligne 1371)
removeColumn(Object { name="name"}, Object { name="colIndex"})... (ligne 1396)
handler(Object { name="b"}, Object { name="e"})... (ligne 959)
onClick(Object { name="e"})Ext.LinkButton.js (ligne 58)
h(Object { name="e"})ext-all-debug.js (ligne 4615)
[Break on this error] var width = this.config[col].width; ext-all-debug.js (ligne 48967)

25 Nov 2010, 2:40 AM
Your 'autoExpandColumn' no longer exists.

25 Nov 2010, 2:54 AM
Argh so big mistake i didn't saw it.
Works fine.
Thanks a lot Condor