首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ExtJS GridPanel宽度

ExtJS GridPanel宽度
EN

Stack Overflow用户
提问于 2011-11-17 01:39:04
回答 3查看 5.7K关注 0票数 0

我使用的是ExtJS2.3.0,并且已经创建了如下所示的搜索对话框。

搜索结果显示在只有一个Name列的GridPanel中,但请注意,此列不会伸展以填充所有可用的水平空间。但是,在我执行搜索之后,列的大小调整正确(即使没有返回任何结果):

如何才能使列在最初显示时正确显示?相关代码如下所示:

代码语言:javascript
复制
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);
    }
});
EN

回答 3

Stack Overflow用户

发布于 2011-11-17 02:34:36

尝试从GridPanel配置中删除autoWidth,因为设置autoWidth:true意味着浏览器将根据元素的内容管理宽度,而Ext根本不会管理它。

此外,您可以尝试在呈现网格之后调用网格上的.doLayout(false, true)

票数 1
EN

Stack Overflow用户

发布于 2011-11-17 03:00:50

这是您在前面的问题中遇到的相同问题,viewConfig是网格面板检查docs的配置项,因此它应该是

代码语言:javascript
复制
this._searchResultsPanel = new Ext.grid.GridPanel({
  viewConfig: {
            forceFit: true
        },
  ....other configs you need,

更准确地说,viewConfig接受Ext.grid.GridView配置,请随意阅读有关该配置的文档。

否则,这似乎是唯一的问题,我指的是列宽,而不是网格面板宽度。在网格面板上,您有一个标题和两个似乎不受影响的按钮。所以我重复一遍,网格面板的宽度是可以的,这是列宽度的问题。

票数 1
EN

Stack Overflow用户

发布于 2011-11-18 01:21:04

尝试向您的GridPanel添加flex: 1

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8156107

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档