ExtJS动态创建RowExpander

时间:2012-10-30 16:15:24

标签: extjs grid expander

我想用rowexpander创建一个网格。我有一个模板和一个rowexpander,但我不想使用gridpanel的商店来加载rowexpander的模板数据。我想在ajax请求成功案例中动态创建rowexpander(因为我用TODO字表示),并且想要从rowExpanderStore加载数据。任何人都可以帮我怎样才能做到这一点?

我的代码如下,

var rowExpanderStore = new Ext.data.Store({
    root            : 'rowExpanderStoreRoot',
    fields          : [
                       {name: 'caption1'}, {name: 'caption2'}, {name: 'caption3'}, 
                        {name: 'caption4'}, {name: 'caption5'}, {name: 'caption6'}
                    ]
});

var gridPanelStore = new Ext.data.Store({
    successProperty : 'success',
    root            : 'gridPanelStoreRoot',
    fields          : [{name: 'id'}, {name: 'date'}, {name: 'time'}, {name: 'address'}]
});


var myTemplate = new Ext.Template(
        '<table class="bgrGREYlight" width="100%" height="99%">' +
            '<tbody>' +
                '<tr>' +
                    '<th align="left" width="15%" class="tableTEXT2">Address1</th>' +
                    '<td  width="85%" align="left" class="tableTEXT">{address1}</td>' + 
                '</tr>'+
                '<tr>' +
                    '<th align="left" width="15%" class="tableTEXT2">Address2</th>' +
                    '<td  width="85%" align="left" class="tableTEXT">{address2}</td>' + 
                '</tr>'+
            '</tbody>' +
        '</table>'
);
// row expander
myRowExpander = new Ext.ux.grid.RowExpander({
    tpl : template
});


Ext.Ajax.request({
    url     : '/action/loadSmtData',
    success: function ( result, request ) {
        var jsonData = Ext.util.JSON.decode(result.responseText);
        rowExpanderStore.loadData(jsonData);
        // TODO: I want to create template and rowexpander here
        // and I don't want to use grid's store, I want to use another store load template data
    },
    failure: function ( result, request ) {
        Ext.MessageBox.alert('Failed', result.responseText);
    }
});

Detail_Grid = new Ext.grid.GridPanel({
        store       : gridPanelStore,
       loadMask : true,
       maxHeight    : 300,
       autoHeight   : true,
       autoScroll   : true,
       layout       : 'fit',
       viewConfig   : { 
           emptyText        : 'no record found!',
           deferEmptyText   : false,
           forceFit         : true
       },
       autoExpandColumn: 2,
        plugins     : myRowExpander,
       columns      :[
                        myRowExpander,
                        {header: 'id', dataIndex: 'id'},
                        {header: 'date', dataIndex: 'date'},
                        {header: 'time', dataIndex: 'time'},
                        {header: 'address', dataIndex: 'address1'}
                     ]
});

var Detail_Panel = new Ext.Panel({
    title       : 'Detail Panel',
    padding     : 5,
    collapsible : true,
    collapsed   : true,
    items       : [Detail_Grid]
});

0 个答案:

没有答案