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.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.title == 'Log Grid'){
113             Roo.log(this);
114             Roo.log(this.lastSize);
115             Roo.log(this.el.isVisible());
116         }
117         
118         if(!this.ignoreResize(width, height)){
119             Roo.log('Run grid resize!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!');
120             Roo.log([width, height]);
121             var grid = this.grid;
122             var size = this.adjustForComponents(width, height);
123             Roo.log(size);
124             var gridel = grid.getGridEl();
125             Roo.log(gridel);
126             gridel.setSize(size.width, size.height);
127             /*
128             var thd = grid.getGridEl().select('thead',true).first();
129             var tbd = grid.getGridEl().select('tbody', true).first();
130             if (tbd) {
131                 tbd.setSize(width, height - thd.getHeight());
132             }
133             */
134             grid.autoSize();
135         }
136     },
137      
138     
139     
140     beforeSlide : function(){
141         this.grid.getView().scroller.clip();
142     },
143     
144     afterSlide : function(){
145         this.grid.getView().scroller.unclip();
146     },
147     
148     destroy : function(){
149         this.grid.destroy();
150         delete this.grid;
151         Roo.bootstrap.panel.Grid.superclass.destroy.call(this); 
152     }
153 });