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         this.toolbar.items = nitems;
42         
43         delete config.toolbar;
44     }
45     
46     this.wrapper.dom.appendChild(config.grid.getGridEl().dom);
47     config.el = this.wrapper;
48     
49     Roo.bootstrap.panel.Grid.superclass.constructor.call(this, config);
50     
51   
52     // xtype created footer. - not sure if will work as we normally have to render first..
53     if (this.footer && !this.footer.el && this.footer.xtype) {
54         
55         var ctr = this.grid.getView().getFooterPanel(true);
56         this.footer.dataSource = this.grid.dataSource;
57         this.footer = Roo.factory(this.footer, Roo);
58         this.footer.render(ctr);
59         
60     }
61     
62     
63     config.grid.monitorWindowResize = false; // turn off autosizing
64     config.grid.autoHeight = false;
65     config.grid.autoWidth = false;
66     this.grid = config.grid;
67     this.grid.getGridEl().replaceClass("x-layout-inactive-content", "x-layout-component-panel");
68     
69      
70 };
71
72 Roo.extend(Roo.bootstrap.panel.Grid, Roo.bootstrap.panel.Content, {
73     getId : function(){
74         return this.grid.id;
75     },
76     
77     /**
78      * Returns the grid for this panel
79      * @return {Roo.bootstrap.Table} 
80      */
81     getGrid : function(){
82         return this.grid;    
83     },
84     
85     setSize : function(width, height){
86         if(!this.ignoreResize(width, height)){
87             var grid = this.grid;
88             var size = this.adjustForComponents(width, height);
89             grid.getGridEl().setSize(size.width, size.height);
90             /*
91             var thd = grid.getGridEl().select('thead',true).first();
92             var tbd = grid.getGridEl().select('tbody', true).first();
93             if (tbd) {
94                 tbd.setSize(width, height - thd.getHeight());
95             }
96             */
97             grid.autoSize();
98         }
99     },
100      
101     
102     
103     beforeSlide : function(){
104         this.grid.getView().scroller.clip();
105     },
106     
107     afterSlide : function(){
108         this.grid.getView().scroller.unclip();
109     },
110     
111     destroy : function(){
112         this.grid.destroy();
113         delete this.grid;
114         Roo.bootstrap.panel.Grid.superclass.destroy.call(this); 
115     }
116 });