简体   繁体   English

如何在ext.panel.Panel中的Ext.js中添加列

[英]How to add Columns in Ext.js within ext.panel.Panel

我的萤幕

Im designing a screen in which the header has a button with certain functionality. 我在设计一个屏幕,其中标题具有一个具有某些功能的按钮。 To acheive this I used 为了达到这个目的,我用了

Ext.panel.Panel

Now I want to add columns within this screen below the header. 现在,我想在此屏幕的标题下方添加列。 This is my code: 这是我的代码:

var screen = Ext.create('Ext.panel.Panel', {
    title: 'Search',
    tools: [{
        xtype: 'button',
        text: 'Click',
        //code here for button functionality
    }],
    layout: 'column',

    items: [{
        text: "column1",
        width: .5
    }, {
        text: "column2",
        width: .5
    }]
})

The error Im getting is that I can get the button to work on the header, but cannot see the columns. 我得到的错误是我可以使按钮在页眉上工作,但看不到列。 Is there a solution to fix this? 有解决此问题的解决方案吗? I have also included the image. 我也包括了图像。 The black rectangle shows how my columns are appearing. 黑色矩形显示我的列的显示方式。

In both Ext 4.1.1 and Ext 4.2.0 the following changes are required in your code: Ext 4.1.1Ext 4.2.0中 ,代码中都需要进行以下更改:

  1. Rename property text to title in the columns config 将属性text重命名为列配置中的title
  2. In the same config, rename property width to columnWidth 在相同的配置中,将属性width重命名为columnWidth
  3. Add renderTo: Ext.getBody() attribute 添加renderTo: Ext.getBody()属性

jsfiddle seems to impose some limitations on how extjs panel is rendered. jsfiddle似乎对extjs panel的呈现方式施加了一些限制。 While I am not sure what's the issue with jsfiddle, here is a Plunker link that displays panel as expected. 虽然我不确定jsfiddle有什么问题,但是这里有一个Plunker链接 ,可以按预期显示panel

IMO, ExtJs GridPanel is a better way to add tool bar to your panel and display tabular data. IMO,ExtJs GridPanel是向面板添加工具栏并显示表格数据的更好方法。 Read more about it in Sencha docs Sencha文档中阅读有关它的更多信息

I finally worked out the solution for my question. 我终于解决了我的问题的解决方案。 I needed a button functionality in the header and also columns which could have functionality like arranging the items in ascending/descending order etc (basically the grid.column) 我需要标题和列中的按钮功能,它们可能具有诸如按升序/降序排列项目等功能(基本上是grid.column)

var screen = Ext.create('Ext.panel.Panel', {
renderTo: Ext.getBody(),
title: 'Search',
tools: [{
    xtype: 'button',
    text: 'Click',
    //code here for button functionality
}],
items:
       [{xtype: 'gridpanel',    
        columns: [
                    {
                    header : "Column 1",
                    width: .5
                    }, 
                    {
                    header : "column2",
                    width: .5
                    }],
                 }],
});

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

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