Roo/bootstrap/panel/Grid.js
[roojs1] / Roo / bootstrap / panel / Grid.js
1
2 /**
3  * @class Roo.bootstrap.panel.Grid
4  * @extends Roo.bootstrap.panel.Content
5  * @constructor
6  * Create a new GridPanel.
7  * @cfg {Roo.bootstrap.Table} grid The grid for this panel
8  * @param {Object} config A the config object
9   
10  */
11
12
13
14 Roo.bootstrap.panel.Grid = function(config){
15     
16   
17     this.wrapper = Roo.DomHelper.append(document.body, // wrapper for IE7 strict & safari scroll issue
18         {tag: "div", cls: "x-layout-grid-wrapper x-layout-inactive-content"}, true);
19
20     
21     if(config.toolbar){
22         var tool_el = this.wrapper.createChild();    
23         this.toolbar = Roo.factory(config.toolbar);
24         var ti = [];
25         if (config.toolbar.items) {
26             ti = config.toolbar.items ;
27             delete config.toolbar.items ;
28         }
29         
30         var nitems = [];
31         this.toolbar.render(tool_el);
32         for(var i =0;i < ti.length;i++) {
33           //  Roo.log(['add child', items[i]]);
34             nitems.push(this.toolbar.addxtype(Roo.apply({}, ti[i])));
35         }
36         this.toolbar.items = nitems;
37         
38         delete config.toolbar;
39     }
40     
41     Roo.bootstrap.panel.Grid.superclass.constructor.call(this, config);
42     
43     config.grid.monitorWindowResize = false; // turn off autosizing
44     config.grid.autoHeight = false;
45     config.grid.autoWidth = false;
46     
47     this.grid = new config.grid.xns[config.grid.xtype](config.grid);
48     
49     if (config.background) {
50         // render grid on panel activation (if panel background)
51         this.on('activate', function(gp) {
52             if (!gp.grid.rendered) {
53                 gp.grid.render(el);
54                 gp.grid.getGridEl().replaceClass("roo-layout-inactive-content", "roo-layout-component-panel");               
55
56             }
57         });
58             
59     } else {
60         this.grid.render(this.wrapper);
61         this.grid.getGridEl().replaceClass("roo-layout-inactive-content", "roo-layout-component-panel");               
62
63     }
64     //this.wrapper.dom.appendChild(config.grid.getGridEl().dom);
65     // ??? needed ??? config.el = this.wrapper;
66     
67     
68     
69   
70     // xtype created footer. - not sure if will work as we normally have to render first..
71     if (this.footer && !this.footer.el && this.footer.xtype) {
72         
73         var ctr = this.grid.getView().getFooterPanel(true);
74         this.footer.dataSource = this.grid.dataSource;
75         this.footer = Roo.factory(this.footer, Roo);
76         this.footer.render(ctr);
77         
78     }
79     
80     
81     
82     
83      
84 };
85
86 Roo.extend(Roo.bootstrap.panel.Grid, Roo.bootstrap.panel.Content, {
87     getId : function(){
88         return this.grid.id;
89     },
90     
91     /**
92      * Returns the grid for this panel
93      * @return {Roo.bootstrap.Table} 
94      */
95     getGrid : function(){
96         return this.grid;    
97     },
98     
99     setSize : function(width, height){
100         if(!this.ignoreResize(width, height)){
101             var grid = this.grid;
102             var size = this.adjustForComponents(width, height);
103             var gridel = grid.getGridEl();
104             gridel.setSize(size.width, size.height);
105             /*
106             var thd = grid.getGridEl().select('thead',true).first();
107             var tbd = grid.getGridEl().select('tbody', true).first();
108             if (tbd) {
109                 tbd.setSize(width, height - thd.getHeight());
110             }
111             */
112             grid.autoSize();
113         }
114     },
115      
116     
117     
118     beforeSlide : function(){
119         this.grid.getView().scroller.clip();
120     },
121     
122     afterSlide : function(){
123         this.grid.getView().scroller.unclip();
124     },
125     
126     destroy : function(){
127         this.grid.destroy();
128         delete this.grid;
129         Roo.bootstrap.panel.Grid.superclass.destroy.call(this); 
130     }
131 });