After posting the question ExtJS checkcolumn grid - check columns to left, uncheck columns to right and thinking there were existing questions and answers for a "select all" option, I've read a little deeper and they don't actually cover what I need in relation to my other question's answer.
I need to know what code is required to generate a checkbox in each column header that, when selected/deselected, changes the checkboxes in the given column.
Existing code for reference:
Ext.Loader.setConfig({
enabled: true
});
Ext.Loader.setPath('Ext.ux', '../ux');
Ext.require([
'Ext.ux.CheckColumn'
]);
Ext.onReady(function(){
Ext.define('ProcessModel', {
extend: 'Ext.data.Model',
fields: [
'Item',
'Phase1',
'Phase2',
'Phase3',
'Phase4',
'Phase5',
'Phase6',
'Phase7',
'Phase8',
'Phase9',
'Phase10'
]
});
// create the Data Store
var processStore = Ext.create('Ext.data.Store', {
model: 'processModel',
autoLoad: true,
proxy: {
// load using HTTP
type: 'ajax',
url: '<?= $site_url ?>/Production/Processes/<?= $itemId ?>',
reader: {
type: 'json',
model: 'ProcessModel',
root: data
}
}
});
function onCheckChange (column, rowIndex, checked, eOpts) {
var record = processStore.getAt(rowIndex);
var columnIndex = column.getIndex();
for (var i = 1; i <= 10; i++) {
if(checked) {
if (i <= columnIndex) {
record.set('Phase'+i, true);
}
else
{
record.set('Phase'+i, false);
}
}
else {
if (i >= columnIndex) {
record.set('Phase'+i, false);
}
}
}
}
Ext.create('Ext.grid.Panel', {
width: 800,
store: processStore,
title: 'Processes',
tbar: [
{
xtype: 'button',
text: 'Update',
handler: function(){
//TODO: update by POST function
}
}
],
columns: [
{
text: 'Item',
dataIndex: 'Item'
},{
xtype: 'checkcolumn',
text: 'Phase 1',
dataIndex:'Phase1',
listeners: {
checkChange: onCheckChange
}
},{
xtype: 'checkcolumn',
text: 'Phase 2',
dataIndex:'Phase2',
listeners: {
checkChange: onCheckChange
}
},{
xtype: 'checkcolumn',
text: 'Phase 3',
dataIndex:'Phase3',
listeners: {
checkChange: onCheckChange
}
},{
xtype: 'checkcolumn',
text: 'Phase 4',
dataIndex:'Phase4',
listeners: {
checkChange: onCheckChange
}
},{
xtype: 'checkcolumn',
text: 'Phase 5',
dataIndex:'Phase5',
listeners: {
checkChange: onCheckChange
}
},{
xtype: 'checkcolumn',,
listeners: {
checkChange: onCheckChange
}
text: 'Phase 6',
dataIndex:'Phase6',
listeners: {
checkChange: onCheckChange
}
},{
xtype: 'checkcolumn',
text: 'Phase 7',
dataIndex:'Phase7',
listeners: {
checkChange: onCheckChange
}
},{
xtype: 'checkcolumn',
text: 'Phase 8',
dataIndex:'Phase8',
listeners: {
checkChange: onCheckChange
}
},{
xtype: 'checkcolumn',
text: 'Phase 9',
dataIndex:'Phase9',
listeners: {
checkChange: onCheckChange
}
},{
xtype: 'checkcolumn',
text: 'Phase 10',
dataIndex:'Phase10',
listeners: {
checkChange: onCheckChange
}
}
],
renderTo: Ext.get('sencha_processes')
});
});
Imagined pseudo-code to handle select all function, for the kind of effect I'm looking for:
function selectAllInColumn (column, checked, eopts){
var columnIndex = column.getIndex();
for( var i = 0; i < processStore.getCount(); i++)
{
if(checked)
{
var record = processStore.getAt(i);
for(var j = 1; j <= columnIndex; j++) {
record.set('Phase'+columnIndex, true);
}
for(var j = columnIndex+1; j <= 10; j++) {
record.set('Phase'+columnIndex, false);
}
}
else
{
var record = processStore.getAt(i);
for(var j = columnIndex; j <= 10; j++) {
record.set('Phase'+columnIndex, false);
}
}
}
}