View Full Version : regarding rendering gridpanel

7 Mar 2010, 10:46 AM
got a custom class which returns an empty grid.same class does some ajax request and later updates the grid....

var grid = new Ext.grid.EditorGridPanel({
title : 'test title'
grid.renderTo = 'divTop';
//rest all configs, store,tbar .....

is this much enough to render the gridpanel.
or needs to call some methods like grid.render()

//here is miniature of the code

var myNS = {}; //defining a namespace
myNS.myClass = function () { //defining a class
return {
initGrid: function (config) { //defining a method with in class
var grid = new Ext.grid.EditorGridPanel({
title: config.title
url: url,
disableCaching: false,
success: function (response) {
function DrawGrid(response) { //definig private method
//process response.responseXML
var store = new Ext.data.Store({......
grid.renderTo = 'divTop'; //a div in body..
tbar,store,bbar etc.....
store.on('load', function () {
return this;
} (); //this initialise this class
var newGrid = myNS.myClass.initGrid(config);

7 Mar 2010, 12:50 PM
i dislike what you are doing here.
do you have knowledge of design-patterns and object oriented programming?

calling a function that directly calls itself "class".... maybe it's kind of a singleton but i see no sense in this. i definitely prefer extending classes (a grid in this case) or using the factory pattern, like:

function myGrid(foo){
// do logic here
return new Ext.grid.GridPanel({...});

var myGrid1 = myGrid(foo1);
var myGrid2 = myGrid(foo2);

in your case you could directly call the content of the initGrid-function, the whole construct is meaningless (it does not even have a return...).

inside "DrawGrid" you call grid.renderTo. That also is not a good idea. You can render a grind ONE TIME. later on you can exchange the column-model, the store or whatever. so a function calling "grid.render()" may one be used once, so it does not really make sense to even use a function for this.

kind regards,