source: trunk/web/addons/job_monarch/lib/extjs/examples/grid/RowExpander.js @ 619

Last change on this file since 619 was 619, checked in by ramonb, 15 years ago

lib/:

  • added new AJAX dependancies: ExtJS, pChart, Lightbox2
File size: 4.0 KB
Line 
1/*
2 * Ext JS Library 2.2.1
3 * Copyright(c) 2006-2009, Ext JS, LLC.
4 * licensing@extjs.com
5 *
6 * http://extjs.com/license
7 */
8
9Ext.grid.RowExpander = function(config){
10    Ext.apply(this, config);
11
12    this.addEvents({
13        beforeexpand : true,
14        expand: true,
15        beforecollapse: true,
16        collapse: true
17    });
18
19    Ext.grid.RowExpander.superclass.constructor.call(this);
20
21    if(this.tpl){
22        if(typeof this.tpl == 'string'){
23            this.tpl = new Ext.Template(this.tpl);
24        }
25        this.tpl.compile();
26    }
27
28    this.state = {};
29    this.bodyContent = {};
30};
31
32Ext.extend(Ext.grid.RowExpander, Ext.util.Observable, {
33    header: "",
34    width: 20,
35    sortable: false,
36    fixed:true,
37    menuDisabled:true,
38    dataIndex: '',
39    id: 'expander',
40    lazyRender : true,
41    enableCaching: true,
42
43    getRowClass : function(record, rowIndex, p, ds){
44        p.cols = p.cols-1;
45        var content = this.bodyContent[record.id];
46        if(!content && !this.lazyRender){
47            content = this.getBodyContent(record, rowIndex);
48        }
49        if(content){
50            p.body = content;
51        }
52        return this.state[record.id] ? 'x-grid3-row-expanded' : 'x-grid3-row-collapsed';
53    },
54
55    init : function(grid){
56        this.grid = grid;
57
58        var view = grid.getView();
59        view.getRowClass = this.getRowClass.createDelegate(this);
60
61        view.enableRowBody = true;
62
63        grid.on('render', function(){
64            view.mainBody.on('mousedown', this.onMouseDown, this);
65        }, this);
66    },
67
68    getBodyContent : function(record, index){
69        if(!this.enableCaching){
70            return this.tpl.apply(record.data);
71        }
72        var content = this.bodyContent[record.id];
73        if(!content){
74            content = this.tpl.apply(record.data);
75            this.bodyContent[record.id] = content;
76        }
77        return content;
78    },
79
80    onMouseDown : function(e, t){
81        if(t.className == 'x-grid3-row-expander'){
82            e.stopEvent();
83            var row = e.getTarget('.x-grid3-row');
84            this.toggleRow(row);
85        }
86    },
87
88    renderer : function(v, p, record){
89        p.cellAttr = 'rowspan="2"';
90        return '<div class="x-grid3-row-expander">&#160;</div>';
91    },
92
93    beforeExpand : function(record, body, rowIndex){
94        if(this.fireEvent('beforeexpand', this, record, body, rowIndex) !== false){
95            if(this.tpl && this.lazyRender){
96                body.innerHTML = this.getBodyContent(record, rowIndex);
97            }
98            return true;
99        }else{
100            return false;
101        }
102    },
103
104    toggleRow : function(row){
105        if(typeof row == 'number'){
106            row = this.grid.view.getRow(row);
107        }
108        this[Ext.fly(row).hasClass('x-grid3-row-collapsed') ? 'expandRow' : 'collapseRow'](row);
109    },
110
111    expandRow : function(row){
112        if(typeof row == 'number'){
113            row = this.grid.view.getRow(row);
114        }
115        var record = this.grid.store.getAt(row.rowIndex);
116        var body = Ext.DomQuery.selectNode('tr:nth(2) div.x-grid3-row-body', row);
117        if(this.beforeExpand(record, body, row.rowIndex)){
118            this.state[record.id] = true;
119            Ext.fly(row).replaceClass('x-grid3-row-collapsed', 'x-grid3-row-expanded');
120            this.fireEvent('expand', this, record, body, row.rowIndex);
121        }
122    },
123
124    collapseRow : function(row){
125        if(typeof row == 'number'){
126            row = this.grid.view.getRow(row);
127        }
128        var record = this.grid.store.getAt(row.rowIndex);
129        var body = Ext.fly(row).child('tr:nth(1) div.x-grid3-row-body', true);
130        if(this.fireEvent('beforecollapse', this, record, body, row.rowIndex) !== false){
131            this.state[record.id] = false;
132            Ext.fly(row).replaceClass('x-grid3-row-expanded', 'x-grid3-row-collapsed');
133            this.fireEvent('collapse', this, record, body, row.rowIndex);
134        }
135    }
136});
Note: See TracBrowser for help on using the repository browser.