简体   繁体   English

ExtJS GridPanel宽度

[英]ExtJS GridPanel width

I'm using Ext JS 2.3.0 and have created the search dialog shown below. 我正在使用Ext JS 2.3.0并创建了如下所示的搜索对话框。

在此输入图像描述

The search results are shown in a GridPanel with a single Name column, but notice that this column does not stretch to fill all the available horizontal space. 搜索结果显示在带有单个“名称”列的GridPanel中,但请注意,此列不会拉伸以填充所有可用的水平空间。 However, after I perform a search, the column resizes properly (even if no results are returned): 但是,在执行搜索后,列会正确调整大小(即使未返回任何结果):

在此输入图像描述

How can I make the column display correctly when it's shown initially? 如何在最初显示列时正确显示列? The relevant code is shown below: 相关代码如下所示:

FV.FindEntityDialog = Ext.extend(Ext.util.Observable, {

    constructor: function() {

        var queryTextField = new Ext.form.TextField({
            hideLabel: true,
            width: 275,
            colspan: 2,
        });
        var self = this;

        // the search query panel
        var entitySearchForm = new Ext.form.FormPanel({
            width: '100%',
            frame: true,
            layout:'table',
            layoutConfig: {columns: 3},
            items: [
                queryTextField,
                {
                    xtype: 'button',
                    text: locale["dialogSearch.button.search"],
                    handler: function() {
                        var queryString = queryTextField.getValue();
                        self._doSearch(queryString);
                    }
                }
            ]
        });

        // the search results model and view
        this._searchResultsStore = new Ext.data.SimpleStore({
            data: [],
            fields: ['name']
        });

        var colModel = new Ext.grid.ColumnModel([
            {
                id: 'name',
                header: locale['dialogSearch.column.name'],
                sortable: true,
                dataIndex: 'name'
            }
        ]);

        var selectionModel = new Ext.grid.RowSelectionModel({singleSelect: false});

        this._searchResultsPanel = new Ext.grid.GridPanel({
            title: locale['dialogSearch.results.name'],
            height: 400,
            stripeRows: true,
            autoWidth: true,
            autoExpandColumn: 'name',
            store: this._searchResultsStore,

            colModel: colModel,
            selModel: selectionModel,
            hidden: false,
            buttonAlign: 'center',
            buttons: [
                {
                    text: locale["dialogSearch.button.add"],
                    handler: function () {
                        entitySearchWindow.close();
                    }
                },
                {
                    text: locale["dialogSearch.button.cancel"],
                    handler: function () {
                        entitySearchWindow.close();
                    }
                }
            ]
        });

        // a modal window that contains both the search query and results panels
        var entitySearchWindow = new Ext.Window({
            closable: true,
            resizable: false,
            draggable: true,
            modal: true,
            viewConfig: {
                forceFit: true
            },
            title: locale['dialogSearch.title'],
            items: [entitySearchForm, this._searchResultsPanel]
        });

        entitySearchWindow.show();
    },

    /**
     * Search for an entity that matches the query and update the results panel with a list of matches
     * @param queryString
     */
    _doSearch: function(queryString) {

        def dummyResults = [['foo'], ['bar'], ['baz']];       
        self._searchResultsStore.loadData(dummyResults, false);
    }
});

Try to remove autoWidth from GridPanel configuration, because setting autoWidth:true means that the browser will manage width based on the element's contents, and that Ext will not manage it at all. 尝试从GridPanel配置中删除autoWidth ,因为设置autoWidth:true意味着浏览器将根据元素的内容管理宽度,而Ext根本不会管理它。

In addition you can try to call .doLayout(false, true) on your grid after it was rendered. 此外,您可以尝试在渲染后在网格上调用.doLayout(false, true)

It's the same issue you had in an earlier question, the viewConfig is an config item for the grid panel check the docs , so it should be 这是你在之前的问题中遇到的同样问题,viewConfig是网格面板的配置项,检查文档 ,所以它应该是

this._searchResultsPanel = new Ext.grid.GridPanel({
  viewConfig: {
            forceFit: true
        },
  ....other configs you need,

To be more precise the viewConfig accepts the Ext.grid.GridView configs, feel free to read the docs on that one too. 更确切地说,viewConfig接受Ext.grid.GridView配置,随时也可以阅读那篇文档。

Otherwise this seems to be the only problem, and i refer the column width, not the gridpanel width. 否则这似乎是唯一的问题,我指的是列宽,而不是网格面板宽度。 On the gridpanel you have a title and two buttons who doesn't seem to be affected. 在gridpanel上,你有一个标题和两个似乎没有受到影响的按钮。 So i repeat the gridPanel's width is ok, it's the columns width issue. 所以我重复gridPanel的宽度是好的,这是列宽问题。

尝试将flex: 1添加到GridPanel

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

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