kadams54
3 May 2007, 8:54 AM
I have a page that includes two scripts: one script is reused across the app to create the layout (a derivative of the complex layout example). The other script is specific to that page and builds the data grid (a derivative of the inline editing example) for display in the center area of the layout. It should fill the center area and resize as the window resizes or when the user expands the west region.
Two questions...
Based on what I've come across in docs and on the forum, it sounds like I need to:
Build the grid
Add it to a GridPanel
Add the GridPanel to a BorderLayout (pretty much following the inline editing example up to this point)
Add the BorderLayout to a NestedLayoutPanel
Add the NestedLayout to my app's BorderLayout
Is that correct?
Since my grid currently lives in a separate script (and scope) from my app layout, how can the grid script retrieve said layout object and and add itself to the center region?
Here are the trimmed-down code samples:
Layout.js
var Layout = {
init : function(){
layout = new Ext.BorderLayout(document.body, {
hideOnLayout: true,
north: { ... },
west: { ... },
south: { ... },
center: { ... }
});
layout.beginUpdate();
layout.add('north', new Ext.ContentPanel('nav', 'Navigation'));
layout.add('south', new Ext.ContentPanel('status', {title: 'Status', closable: true}));
layout.add('west', new Ext.ContentPanel('search', {title: 'Search'}));
layout.add('center', new Ext.ContentPanel('content', {title: 'Content', closable: false}));
layout.endUpdate();
}
};
Ext.onReady(function() {
Layout.init();
});
CipGrid.js
var CipGrid = {
init: function() {
var grid = this.createGrid('editor-grid');
// create the grid panel
var gridPanel = new Ext.GridPanel(grid);
var gridLayout = Ext.BorderLayout.create({
center: {
margins:{left:3,top:3,right:3,bottom:3},
panels: [gridPanel]
}
}, 'grid-panel');
var nestedPanel = new Ext.NestedLayoutPanel(layout, 'CIP Grid');
// I THINK THERE IS WHERE IT NEEDS TO BE ADDED TO THE APP LAYOUT
// layout.add('center', nestedPanel);
// render it
grid.render();
// add the grid's toolbar
var gridHead = grid.getView().getHeaderPanel(true);
var tb = new Ext.Toolbar(gridHead, [{
text: 'Add CIP',
handler : function(){
var p = new Cip({ ... });
grid.stopEditing();
ds.insert(0, p);
grid.startEditing(0, 0);
}
}]);
},
createGrid: function(id) {
var fm = Ext.form, Ed = Ext.grid.GridEditor;
// the column model has information about grid columns
// dataIndex maps the column to the specific data field in
// the data store (created below)
var cm = new Ext.grid.ColumnModel([{ ... }, ... ]);
// by default columns are sortable
cm.defaultSortable = true;
// this could be inline, but we want to define the CIP record
// type so we can add records dynamically
var Cip = Ext.data.Record.create([ { ... }, ... ]);
// create the Data Store
var ds = new Ext.data.Store({
// load using HTTP
proxy: new Ext.data.HttpProxy({url: 'cips.xml'}),
// the return will be XML, so lets set up a reader
reader: new Ext.data.XmlReader({
// records will have a "cip" tag
record: 'cip'
}, Cip)
});
// create the editor grid
var grid = new Ext.grid.EditorGrid(id, {
ds: ds,
cm: cm,
enableColLock:false
});
// trigger the data store load
ds.load();
return grid;
}
};
Ext.onReady(function() {
CipGrid.init();
});
And finally the HTML:
<div id="content" class="x-layout-inactive-content">
<div id="grid-panel">
<div id="editor-grid"></div>
</div>
</div>
Two questions...
Based on what I've come across in docs and on the forum, it sounds like I need to:
Build the grid
Add it to a GridPanel
Add the GridPanel to a BorderLayout (pretty much following the inline editing example up to this point)
Add the BorderLayout to a NestedLayoutPanel
Add the NestedLayout to my app's BorderLayout
Is that correct?
Since my grid currently lives in a separate script (and scope) from my app layout, how can the grid script retrieve said layout object and and add itself to the center region?
Here are the trimmed-down code samples:
Layout.js
var Layout = {
init : function(){
layout = new Ext.BorderLayout(document.body, {
hideOnLayout: true,
north: { ... },
west: { ... },
south: { ... },
center: { ... }
});
layout.beginUpdate();
layout.add('north', new Ext.ContentPanel('nav', 'Navigation'));
layout.add('south', new Ext.ContentPanel('status', {title: 'Status', closable: true}));
layout.add('west', new Ext.ContentPanel('search', {title: 'Search'}));
layout.add('center', new Ext.ContentPanel('content', {title: 'Content', closable: false}));
layout.endUpdate();
}
};
Ext.onReady(function() {
Layout.init();
});
CipGrid.js
var CipGrid = {
init: function() {
var grid = this.createGrid('editor-grid');
// create the grid panel
var gridPanel = new Ext.GridPanel(grid);
var gridLayout = Ext.BorderLayout.create({
center: {
margins:{left:3,top:3,right:3,bottom:3},
panels: [gridPanel]
}
}, 'grid-panel');
var nestedPanel = new Ext.NestedLayoutPanel(layout, 'CIP Grid');
// I THINK THERE IS WHERE IT NEEDS TO BE ADDED TO THE APP LAYOUT
// layout.add('center', nestedPanel);
// render it
grid.render();
// add the grid's toolbar
var gridHead = grid.getView().getHeaderPanel(true);
var tb = new Ext.Toolbar(gridHead, [{
text: 'Add CIP',
handler : function(){
var p = new Cip({ ... });
grid.stopEditing();
ds.insert(0, p);
grid.startEditing(0, 0);
}
}]);
},
createGrid: function(id) {
var fm = Ext.form, Ed = Ext.grid.GridEditor;
// the column model has information about grid columns
// dataIndex maps the column to the specific data field in
// the data store (created below)
var cm = new Ext.grid.ColumnModel([{ ... }, ... ]);
// by default columns are sortable
cm.defaultSortable = true;
// this could be inline, but we want to define the CIP record
// type so we can add records dynamically
var Cip = Ext.data.Record.create([ { ... }, ... ]);
// create the Data Store
var ds = new Ext.data.Store({
// load using HTTP
proxy: new Ext.data.HttpProxy({url: 'cips.xml'}),
// the return will be XML, so lets set up a reader
reader: new Ext.data.XmlReader({
// records will have a "cip" tag
record: 'cip'
}, Cip)
});
// create the editor grid
var grid = new Ext.grid.EditorGrid(id, {
ds: ds,
cm: cm,
enableColLock:false
});
// trigger the data store load
ds.load();
return grid;
}
};
Ext.onReady(function() {
CipGrid.init();
});
And finally the HTML:
<div id="content" class="x-layout-inactive-content">
<div id="grid-panel">
<div id="editor-grid"></div>
</div>
</div>