javascript - 如何使 Ext.js 4 网格插件有状态?

标签 javascript extjs

我找到了一个 ext.js 网格插件,用于通过组合框更改页面大小。从这里 ( enter link description here )

这是插件

/**
* Ext.ux.grid.PageSize
*/
Ext.define('Ext.ux.grid.PageSize', {
    extend      : 'Ext.form.field.ComboBox',
    alias       : 'plugin.pagesize',
    beforeText  : 'Show',
    afterText   : 'rows/page',
    mode        : 'local',
    displayField: 'text',
    valueField  : 'value',
    allowBlank  : false,
    triggerAction: 'all',
    width       : 50,
    maskRe      : /[0-9]/,    
    /**
    * initialize the paging combo after the pagebar is randered
    */
    init: function(paging) {
        paging.on('afterrender', this.onInitView, this);
    },
    /**
    * create a local store for availabe range of pages
    */
    store: new Ext.data.SimpleStore({
        fields: ['text', 'value'],
        data: [['5', 5], ['10', 10], ['15', 15], ['20', 20], ['25', 25], ['50', 50], ['100', 100], ['200', 200], ['500', 500]]
    }),    
    /**
    * assing the select and specialkey events for the combobox 
    * after the pagebar is rendered.
    */
    onInitView: function(paging) {
        this.setValue(paging.store.pageSize); 
        paging.add('-', this.beforeText, this, this.afterText);
        this.on('select', this.onPageSizeChanged, paging);
        this.on('specialkey', function(combo, e) {
            if(13 === e.getKey()) {
                this.onPageSizeChanged.call(paging, this);        
            }
        });
    },
    /**
    * refresh the page when the value is changed
    */
    onPageSizeChanged: function(combo) {
        this.store.pageSize = parseInt(combo.getRawValue(), 10);
        this.doRefresh();
    }
}); 

我想将组合框状态添加到网格状态,以便网格在重新加载时显示最后更改的页面大小。 (我需要将值添加到网格状态项而不是分离状态项)

我如何在 Ext.JS 4.* 中做到这一点?

最佳答案

您需要包含 Ext.state.Stateful 混合宏并覆盖 getState()方法:

getState: function(){
    return this.store.pageSize;
}

applyState()方法:

applyState: function(state) {
    if (state) {
        this.store.pageSize = state;
    }
}

然后,如果您使用此插件,则需要将 stateful 设置为 true 并为您的插件实例提供一个 stateId

关于javascript - 如何使 Ext.js 4 网格插件有状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23465199/

相关文章:

javascript - 当在其顶部打开新窗口然后关闭时,Google Chrome 扩展弹出窗口是否可以保持打开状态?

Javascript window.location 搜索 "#"永远不会返回 true

javascript - 启用日期字段 ExtJS 中的日期,仅指定要启用的日期

javascript - 固定面板 extjs 4.2 的大小

javascript - EXTJS 复选框显示为 [object Object]

php - javascript在刷新页面后保持复选框选中状态

javascript - 如何在父元素缩放时限制子元素倾斜

带有空存储的 ExtJS 网格,在添加/插入时仅显示添加的最新记录

javascript - 禁用 Ext.form.ComboBox 中的某些项目

javascript - 为什么以下 JavaScript 正则表达式无法工作?