2011-04-15 26 views
2

我試圖在主/關係中顯示兩個網格。作爲Ext JS的新手,我修改了一個能夠成功顯示數據的示例 - 無論是主數據還是細節。但我無法將它們加載到兩者。每個網格都有它自己的dataStore,columnModel和gridPanel。Ext Js - 加載兩個網格的問題

我是否需要使用不同的容器來容納gridPanels?我的窗口在配置中是否有語法錯誤?謝謝。


    OrdersGrid = new Ext.grid.EditorGridPanel({ 
     id: 'OrdersGrid', 
     store: OrdersDataStore, 
     cm: OrdersColumnModel, 
     enableColLock:false, 
     clicksToEdit:1, 
     selModel: new Ext.grid.RowSelectionModel({singleSelect:false}) 
    }); 

    ItemsGrid = new Ext.grid.EditorGridPanel({ 
     id: 'ItemsGrid', 
     store: ItemsDataStore, 
     cm: ItemsColumnModel, 
     enableColLock:false, 
     clicksToEdit:1, 
     selModel: new Ext.grid.RowSelectionModel({singleSelect:false}) 
    }); 

    OrdersItemsWindow = new Ext.Window({ 
     id: 'OrdersItemsWindow', 
     title: 'Orders and Items', 
     layout: 'vbox', 
     closable: true, 
     height: 700,   
     width: 800, 
     layoutConfig: { 
     align : 'stretch', 
     pack : 'start', 
     }, 
     plain: false, 
     items: [ OrdersGrid, ItemsGrid ] 
    }); 

    OrdersDataStore.load(); 
    ItemsDataStore.load(); 

    OrdersItemsWindow.show(); 

回答

1

兩個GridPanels需求的高度設置,因爲窗口VBoxLayout不處理這種情況。它只能設置它包含的項目的水平寬度。

例如:

OrdersGrid = new Ext.grid.EditorGridPanel({ 
    id: 'OrdersGrid', 
    store: OrdersDataStore, 
    cm: OrdersColumnModel, 
    enableColLock:false, 
    clicksToEdit:1, 
    flex: 1, // add this line 
    selModel: new Ext.grid.RowSelectionModel({singleSelect:false}) 
}); 

你正在使用的語法的其餘部分是正確的。

或者,可以使用類似height: 200的東西來固定高度,以取代flex參數。

+0

感謝您的建議。我添加到「項目:[{OrdersGrid,flex:1},{ItemsGrid,height:400}]」在我的窗口配置,但沒有得到它顯示(我得到一個空白頁)。我的語法正確嗎? – hadenp 2011-04-16 04:02:23

+0

希望這些編輯更清晰。 – 2011-04-16 04:08:57

1
Ext.onReady(function() { 

    var movieStore = Ext.create("Ext.data.Store", { 
     baseParams: { action: 'movie' }, 
     fields: ["film_id","title", "rent", "buy"], 
     data: [{film_id:1,title: "film_A",rent: 20.0,buy: 30}, 
       {film_id:2,title: "film_B",rent: 20.0,buy: 36}, 
       {film_id:3,title: "film_C",rent :22.0,buy :27}] 

    }); 
    var actorStore = Ext.create("Ext.data.Store", { 
     baseParams: { action: 'actors' }, 
     fields: ["actor_id","name"], 
     data: [{actor_id: 1,name:"A"}, 
       {actor_id: 2,name: "B"}, 
       {actor_id: 3,name :"C"}] 

    }); 

    var movieGrid = Ext.create("Ext.grid.Panel", { 
     store: movieStore, 
     //sm: Ext.create('Ext.grid.RowSelectionModel',{ singleSelect: true }), 
     singleSelect: true, 

     title: "Movies", 
     selType: 'rowmodel', 
     /* plugins: [ 
     Ext.create('Ext.grid.plugin.RowEditing', { 
      clicksToEdit: 2 
     })],*/ 

     columnLines: true, 
     width: 600, 
     height: 200, 
     columns: [ 
        {xtype : "rownumberer"}, 
        {text: 'film_ID',dataIndex: 'film_id'}, 
        {text: 'Movie',dataIndex: 'title', editor: 'textfield'}, 
      {text: 'Rent', dataIndex: 'rent',xtype : "numbercolumn",format:"0.00"}, 
      {text: 'Buy', dataIndex: 'buy',xtype:"numbercolumn",format:"0.00"} 


     ], 
     iconCls: 'icon-grid', 
     margin: '0 0 20 0', 
     renderTo: Ext.getBody() 
    }); 

    var actorGrid = Ext.create("Ext.grid.Panel", { 
     store: actorStore, 
     //sm: Ext.create('Ext.grid.RowSelectionModel',{ singleSelect: true }), 
     singleSelect: true, 

     title: "Actor", 
     selType: 'rowmodel', 
     /* plugins: [ 
     Ext.create('Ext.grid.plugin.RowEditing', { 
      clicksToEdit: 2 
     })],*/ 

     columnLines: true, 
     width: 600, 
     height: 200, 
     columns: [ 
        {xtype : "rownumberer"}, 
        {text: 'actor_id',dataIndex: 'actor_id'}, 
        {text: 'name',dataIndex: 'name', editor: 'textfield'}, 



     ], 
     iconCls: 'icon-grid', 
     margin: '0 0 20 0', 
     renderTo: Ext.getBody() 
    }); 

    movieGrid.getSelectionModel().on('rowselect', 
      function(sm, rowIndex, record) { 
      /*moviesGrid.setTitle('Movies starring ' + 
      record.data.first_name + ' ' + record.data.last_name);*/ 
      actorStore.load({ params: { 'movie': 
      record.data.actor_id} }); 
      }); 
      movieStore.load(); 

}); 
+0

你能解釋一下你做了什麼來使這個解決方案有效嗎?一般來說,「有代碼」的答案比有解釋的答案要少。 – jakerella 2014-01-22 20:34:36