javascript - ExtJS GridPanel 宽度

标签 javascript extjs

我正在使用 Ext JS 2.3.0 并创建了如下所示的搜索对话框。

enter image description here

搜索结果显示在带有单个“名称”列的 GridPanel 中,但请注意,该列不会拉伸(stretch)以填充所有可用的水平空间。但是,在执行搜索后,列的大小会正确调整(即使没有返回结果):

enter image description here

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

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);
    }
});

最佳答案

这与您在之前的问题中遇到的问题相同,viewConfig 是网格面板的配置项,请检查 docs ,所以应该是

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

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

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

关于javascript - ExtJS GridPanel 宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8156107/

相关文章:

JavaScript 访问 SVG 的内部 DOM

javascript - Firefox 不会触发动态嵌套 iframe 的 onload

javascript - 在 jQuery 中使以下内容动态化

php - 将 PHP 转换为 JavaScript。将键/值存储到数组中

ExtJS 4 "always on top"窗口

javascript - 绝对 div 上的 css 过渡宽度和高度到 0 不起作用

ajax - Extjs 代理只是将脏字段发布到服务器,而不是所有字段

javascript - 根据redux中的id将对象添加到数组

javascript - 使用 ExtJs 自动完成文本字段

extjs - 如何从 Ext js 网格存储中仅获取已删除的记录?