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