2
votes

I am developing a checkbox grid list with pagination using the EXTJS grid. I need to remember the selected record when the page navigation is performed.

Details: 1) Go to page:1 and selected rows 1,2 and 3. 2) Now navigate to page:2 3) Come back to page:1 4) The rows 1,2 and 3 which are already selected should be shown as selected

Is there is any api in grid which handles this kind of function?

Thanks in advance.

3

3 Answers

2
votes

Thanks for your responses. I have achieved my design by implementind a plugin for grid. The plugin looks as,

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

This plugin was called from gird as,

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

});

Hope this helps some one.

1
votes

I don't think there is. You;d need to store IDs of selected records in some separate store/array and use it to re-apply selections when page is changed.

0
votes

You could put a MixedCollection Object at the global scope to keep track of these records. This will allow you to store global settings of different object types.