Results 1 to 2 of 2

Thread: regarding rendering gridpanel

  1. #1
    Sencha User
    Join Date
    Sep 2009
    Posts
    81

    Default regarding rendering gridpanel

    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
    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
                });
                Ext.Ajax.request({
                    url: url,
                    disableCaching: false,
                    success: function (response) {
                        DrawGrid(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 () {
                        grid.show()
                    });
                    store.load();
                }
                return this;
            }
        }
    } (); //this initialise this class
    var newGrid = myNS.myClass.initGrid(config);

  2. #2
    Sencha User tobiu's Avatar
    Join Date
    May 2007
    Location
    Munich (Germany)
    Posts
    2,751

    Default

    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:

    Code:
    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,
    tobiu
    Best regards
    Tobias Uhlig

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •