b6b446c2525019cb23770aeace71deea04bbb0ea
[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.container) {
25         // ctor'ed from a Border/panel.grid
26         
27         
28         this.wrapper.setStyle("overflow", "hidden");
29         this.wrapper.addClass('roo-grid-container');
30
31     }
32     
33     
34     if(config.toolbar){
35         var tool_el = this.wrapper.createChild();    
36         this.toolbar = Roo.factory(config.toolbar);
37         var ti = [];
38         if (config.toolbar.items) {
39             ti = config.toolbar.items ;
40             delete config.toolbar.items ;
41         }
42         
43         var nitems = [];
44         this.toolbar.render(tool_el);
45         for(var i =0;i < ti.length;i++) {
46           //  Roo.log(['add child', items[i]]);
47             nitems.push(this.toolbar.addxtype(Roo.apply({}, ti[i])));
48         }
49         this.toolbar.items = nitems;
50         
51         delete config.toolbar;
52     }
53     
54     Roo.bootstrap.panel.Grid.superclass.constructor.call(this, config);
55     config.grid.scrollBody = true;;
56     config.grid.monitorWindowResize = false; // turn off autosizing
57     config.grid.autoHeight = false;
58     config.grid.autoWidth = false;
59     
60     this.grid = new config.grid.xns[config.grid.xtype](config.grid);
61     
62     if (config.background) {
63         // render grid on panel activation (if panel background)
64         this.on('activate', function(gp) {
65             if (!gp.grid.rendered) {
66                 gp.grid.render(this.wrapper);
67                 gp.grid.getGridEl().replaceClass("roo-layout-inactive-content", "roo-layout-component-panel");   
68             }
69         });
70             
71     } else {
72         this.grid.render(this.wrapper);
73         this.grid.getGridEl().replaceClass("roo-layout-inactive-content", "roo-layout-component-panel");               
74
75     }
76     //this.wrapper.dom.appendChild(config.grid.getGridEl().dom);
77     // ??? needed ??? config.el = this.wrapper;
78     
79     
80     
81   
82     // xtype created footer. - not sure if will work as we normally have to render first..
83     if (this.footer && !this.footer.el && this.footer.xtype) {
84         
85         var ctr = this.grid.getView().getFooterPanel(true);
86         this.footer.dataSource = this.grid.dataSource;
87         this.footer = Roo.factory(this.footer, Roo);
88         this.footer.render(ctr);
89         
90     }
91     
92     
93     
94     
95      
96 };
97
98 Roo.extend(Roo.bootstrap.panel.Grid, Roo.bootstrap.panel.Content, {
99     getId : function(){
100         return this.grid.id;
101     },
102     
103     /**
104      * Returns the grid for this panel
105      * @return {Roo.bootstrap.Table} 
106      */
107     getGrid : function(){
108         return this.grid;    
109     },
110     
111     setSize : function(width, height){
112         if(!this.ignoreResize(width, height)){
113             var grid = this.grid;
114             var size = this.adjustForComponents(width, height);
115             // tfoot is not a footer?
116           
117             
118             var gridel = grid.getGridEl();
119             gridel.setSize(size.width, size.height);
120             
121             var tbd = grid.getGridEl().select('tbody', true).first();
122             var thd = grid.getGridEl().select('thead',true).first();
123             var tbf= grid.getGridEl().select('tfoot', true).first();
124
125             if (tbf) {
126                 size.height -= thd.getHeight();
127             }
128             if (thd) {
129                 size.height -= thd.getHeight();
130             }
131             
132             tbd.setSize(size.width, size.height );
133             // this is for the account management tab -seems to work there.
134             var thd = grid.getGridEl().select('thead',true).first();
135             //if (tbd) {
136             //    tbd.setSize(size.width, size.height - thd.getHeight());
137             //}
138              
139             grid.autoSize();
140         }
141     },
142      
143     
144     
145     beforeSlide : function(){
146         this.grid.getView().scroller.clip();
147     },
148     
149     afterSlide : function(){
150         this.grid.getView().scroller.unclip();
151     },
152     
153     destroy : function(){
154         this.grid.destroy();
155         delete this.grid;
156         Roo.bootstrap.panel.Grid.superclass.destroy.call(this); 
157     }
158 });