【问题标题】:EXTJS 3.3.3 GridEXTJS 3.3.3 网格
【发布时间】:2012-01-20 11:25:59
【问题描述】:

我正在使用 EXTJS 网格开发一个带有分页的复选框网格列表。执行页面导航时,我需要记住选择的记录。

详情: 1) 转到第 1 页并选择第 1,2 和 3 行。 2)现在导航到页面:2 3) 回到页面:1 4) 已选中的第 1,2 和 3 行应显示为选中

grid中是否有处理这种功能的api?

提前致谢。

【问题讨论】:

    标签: extjs


    【解决方案1】:

    感谢您的回复。我通过实现网格插件实现了我的设计。该插件看起来像,

    Ext.namespace('Ext.ux.plugins');
    
    Ext.ux.plugins.CheckBoxMemory = Ext.extend(Object,
    {
       constructor: function(config)
       {
          if (!config)
             config = {};
    
          this.prefix = 'id_';
          this.items = {};
          this.idProperty = config.idProperty || 'id';
       },
    
       init: function(grid)
       {
          this.view = grid.getView()
          this.store = grid.getStore();
          this.sm = grid.getSelectionModel();
          this.sm.on('rowselect', this.onSelect, this);
          this.sm.on('rowdeselect', this.onDeselect, this);
          this.store.on('clear', this.onClear, this);
          this.view.on('refresh', this.restoreState, this);
       },
    
       onSelect: function(sm, idx, rec)
       {
          this.items[this.getId(rec)] = true;
       },
    
       onDeselect: function(sm, idx, rec)
       {
          delete this.items[this.getId(rec)];
       },
    
       restoreState: function()
       {
          var i = 0;
          var sel = [];
          this.store.each(function(rec)
          {
             var id = this.getId(rec);
             if (this.items[id] === true)
                sel.push(i);
    
             ++i;
          }, this);
          if (sel.length > 0)
             this.sm.selectRows(sel);
       },
    
       onClear: function()
       {
          var sel = [];
          this.items = {};
       },
    
       getId: function(rec)
       {
          return rec.get(this.idProperty);
       }
    });
    

    这个插件是从 gird 调用的,

    Ext.grid.Gridpanel({
    store: 'someStore',
    plugins: [new Ext.ux.plugins.CheckBoxMemory({idProperty: "recordID"})]
    
    });
    

    希望这对某人有所帮助。

    【讨论】:

    • 2007 年 4 月,sencha.com/forums 上的用户 evant 实现了完全相同的操作。这是链接:sencha.com/forum/…
    【解决方案2】:

    我认为没有。您需要将所选记录的 ID 存储在某个单独的存储/数组中,并在页面更改时使用它重新应用选择。

    【讨论】:

    • 我之前尝试过将选定的行存储在一个数组中并使用 selectRows(Array) 我突出显示了记录。但是这里有一个问题。假设如果在 page:1 中选择 id 为 1,2 和 3 的行并移动到 page:2,则选择 page:2 中的第 1,2 和 3 行。所以我不认为在分页网格中存储行 ID 是不合适的。
    • 这就是为什么我说的是记录 ID 而不是行 ID。可以统一指示要突出显示的记录的内容,例如数据库中的主键。
    【解决方案3】:

    您可以在全局范围内放置一个 MixedCollection 对象来跟踪这些记录。这将允许您存储不同对象类型的全局设置。

    【讨论】:

      猜你喜欢
      • 2012-06-24
      • 2013-10-30
      • 2012-02-19
      • 2015-12-12
      • 2011-02-15
      • 2011-08-06
      • 2013-02-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多