PDA

View Full Version : Grid destruction



DrZog
29 May 2007, 6:53 AM
I'm trying to build a graphical tool for building SQL queries using two Ext grids. The first is used to choose the tables, fields, constraints etc. and the second is used to show the results when the query is run.

At the moment I'm trying to destroy the preview grid and rebuild it because of the new column model I need to create and it seems easier then using grid.reconfigure for now.

The issue is that grid.destroy(true) deletes the grid container as well so there is nothing to build the new grid into. Is there something 'between' grid.destroy() and grid.destroy(true) that still leaves a div container?

tryanDLS
29 May 2007, 7:47 AM
What is 'in between' removing the dom element and not removing the dom element? What do you want it to do?

DrZog
29 May 2007, 8:35 AM
Hi Tim, thanks for answering

Because my column model is dynamic, I'm going to the brutal approach at the moment at just destroying the grid and then trying to re-render it:



if(!Resultsgrid){
Resultsds = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({url: 'scripts/JSON_querybuilder.php'}),
reader: new Ext.data.JsonReader({
root: 'BuilderResults',
totalProperty: 'totalCount',
id: 'id_results'
},
dsfields),

baseParams: {tables:t, fields:f, conditions:c, no:i}
});

Resultsds.load();


Resultscm = new Ext.grid.ColumnModel(DynamicColumnModel);


// create the grid
Resultsgrid = new Ext.grid.Grid('ResultsGrid', {
ds: Resultsds,
cm: Resultscm,
autoSizeColumns: true,
loadMask: true
});

Resultsgrid.render();
}else{
Resultscm = null;
Resultscm = new Ext.grid.ColumnModel(DynamicColumnModel);
Ext.apply(Resultsds.baseParams, {tables:t, fields:f, conditions:c, no:i});
Resultsds.load();

Resultsgrid.destroy();

Resultsgrid = new Ext.grid.Grid('ResultsGrid', {
ds: Resultsds,
cm: Resultscm,
autoSizeColumns: true,
loadMask: true
});

Resultsgrid.render();

}



I've looked at all the posts RE dynamic grids and have tried to get grid.reconfigure() to work without success so I'm trying to go this route with this fugly code

tryanDLS
29 May 2007, 9:19 AM
I would think the code in you else block is going to have problems:
1) if you don't grid.destroy(true), the grid container is gone and you have nothing to render into.
2) you probably should grid.destroy(true) before you recreate your cm or load your ds. The grid has pointers to those objects and while the function isn't doing any cleanup related to those, that might not always be the case - in any case it's much easier to understand what's happening if you follow the logical flow - cleanup(destroy), then recreate.

I guess the question is, if you grid.destroy(true), is the dom container preserved? Then when you re-render what happens?

DrZog
29 May 2007, 9:25 AM
Thats the prob though, if I grid.destroy(true), the Div that I render the grid into also gets destroyed :-?

tryanDLS
29 May 2007, 9:33 AM
Guess I'm missing something. If you don't destroy the container is there an issue? If you want to destroy the container, use DomHelper to append it back again before you recreate.

DrZog
29 May 2007, 11:31 AM
Thanks for the hint about Domhelper, I can use it to create a new container Div.

One last stoopid question: Should I wrap the original grid container in another Div then when grid.destroy() removes it, use append or insertFirst ?

tryanDLS
29 May 2007, 11:51 AM
I don't see any reason to do that, unless you need it in a container to use for padding.

DrZog
29 May 2007, 12:15 PM
The things is grid.destroy(true) also deletes the original Div container so I think I need to use Domhelper to add another (in the same place)

tryanDLS
29 May 2007, 12:57 PM
Well you need to add the container div for the grid, so depending on whether you originally had it in the body or some other container that's what you append to the next time. You don't need to put it in a specific place (e.g insertFirst, insertAfter, etc) unless there are other elements in the container that you need the grid to precede for positioning.

DrZog
29 May 2007, 1:28 PM
Great, thanks for the info Tim