Please see code example and attached fiddle.
Issue: Basically, since Chrome 81 and maybe even before users of our application have reported an issue with the Ext.grid.Panel getHeaderContainer().insert not working. Basically, we have some dynamic columns that get set when a user changes selections in a combobox.
Question: Does anyone know of a possible workaround for this issue? Or know if Sencha is aware of the problem and working on a fix?
Workaround:
Found that grid.columns.length
is no longer returning 0 after removeAll()
header.insert(0, cols) works
header.add(cols) also works
ExtJS 7.2.0 Chrome 81 (No longer works) Firefox 76.0.1 (Works) Edge (Non-chromium) (Works)
Sencha Fiddle: https://fiddle.sencha.com/#view/editor&fiddle/35vb
Ext.application({
name : 'Fiddle',
launch : function() {
Ext.create('Ext.Button', {
text: 'Change Fields',
renderTo: Ext.getBody(),
handler: function(button, e) {
var grid = Ext.getCmp('testGrid');
console.log('grid = ', grid);
var header = grid.getHeaderContainer();
console.log('header Before = ', header);
//Setup the columns for Grading Period = Semester
var cols = [{ text: 'Student ID', dataIndex: 'StudentID'},
{ text: 'Name', dataIndex: 'LastFirst', width: 180},
{ text: '1st Midterm Grade', dataIndex: 'GradEntA_1', width: 140, editor: 'textfield'},
{ text: '1st Nine Weeks', dataIndex: 'GradEntA_2', width: 140, editor: 'textfield'},
{ text: '2nd Midterm Grade', dataIndex: 'GradEntA_3', width: 140, editor: 'textfield'},
{ text: '2nd Nine Weeks', dataIndex: 'GradEntA_4', width: 140, editor: 'textfield'},
{ text: '1st Exam Value', dataIndex: 'GradEntB_1', width: 140, editor: 'textfield'},
{ text: '1st Semester Value', dataIndex: 'GradEntB_2', width: 140, editor: 'textfield'},
{ text: '1st Semester Credit', dataIndex: 'GradEntB_3', width: 140, editor: 'textfield'},
{ text: '3rd Midterm Grade', dataIndex: 'GradEntC_1', width: 140, editor: 'textfield'},
{ text: '3rd Nine Weeks', dataIndex: 'GradEntC_2', width: 140, editor: 'textfield'},
{ text: '4th Midterm Grade', dataIndex: 'GradEntC_3', width: 140, editor: 'textfield'},
{ text: '4th Nine Weeks', dataIndex: 'GradEntC_4', width: 140, editor: 'textfield'},
{ text: '2nd Exam Value', dataIndex: 'GradEntD_1', width: 140, editor: 'textfield'},
{ text: '2nd Semester Value', dataIndex: 'GradEntD_2', width: 140, editor: 'textfield'},
{ text: '2nd Semester Credit', dataIndex: 'GradEntD_3', width: 140, editor: 'textfield'},
{ text: 'Final for Term', dataIndex: 'GradFinal', width: 140, editor: 'textfield'}
];
header.removeAll();
header.insert(cols);
console.log('header After = ', header);
}
});
Ext.create('Ext.grid.Panel', {
title: 'Column Demo',
id: 'testGrid',
width: '100%',
columns: [
{text: 'First Name', dataIndex:'firstname'},
{text: 'Last Name', dataIndex:'lastname'},
{text: 'Hired Month', dataIndex:'hired', xtype:'datecolumn', format:'M'},
{text: 'Department (Yrs)', xtype:'templatecolumn', tpl:'{dep} ({seniority})'}
],
forceFit: true,
renderTo: Ext.getBody()
});
}
});
You should use grid reconfigure function instead to avoid problems.
Ex.
tree.reconfigure(store);
// or
grid.reconfigure(columns);
// or
tree.reconfigure(null, columns);