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