PDA

View Full Version : Help withb CheckboxSelectionModel and Paging



j.torres
2 Jul 2010, 10:57 AM
:)
Have a good day, i have a problem using some plug in, one is Ext.ux.grid.Search and the other one is Ext.ux.plugins.CheckBoxMemory, i use both plug ins in a paging grid, but each row has a checkbox for its selection, whe i go to other page of teh grid and back the grid don't forget the selection, but when i click the button selection to return all my selections, only return the current page selections, i have a good idea how resolve this problem but i need override a function that return the selected records

this.selections = this.selectedRecords = this.view.sm.getSelections();

line: 852 of Ext.ux.grid.Search

the both plug ins are in the grid

var gridAdminCBMemory = new Ext.ux.plugins.CheckBoxMemory({idProperty: 'gridAdmin'});
var grid = new Ext.grid.GridPanel({
id: 'gridAdmin',
idProperty:'gridAdmin',
width: 500,
height: 300,
title: config.title,
store: store,
columns: columnsx,
sm: smx,
plugins: [gridAdminCBMemory,
new Ext.ux.grid.Search({
mode: 'remote',
iconCls: false,
minLength: 1
})],
bbar: new Ext.PagingToolbar({

store: store,
displayInfo: true,
displayMsg: config.title + '{0} - {1} ' + Messages.of + ' {2}',
emptyMsg: Messages.emptyTable,
beforePageText: Messages.page,
afterPageText: Messages.of + ' {0}'
}),
viewConfig: {
forceFit: true
},
listeners: {
cellclick: function(grid, rowIndex, columnIndex, e){
record = grid.getStore().getAt(rowIndex);
},
resize: function(comp, adjWidth, adjHeight, rawWidth, rawHeight ) {

if (tbarx != 'select') {
var page = parseInt((adjHeight - 110) / getRowHeight());
comp.getBottomToolbar().pageSize = page;

if (Ext.isDefined(comp.getStore()) && comp.getStore().lastOptions != null && Ext.isDefined(comp.getStore().lastOptions)
&& Ext.isDefined(comp.getStore().lastOptions.params) && Ext.isDefined(comp.getStore().lastOptions.params.start) && comp.getStore().lastOptions.params.start != null) {
comp.getStore().load({
params: {
start: comp.getStore().lastOptions.params.start,
limit: page,
fields: comp.getStore().baseParams['fields'],
query: comp.getStore().baseParams['query']
}
});
}
}
}
},
loadMask: true,
tbar: this.tbar
});
this.grid = grid;
return grid;
and this is the code of the CheckBoxMemory plug in

var count=0;
var arraySelections=[];
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);
//this.sm.on('getSelections', this.getSelections, this);
this.view.on('getSelections', this.getSelections, this);
},

onSelect: function(sm, idx, rec,grid)
{
if(this.idProperty === sm.grid.idProperty){
this.items[rec.id] = true;
if(this.items[rec.id]==true){
arraySelections.push(rec);
count++;
}
}
},

onDeselect: function(sm, idx, rec)
{
if(this.idProperty === sm.grid.idProperty){
this.items[rec.id]=false;
for(i= (arraySelections.length -1);i>-1;i--){
if(rec.id === arraySelections.valueOf().id){
arraySelections.splice(i,1);
count--;
}
}
}
},
restoreState: function(sm)
{
if(this.idProperty === sm.grid.idProperty){

var i = 0;
var sel = [];
this.store.each(function(rec)
{
var id = rec.id;
if (this.items[id] === true)
sel.push(i);
++i;
}, this);
if (sel.length > 0){
this.sm.selectRows(sel);
}
}
},

onClear: function()
{
var sel = [];
this.items = {};
sel.clear();
},
getSelections: function(sm){
alert('Hey whats up');
}
}
);

ok, i just need know how can i override the function [I]getSelectedRecords line 849 from Ext.ux.grid.Search in ChekBoxMemory to return the real row selections. :((

Thanks a lot for your Help.

Jorge Andres Torres M.
aka George

Condor
2 Jul 2010, 11:34 PM
Just check if every selected record is actually part of the store and only return the records that are.