I have a gridpanel with checkbox Selection Model inside a window.
On a button click handler, the window opens up the grid with checkboxes for the first time perfectly.
On opening it second time or later, the checkboxes are not visible. I am going an explicit instance creation in the grid Ext.define()
.
selModel: Ext.create('Ext.selection.CheckboxModel', {
mode: 'SIMPLE',
checkOnly: true,
listeners: {
selectionchange: function (model, selections) {
if (selections.length > 10) {
Ext.Msg.alert('Info', 'Max of only 10 selections allowed');
for (var i = 10; i < selections.length; i++) {
var record = selections[i];
model.deselect(record, true);
}
}
}
}
})
Update:
- inside the button handler - opening a form with input entries - on form submit - open a window with checkbox - grid inside the storeload
checkGridStore.load({
scope: this,
callback: function (records, operation, success) {
var firstWindowWithCheckGrid= Ext.widget('gridwindow', {
id: 'firstWindowWithCheckGrid'
});
firstWindowWithCheckGrid.show();
}
});
Window config :
Ext.define('Sample.view.GridWindow', {
extend: 'Ext.window.Window',
alias: 'widget.gridwindow',
height: 500,
width: 1500,
modal: true,
layout: 'fit',
forceFit: true,
listeners: {
beforeshow: function (window) {
window.doLayout();
}
},
buttons: [
{
text: 'Submit',
handler: function () {
var selectedRows = Ext.getCmp('statusGrid').getSelectionModel().getSelection();
// do something
Ext.getCmp('firstWindowWithCheckGrid').close();
// do something
secondStore.load({
scope: this,
callback: function (records, operation, flag) {
if (records.length > 0) {
var secondWindowWithoutCheckGrid = Ext.create('GridWindow', {
id: 'statusWindow',
items: {
xtype: 'gridpanel'
},
buttons: [
{
text: 'Close',
handler: function () {
secondWindowWithoutCheckGrid .close();
}
}
]
}).show();
}
}
});
}
},
{
text: 'Close',
handler: function () {
try {
Ext.getCmp('firstWindowWithCheckGrid').close();
} catch (error) {
}
}
}
],
initComponent: function () {
this.items = [
{
xtype: 'statusgrid',
id: 'statusGrid'
}
]
this.callParent(arguments);
}
});
Grid Config:
Ext.define('Sample.view.StatusGrid', {
extend: 'Ext.grid.Panel',
alias: 'widget.statusgrid',
multiSelect: true,
emptyText: 'No Matching Records',
stripeRows: true,
columnLines: true,
store: 'SomeStore',
autoScroll: true,
margin: '5 5 5 5',
selModel: Ext.create('Ext.selection.CheckboxModel', {
mode: 'SIMPLE',
listeners: {
selectionchange: function (model, selections) {
if (selections.length > 10) {
Ext.Msg.alert('Info', 'Max of only 10 selections allowed');
for (var i = 10; i < selections.length; i++) {
var record = selections[i];
model.deselect(record, true);
}
}
}
}
}),
columns: [
// columns
]
initComponent: function () {
this.callParent(arguments);
}
});
I fixed it this way - thanks @EvanTrimboli for the hint
I removed the selModel
instance in the grid definition.
Inside the initComponent
of the window config above, I create a new instance of the selModel
config object and include it in the items -> grid instance so the checkboxes don't disappear anymore
initComponent: function () {
var selModel= Ext.create('Ext.selection.CheckboxModel', {
mode: 'SIMPLE',
hidden: true,
listeners: {
selectionchange: function (model, selections) {
if (selections.length > 10) {
Ext.Msg.alert('Info', 'Max of only 10 selections allowed');
for (var i = 10; i < selections.length; i++) {
var record = selections[i];
model.deselect(record, true);
}
}
}
}
});
this.items = [
{
xtype: 'statusgrid',
id: 'statusGrid',
selModel: selModel
}
]
this.callParent(arguments);
}
Thank you all for the help !!!