简体   繁体   English

如何通过ID选择Extjs网格并将其显示在面板上

[英]How to select an Extjs grid by Id and display it on the panel

I have created an array with data, a store with this data and a grid. 我创建了一个包含数据的数组,一个包含此数据的存储区和一个网格。 All these exist inside a callback ajax function (the array with the data is the response of a POST request). 所有这些都存在于回调ajax函数中(带有数据的数组是POST请求的响应)。

  var ajaxurl = 'requests/requestKomvus.php', // script to run
        data =  {datastr:datastr}; // data to pass
        $.post(ajaxurl, data, function (response) {
            var myData = [
              ['Company1',71.72,0.02],
             ['Company2',29.01,0.42],
             ['Company3',83.81,0.28],
             ['Company4',52.55,0.01]
             ];


           var store = new Ext.data.ArrayStore({
            fields: [
               {name: 'company'},
               {name: 'price', type: 'float'},
               {name: 'change', type: 'float'},
            ]
          });
          store.loadData(myData);

         var grid = Ext.create('Ext.grid.Panel', {
          store: store,
          columns: [
           {id:'company',header: "Company", width: 160, sortable: true, dataIndex: 'company'},
           {header: "Price", width: 75, sortable: true, dataIndex: 'price'},
           {header: "Change", width: 75, sortable: true, dataIndex: 'change'},
          ],
          stripeRows: true,
          height:940,
          width:500        
        });.... //end of ajax request

What I want is to get the "grid" variable inside my items element: 我想要的是在我的items元素中获取“ grid”变量:

     items: [{
                        xtype: 'panel',
                        title: 'Images',
                        items: [{contentEl:'img',autoScroll:true, height:940 }],


                        },{ 
                        xtype: 'panel',
                        title: 'Material',
                        items: [{contentEl:'msg',autoScroll:true,height:940 }]
                        },
                        {   
                        xtype: 'panel',
                        title: 'Check',
                        items: [grid],  //// how to put it here?
                        }]
            }],renderTo : Ext.getBody()

Is there some straight forward way doing this using extjs? 是否有一些使用extjs的直接方法? For example defining in my grid an Id and then get the variable with this id? 例如,在我的网格中定义一个ID,然后获取具有该ID的变量?

After re-reading the question. 重新阅读问题后。 First of all, declare everything outside the AJAX call. 首先,在AJAX调用之外声明所有内容。 Declare the store, data & grid outside. 在外部声明存储,数据和网格。 Then in your panel, you must simply put your grid on the items array: 然后,在面板中,您只需将网格放在items数组上:

var store = ....
var grid = ...

// ...
{   
    xtype: 'panel',
    title: 'Check',
    items: [
        grid
    ]
}

If you need to update your grid data within the AJAX request, you can do it calling loadData as you're doing right now. 如果需要在AJAX请求中更新网格数据,则可以像现在一样通过调用loadData来完成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM