Hello again Susan!
Looks like there are two issues, that even
AddColumn()
and
InsertColumn()
don't work in MVC's code behind.
The problem is that, in WebForms, code behind knows the initial grid configuration (whereas knowing it has the FilterHeader plug in attached).
For MVC, when we get a reference for the grid via
X.GetCmp<GridPanel>("gpanelTest")
, the retrieved reference to the grid does not actually has any different thing attached to it.
In
post #9, I've said:
The time the columns are rewritten during a reconfigure (specifying the new column model) disallows to apply the filter header settings, and the easiest way seems to just reconfigure it to an empty grid then add the columns after the grid is re-rendered and the filterheader plugin can touch what it needs in order to set up the column headers.
This is quite wrong. In fact, there's no client-side handling of the column settings when columns are added at all. This is all done server-side, and the column definition you provide to the add and insert methods are just tampered with the necessary settings to implement the filter header whenever the column matches some pre-requisites (its type, being filterable).
As you are stuck to an older version of Ext.NET, I'm sure you can't benefit from the fix from latest version. But as the issue was still actual down to Ext.NET 4.5.0, I'll post the reviewed controller code with a workaround for this.
public DirectResult c62207_reconfig()
{
DirectResult response = new DirectResult();
var btn = X.GetCmp<Button>("ReconfigBtn");
btn.Disabled = true;
var newcols = new List<ColumnBase>() {
new DateColumn
{
Text = "Last Updated",
Width = 85,
Sortable = true,
DataIndex = "lastChange",
Format = "M/d/yyyy"
},
new Column
{
Text = "Company",
Width = 150,
DataIndex = "company"
}
};
var grid = X.GetCmp<GridPanel>("gpanelTest");
// From MVC, just by X.GetCmp() you can't know whether the grid has
// the FilterHeader plug in, so we should just add it, then.
grid.Plugins.Add(new FilterHeader());
#region Workaround for issue #1572
grid.ColumnModel.RemoveAll();
// Manually adding the to-be-added columns indirectly crafts the
// columns' definition to include the FilterHeader's necessary
// settings.
newcols.ForEach(col => grid.ColumnModel.Add(col));
#endregion Workaround for issue #1572
// Now reconfiguring with the right column definitions will do.
grid.Reconfigure(newcols);
return response;
}
Furthermore, as the actual issue was identified, it was straightforward to fix it in Ext.NET, so that fix is going to make it to the next Ext.NET release, currently 4.5.1 (may change to 4.6.0 if a bigger/feature change makes it to the release).
Please notice line 29 of the code is required regardless of the fix due to a limitation in how MVC works with Ext.NET. The reason you couldn't port the WebForms sample to MVC is probably this. The fetched grid reference needs to have the plug in (and any other plug ins that might incur into side effects like this), or else even the commands that worked in WebForms would not have the desired effects in MVC.
I hope this helps!