Skip to main content
Answer

Prevent Modern UI grid with dynamic columns from removing the columns

  • July 17, 2025
  • 3 replies
  • 129 views

darylbowman
Captain II
Forum|alt.badge.img+15

I am dynamically creating grid columns on a Modern UI grid. This works great.

What is not working great is that the dynamic columns seem to vanish when the grid ‘refresh’ button is used or the grid paging is used.

Does anyone know how to prevent this?

TypeScript:

@gridConfig({
adjustPageSize: true,
exportRowsLimit: 5000,
fastFilterByAllFields: true,
generateColumns: GridColumnGeneration.AppendDynamic,
//generateColumnsAfterSelect: true,
pagerMode: GridPagerMode.Numeric,
preset: GridPreset.Inquiry,
preventInitialFocus: true,
repaintColumns: true,
//statusField: "Availability",
suppressAutoHide: true,
})
export class DXDynamicResult extends PXView {

@columnConfig({
width: 70,
textAlign: TextAlign.Left
})
DXResultNbr : PXFieldState;
}

 

tagging ​@vanit05 because of this post

Best answer by darylbowman

Turns out the REAL underlying problem is how I was trying to remove fields (columns) from the cache.

view.Cache.Fields is a PXFieldCollection, which inherits List. This means that Clear() is an inherited method. The PXFieldCollection defines an override for Add(item) and Remove(item) but not Clear(). I was using Clear() in an effort to remove all the fields I had previously added, when that’s not at all what it does. it was having an effect, as the columns disappeared, but view.Cache.Fields.Contains(item) still returned ‘true’. Instead, I had to use view.Cache.Remove(item) on each field. Now the fields are correctly being removed, then correctly re-added, and no longer disappearing.

@Dmitrii Naumov - I recommend an override for Clear() be added or somehow indicate this is not what the method does

3 replies

darylbowman
Captain II
Forum|alt.badge.img+15
  • Author
  • July 18, 2025

I believe I’ve narrowed down the issue to the dynamic FieldSelecting event handler. It seems to only run one time after being initialized in an action.

 

Edit: I think this is due to the fact that the fields are being removed from View.Cache.Fields for some reason. I really wish there was documentation about how this works.


darylbowman
Captain II
Forum|alt.badge.img+15
  • Author
  • July 19, 2025

Upon more testing, here are my findings:

  • dynamic columns added when the graph is initialized remain until they are removed
  • dynamic columns added pretty much any other time will be removed automatically (I think during RowSelected

If you need to add truly dynamic columns (ie: they may be removed / readded during the lifecycle of a graph), they need to be re-added in a RowSelected event handler. However, simply storing a list of columns was not enough, as the list would be emptied for no apparent reason right before the RowSelected event handler ran. I had to add a virtual view to store the field definitions, which is not emptied until I ask it to be.

Additionally, though the columns show correctly when run the first time, subsequent runs required me to set ‘generateColumnsAfterSelect: true’ in the gridConfig.


darylbowman
Captain II
Forum|alt.badge.img+15
  • Author
  • Answer
  • July 21, 2025

Turns out the REAL underlying problem is how I was trying to remove fields (columns) from the cache.

view.Cache.Fields is a PXFieldCollection, which inherits List. This means that Clear() is an inherited method. The PXFieldCollection defines an override for Add(item) and Remove(item) but not Clear(). I was using Clear() in an effort to remove all the fields I had previously added, when that’s not at all what it does. it was having an effect, as the columns disappeared, but view.Cache.Fields.Contains(item) still returned ‘true’. Instead, I had to use view.Cache.Remove(item) on each field. Now the fields are correctly being removed, then correctly re-added, and no longer disappearing.

@Dmitrii Naumov - I recommend an override for Clear() be added or somehow indicate this is not what the method does