I am trying to use a Checkbox which is the first field in an EditorGrid row to trigger a Row Selection Model. Originally, I tried using a Checkbox Selection Model. That gave me the checkbox at the beginning of the row, and selected the row that I wanted which I used to get information for a grid in a popup window that I coded. The selection and the popup window worked fine except for the fact that there were other editable fields in the row that I was selecting. When I tried to edit any of those fields, the Checkbox Selection Model kicked in and my grid in a window popped up. Next I tried setting up a check column and making that column part of my column model. What I would then get is text (true or false) appearing where the checkbox should be. When I would click on the text, the checkbox would finally appear. I abandoned the check column and tried putting an entry in the column model with an xtype of 'booleanfield' and then later 'booleancolumn' and having an editor on that column with an xtype of 'checkbox'. That gave me the same results as with a check column, ie text appeared where the checkbox should be and only after I clicked on the text did the checkbox appear.
My latest attempt came from an analogous issue that Ken Toole found on the EXTJS forum. This involved using a check column again and referencing it in the column model and using a specially defined renderer for it. The result of this attempt is that now the text shows up but is not clickable. The special renderer to create a checkbox is not working. Below you will find my code which reflects the latest attempt. I am just trying at this point to get the checkbox to appear but I want to put a listener on that checkbox somehow to trigger the Row Selection Model...
Here is my checkColumn:
var pnAlloc = new Ext.grid.CheckColumn({
header: 'Pen Alloc?',
dataIndex: 'PNALLOC',
width: 40
});
Here is my column model:
var cm = new Ext.grid.ColumnModel({
columns: [
// pnAlloc,
{header: '<b>Pen Alloc?</b>',width: 65,align: 'center',xtype: 'booleancolumn',dataIndex: 'PNALLOC',renderer: formatBoolean,editable: false},
{header: '<b>Qty</b>',width: 80,sortable: true, editor:{xtype: 'numberfield',allowBlank: false,selectOnFocus: true}, dataIndex: 'CSTQTY'},
{header: '<b>Sex</b>',width: 100,sortable: true,dataIndex: 'DLSEXD'},
{header: '<b>Hatch Loc</b>',width: 80,sortable: true,hidden: true,editor:{ xtype: 'textfield',allowBlank: false,selectOnFocus: true}, dataIndex: 'DLHLOC'},
{header: '<b>Hatch Farm#</b>',width: 80,sortable: true,editor:{ xtype: 'numberfield',allowBlank: false,selectOnFocus: true}, dataIndex: 'DLHFARMNO'},
{header: '<b>Hatch BarnId</b>',width: 80,sortable: true, editor:{ xtype: 'textfield',allowBlank: false,selectOnFocus: true}, dataIndex: 'DLHBARNID'},
{header: '<b>Hatch Flck Yr</b>',width: 80,sortable: true, editor:{ xtype: 'numberfield',allowBlank: false,selectOnFocus: true}, dataIndex: 'DLHYEAR'},
{header: '<b>Hatch Flck Id#</b>',width: 80,sortable: true,editor:{ xtype: 'numberfield',allowBlank: false,selectOnFocus: true}, dataIndex: 'DLHNUM'},
{header: '<b>Hatch PenId</b>',width: 80,sortable: true, editor:{ xtype: 'textfield',allowBlank: false,selectOnFocus: true}, dataIndex: 'DLHPENID'},
{header: '<b>Set Date</b>',xtype: 'datecolumn', width: 100,sortable: true, format:'Y-m-d',editor:{ xtype: 'datefield',allowBlank: false,selectOnFocus: true}, dataIndex: 'DLSDAT'},
{header: '<b>Test Lot</b>',width: 80,sortable: true, editor:{ xtype: 'textfield',allowBlank: false,selectOnFocus: true}, dataIndex: 'DLTSLT'},
{header: '<b>Day Old Cst</b>',width: 80,sortable: true,dataIndex: 'BABYCST'},
{header: '<b>.00 % Free</b>',width: 80,sortable: true,dataIndex: 'DLMORP'},
{header: '<b>Audit Credit</b>',width: 80,sortable: true,dataIndex: 'DLAUDIT'},
{header: '<b>Energy Credit</b>',width: 80,sortable: true,dataIndex: 'DLENERGY'},
{header: '<b>Net Cost</b>',width: 120,sortable: true,dataIndex: 'NETCOST'},
{header: '<b>Cost</b>',width: 120,sortable: true,dataIndex: 'LINECST'}
]
});
Here is my editor grid:
var ticketGrid3 = new Ext.grid.EditorGridPanel({
id: 'grid03',
height: 200,
store: store3,
clicksToEdit: 1,
//plugin:[pnAlloc],
// ds: ds,
cm: cm,
enableColLock:false,
listeners: { // add a cellclick listener to the grid
cellclick: function(o, row, cell, e){
// ensure mouseclick occurred within checkbox icon's visible area
if (o.getColumnModel().getDataIndex(cell) == 'PNALLOC' && e.getTarget('.checkbox', 1)) {
var rec = o.getDataSource().getAt(row);
rec.set('PNALLOC', !rec.get('PNALLOC')); // toggle "PNALLOC" value
}
}
},
sm: smPen
});
here is my renderer:
function formatBoolean(value, cell, rec, rowIndex, colIndex, ds) {
return [
'<img ',
'class="checkbox" ', // give the checkbox image a css class of "checkbox"
'src="../../resources/images/default/menu/',
value? 'checked.gif' : 'unchecked.gif',
'"/>'
].join("");
};
My latest attempt came from an analogous issue that Ken Toole found on the EXTJS forum. This involved using a check column again and referencing it in the column model and using a specially defined renderer for it. The result of this attempt is that now the text shows up but is not clickable. The special renderer to create a checkbox is not working. Below you will find my code which reflects the latest attempt. I am just trying at this point to get the checkbox to appear but I want to put a listener on that checkbox somehow to trigger the Row Selection Model...
Here is my checkColumn:
var pnAlloc = new Ext.grid.CheckColumn({
header: 'Pen Alloc?',
dataIndex: 'PNALLOC',
width: 40
});
Here is my column model:
var cm = new Ext.grid.ColumnModel({
columns: [
// pnAlloc,
{header: '<b>Pen Alloc?</b>',width: 65,align: 'center',xtype: 'booleancolumn',dataIndex: 'PNALLOC',renderer: formatBoolean,editable: false},
{header: '<b>Qty</b>',width: 80,sortable: true, editor:{xtype: 'numberfield',allowBlank: false,selectOnFocus: true}, dataIndex: 'CSTQTY'},
{header: '<b>Sex</b>',width: 100,sortable: true,dataIndex: 'DLSEXD'},
{header: '<b>Hatch Loc</b>',width: 80,sortable: true,hidden: true,editor:{ xtype: 'textfield',allowBlank: false,selectOnFocus: true}, dataIndex: 'DLHLOC'},
{header: '<b>Hatch Farm#</b>',width: 80,sortable: true,editor:{ xtype: 'numberfield',allowBlank: false,selectOnFocus: true}, dataIndex: 'DLHFARMNO'},
{header: '<b>Hatch BarnId</b>',width: 80,sortable: true, editor:{ xtype: 'textfield',allowBlank: false,selectOnFocus: true}, dataIndex: 'DLHBARNID'},
{header: '<b>Hatch Flck Yr</b>',width: 80,sortable: true, editor:{ xtype: 'numberfield',allowBlank: false,selectOnFocus: true}, dataIndex: 'DLHYEAR'},
{header: '<b>Hatch Flck Id#</b>',width: 80,sortable: true,editor:{ xtype: 'numberfield',allowBlank: false,selectOnFocus: true}, dataIndex: 'DLHNUM'},
{header: '<b>Hatch PenId</b>',width: 80,sortable: true, editor:{ xtype: 'textfield',allowBlank: false,selectOnFocus: true}, dataIndex: 'DLHPENID'},
{header: '<b>Set Date</b>',xtype: 'datecolumn', width: 100,sortable: true, format:'Y-m-d',editor:{ xtype: 'datefield',allowBlank: false,selectOnFocus: true}, dataIndex: 'DLSDAT'},
{header: '<b>Test Lot</b>',width: 80,sortable: true, editor:{ xtype: 'textfield',allowBlank: false,selectOnFocus: true}, dataIndex: 'DLTSLT'},
{header: '<b>Day Old Cst</b>',width: 80,sortable: true,dataIndex: 'BABYCST'},
{header: '<b>.00 % Free</b>',width: 80,sortable: true,dataIndex: 'DLMORP'},
{header: '<b>Audit Credit</b>',width: 80,sortable: true,dataIndex: 'DLAUDIT'},
{header: '<b>Energy Credit</b>',width: 80,sortable: true,dataIndex: 'DLENERGY'},
{header: '<b>Net Cost</b>',width: 120,sortable: true,dataIndex: 'NETCOST'},
{header: '<b>Cost</b>',width: 120,sortable: true,dataIndex: 'LINECST'}
]
});
Here is my editor grid:
var ticketGrid3 = new Ext.grid.EditorGridPanel({
id: 'grid03',
height: 200,
store: store3,
clicksToEdit: 1,
//plugin:[pnAlloc],
// ds: ds,
cm: cm,
enableColLock:false,
listeners: { // add a cellclick listener to the grid
cellclick: function(o, row, cell, e){
// ensure mouseclick occurred within checkbox icon's visible area
if (o.getColumnModel().getDataIndex(cell) == 'PNALLOC' && e.getTarget('.checkbox', 1)) {
var rec = o.getDataSource().getAt(row);
rec.set('PNALLOC', !rec.get('PNALLOC')); // toggle "PNALLOC" value
}
}
},
sm: smPen
});
here is my renderer:
function formatBoolean(value, cell, rec, rowIndex, colIndex, ds) {
return [
'<img ',
'class="checkbox" ', // give the checkbox image a css class of "checkbox"
'src="../../resources/images/default/menu/',
value? 'checked.gif' : 'unchecked.gif',
'"/>'
].join("");
};
Comment