View Full Version : Use component twice

11 Oct 2010, 5:37 AM

I got a quick question about using the same component twice. In my code I instantiate a new editorgridpanel. Since I need several of these in my app and the only difference between them is the title, width, and url of the JsonStore, I only want to make it once and then set the other options myself.

This is my code:

// Entry point

// The editorgrid I need several times in my app
var editorGrid = new Ext.grid.EditorGridPanel({
autoHeight : true,
autoWidth : true,
header : true,
columns : [],
store : new Ext.data.JsonStore({
url : '...',
remoteSort : true,
fields : [],
viewConfig : { forceFit: true,
onDataChange: function(){this.cm.setConfig(this.ds.reader.jsonData.columns);
emptyText: 'No data found'},
bbar : new Ext.PagingToolbar({
pageSize : 4,
displayInfo : true
listeners : {render : showToolTip,
celldblclick : openNewTab,
beforerender : function(){ this.getBottomToolbar().bindStore(this.store)}},

// Function were I need 2 editorgrids
function newFunction(){
// Make the 1st grid
var gridFirst = editorGrid;
gridFirst.getStore().setBaseParam('source', 'example');
gridFirst.getStore().load({params: {start:0, limit:4}});

// Make the 2nd grid
var gridSecond = editorGrid;
gridSecond.getStore().setBaseParam('source', 'second');
gridSecond.getStore().load({params: {start:0, limit:4}});
This ain't working, but I tried loads of different combinations like:
- new Ext.grid.EditorGridPanel(editorGrid);
- xtype : 'editorgrid', with Ext.Panel
- Etc..

Is this the right way to achieve what I want ? Or do I need to make every editorgrid seperately ?

11 Oct 2010, 5:48 AM
No, you can't use a component twice.

Why not create a function that has 'title', 'width' and 'url' parameters and returns an EditorGridPanel instance?

If your grid becomes more complicated you could also consider extending EditorGridPanel.

11 Oct 2010, 7:01 AM
Thx Condor,

Extending it will be better in my situtation, so I going to do that.