113ebdff921552a0a1012820b98bd4480bb35859
[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             var gridel = grid.getGridEl();
116             gridel.setSize(size.width, size.height);
117             /*
118             var thd = grid.getGridEl().select('thead',true).first();
119             var tbd = grid.getGridEl().select('tbody', true).first();
120             if (tbd) {
121                 tbd.setSize(width, height - thd.getHeight());
122             }
123             */
124             grid.autoSize();
125         }
126     },
127      
128     
129     
130     beforeSlide : function(){
131         this.grid.getView().scroller.clip();
132     },
133     
134     afterSlide : function(){
135         this.grid.getView().scroller.unclip();
136     },
137     
138     destroy : function(){
139         this.grid.destroy();
140         delete this.grid;
141         Roo.bootstrap.panel.Grid.superclass.destroy.call(this); 
142     }
143 });