Skip to main content
Answer

Has anyone successfully dynamically generated grid columns?

  • February 6, 2024
  • 2 replies
  • 165 views

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

I have attempted several times to follow this article, but I find it very difficult, and I always get hung up and end up ditching it. Has anyone successfully done this that would be willing to provide some helpful tips, and/or allow me to pay for samples?

Best answer by darylbowman

I did finally manage to crack this. Turns out my use-case was just much more complicated than the examples in that document.

Here are the basics:

  • Generate the dynamic columns in
    • Initialize() if the dynamic columns won’t be added or removed through the graph lifecycle
    • a RowSelected event handler of the primary DAC if they will be added or removed
  • Generate the columns like this:
    string fieldName = "someName";

    // Add the field to the cache's Fields collection if not already present
    if (!Results.Cache.Fields.Contains(fieldName))
    {
    Results.Cache.Fields.Add(fieldName);

    // Attaches FieldSelecting handler
    this.FieldSelecting.AddHandler(
    typeof(SomeDAC),
    fieldName,
    (sender, e) => DynamicFieldSelecting(sender, e, fieldName)
    );

    // Attaches FieldUpdating handler
    this.FieldUpdating.AddHandler(
    typeof(SomeDAC),
    fieldName,
    (sender, e) => DynamicFieldUpdating(sender, e, fieldName)
    );
    }
  • Set the field value in FieldSelecting:
    private void DynamicFieldSelecting(PXCache sender, PXFieldSelectingEventArgs e, string fieldName)
    {
    if (e.Row == null)
    {
    // Configure field properties for the grid header
    e.ReturnState = CreateFieldState(e.ReturnValue, typeof(string), fieldName);
    return;
    }

    e.ReturnValue = "some value";

    // Configure field state for the data row; TO DO: change to your 'Type'
    e.ReturnState = CreateFieldState(e.ReturnValue, typeof(decimal), fieldName);
    e.IsAltered = true;
    }
  • Don’t necessarily need FieldUpdating:
    protected virtual void DynamicFieldUpdating(PXCache sender, PXFieldUpdatingEventArgs e, string fieldName)
    { }
  • CreateFieldState method:
    private object CreateFieldState(object value, Type type, string fieldName)
    {
    return PXFieldState.CreateInstance(
    value,
    type,
    fieldName: fieldName,
    displayName: fieldName,
    visible: true,
    visibility: PXUIVisibility.Dynamic
    );
    }
  • Set the grid properties to support dynamic columns
    • In ASPX (Classic UI):
      <px:PXGrid DataSourceID="ds" AutoGenerateColumns="AppendDynamic" runat="server" ID="grid"></px:PXGrid>
    • In TypeScript (Modern UI):
      @gridConfig({ // Play with these options
      generateColumns: GridColumnGeneration.AppendDynamic,
      generateColumnsAfterSelect: true,
      repaintColumns: true
      })
      export class MyGridView extends PXView {

      }

2 replies

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

I did finally manage to crack this. Turns out my use-case was just much more complicated than the examples in that document.

Here are the basics:

  • Generate the dynamic columns in
    • Initialize() if the dynamic columns won’t be added or removed through the graph lifecycle
    • a RowSelected event handler of the primary DAC if they will be added or removed
  • Generate the columns like this:
    string fieldName = "someName";

    // Add the field to the cache's Fields collection if not already present
    if (!Results.Cache.Fields.Contains(fieldName))
    {
    Results.Cache.Fields.Add(fieldName);

    // Attaches FieldSelecting handler
    this.FieldSelecting.AddHandler(
    typeof(SomeDAC),
    fieldName,
    (sender, e) => DynamicFieldSelecting(sender, e, fieldName)
    );

    // Attaches FieldUpdating handler
    this.FieldUpdating.AddHandler(
    typeof(SomeDAC),
    fieldName,
    (sender, e) => DynamicFieldUpdating(sender, e, fieldName)
    );
    }
  • Set the field value in FieldSelecting:
    private void DynamicFieldSelecting(PXCache sender, PXFieldSelectingEventArgs e, string fieldName)
    {
    if (e.Row == null)
    {
    // Configure field properties for the grid header
    e.ReturnState = CreateFieldState(e.ReturnValue, typeof(string), fieldName);
    return;
    }

    e.ReturnValue = "some value";

    // Configure field state for the data row; TO DO: change to your 'Type'
    e.ReturnState = CreateFieldState(e.ReturnValue, typeof(decimal), fieldName);
    e.IsAltered = true;
    }
  • Don’t necessarily need FieldUpdating:
    protected virtual void DynamicFieldUpdating(PXCache sender, PXFieldUpdatingEventArgs e, string fieldName)
    { }
  • CreateFieldState method:
    private object CreateFieldState(object value, Type type, string fieldName)
    {
    return PXFieldState.CreateInstance(
    value,
    type,
    fieldName: fieldName,
    displayName: fieldName,
    visible: true,
    visibility: PXUIVisibility.Dynamic
    );
    }
  • Set the grid properties to support dynamic columns
    • In ASPX (Classic UI):
      <px:PXGrid DataSourceID="ds" AutoGenerateColumns="AppendDynamic" runat="server" ID="grid"></px:PXGrid>
    • In TypeScript (Modern UI):
      @gridConfig({ // Play with these options
      generateColumns: GridColumnGeneration.AppendDynamic,
      generateColumnsAfterSelect: true,
      repaintColumns: true
      })
      export class MyGridView extends PXView {

      }

Chris Hackett
Community Manager
Forum|alt.badge.img
  • Acumatica Community Manager
  • August 20, 2025

Thank you for sharing your solution with the community ​@darylbowman!